diff options
| author | Evsyukov Denis Anatolyevich <[email protected]> | 2020-01-10 09:52:39 +0300 |
|---|---|---|
| committer | Evsyukov Denis Anatolyevich <[email protected]> | 2020-01-10 09:52:39 +0300 |
| commit | 0eb03b901a70b38182fdd7f9b7505289784140b7 (patch) | |
| tree | 989c3e7d6b66b9eab8ab277e32bf6368b11e329e /src/main.cpp | |
| parent | Some refactoring (diff) | |
| download | t-0eb03b901a70b38182fdd7f9b7505289784140b7.tar.xz t-0eb03b901a70b38182fdd7f9b7505289784140b7.zip | |
Change sha256 to sha1, and move parsing to main module
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index 5df353f..35389b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,56 @@ -#include "opts/opts.hpp" +#include <filesystem> + +#include "opts/cxxopts.hpp" +#include "functions.hpp" +#include "sha1/sha1.hpp" + +using namespace std; int main(int argc, char *argv[]) { - execute_commands(argc, argv); + cxxopts::Options options("MyProgram", "One line description of MyProgram"); + options + .allow_unrecognised_options() + .add_options() + ("positional", + "Positional arguments: these are the arguments that are entered " + "without an option", cxxopts::value<std::vector<std::string >>()) + ("e,edit", "edit TASK to contain TEXT", cxxopts::value<std::string>()) + ("f,finish", "mark TASK as finished", cxxopts::value<std::string>()) + ("r,remove", "Remove TASK from list", cxxopts::value<std::string>()) + ("l,list", "work on LIST", cxxopts::value<std::string>()) + ("t,taskdir", "work on the lists in DIR", cxxopts::value<std::string>()) + ("d,delete-if-empty", "delete the task file if it becomes empty") + ("g,grep", "print only tasks that contain WORD", cxxopts::value<std::string>()) + ("v,verbose", "print more detailed output (full task ids, etc)") + ("q,quiet", "print less detailed output (no task ids, etc)") + ("D,done", "list done tasks instead of unfinished ones") + ("h,help", "HELP"); + options.parse_positional({"positional"}); + auto result = options.parse(argc, argv); + const auto &arguments = result.arguments(); + if (result.count("help")) { + std::cout << options.help() << std::endl; + exit(0); + } + if (result.count("positional")) { + std::string str; + auto &v = result["positional"].as<std::vector<std::string >>(); + for (const auto &s : v) { + str += s + " "; + } + str = trim(str); + char hex[SHA1_HEX_SIZE]; + sha1(str.c_str()).finalize().print_hex(hex); + cout << "sha1('" << str << "'): " << hex << endl; + } + std::string taskdir; + if (result.count("taskdir")) { + taskdir = result["taskdir"].as<std::string>(); + } else { + namespace fs = std::filesystem; + taskdir = fs::current_path(); + } + + std::cout << "Current path is " << taskdir << '\n'; return 0; }
\ No newline at end of file |