| 34 | } |
| 35 | |
| 36 | int mainLs(int argc, const char* argv[]) |
| 37 | { |
| 38 | if (argc == 1) |
| 39 | showProfiles("ls", formats); |
| 40 | flags.parseFlagsWithConfigFiles(argc, argv, formats); |
| 41 | |
| 42 | try |
| 43 | { |
| 44 | auto filesystem = Filesystem::createFilesystemFromConfig(); |
| 45 | auto files = filesystem->list(Path(directory)); |
| 46 | |
| 47 | int maxlen = 0; |
| 48 | for (const auto& dirent : files) |
| 49 | maxlen = std::max(maxlen, (int)quote(dirent->filename).size()); |
| 50 | |
| 51 | uint32_t total = 0; |
| 52 | for (const auto& dirent : files) |
| 53 | { |
| 54 | fmt::print("{} {:{}} {:6} {:4} {}\n", |
| 55 | fileTypeChar(dirent->file_type), |
| 56 | quote(dirent->filename), |
| 57 | maxlen + 2, |
| 58 | dirent->length, |
| 59 | dirent->mode, |
| 60 | dirent->attributes[Filesystem::CTIME]); |
| 61 | total += dirent->length; |
| 62 | } |
| 63 | fmt::print("({} files, {} bytes)\n", files.size(), total); |
| 64 | } |
| 65 | catch (const FilesystemException& e) |
| 66 | { |
| 67 | error("{}", e.message); |
| 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |
nothing calls this directly
no test coverage detected