diff --git a/src/main.cpp b/src/main.cpp index 6e695e2..81922d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,12 +4,13 @@ #include #include #include -#include #include #include +#include // POSIX #include +#include #include //libraries @@ -25,6 +26,7 @@ std::string change; std::map changes; std::vector deletions; bool should_list = false; +bool sort = false; static void handle_additions(std::vector& tags) { for (const std::string& tag : additions) { @@ -69,6 +71,9 @@ static void process(const char* path) { handle_deletions(tags); handle_changes(tags); handle_additions(tags); + if (sort) { + std::sort(tags.begin(), tags.end()); + } if (should_list) { std::cout << " after: " << sc::io::yellowf << sc::join(tags, ", ") << sc::io::reset << '\n'; } @@ -106,9 +111,10 @@ int main(int argc, char* argv[]) { {"change", required_argument, nullptr, 'c'}, {"into", required_argument, nullptr, 'i'}, {"list", no_argument, nullptr, 'l'}, + {"sort", no_argument, nullptr, 's'}, {nullptr, 0, nullptr, 0} }; - while ((opt_char = getopt_long(argc, argv, "a:c:d:hi:l", long_options, nullptr)) != -1) { + while ((opt_char = getopt_long(argc, argv, "a:c:d:hi:ls", long_options, nullptr)) != -1) { std::string arg {optarg ? optarg : ""}; switch (opt_char) { case 0: { @@ -138,6 +144,9 @@ int main(int argc, char* argv[]) { case 'l': should_list = true; break; + case 's': + sort = true; + break; case '?': throw std::runtime_error("unrecognized option"); }