From 8736f2b61aee0821a6764dbc9d42e62d89d22529 Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Anatolyevich Date: Thu, 9 Jan 2020 15:44:35 +0300 Subject: Some refactoring --- src/opts/opts.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/opts/opts.cpp (limited to 'src/opts/opts.cpp') diff --git a/src/opts/opts.cpp b/src/opts/opts.cpp new file mode 100644 index 0000000..fac0356 --- /dev/null +++ b/src/opts/opts.cpp @@ -0,0 +1,55 @@ +#include + +#include "cxxopts.hpp" +#include "../functions.hpp" +#include "../sha256/sha256.h" + +using namespace std; + +void execute_commands(int argc, char **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>()) + ("e,edit", "edit TASK to contain TEXT", cxxopts::value()) + ("f,finish", "mark TASK as finished", cxxopts::value()) + ("r,remove", "Remove TASK from list", cxxopts::value()) + ("l,list", "work on LIST", cxxopts::value()) + ("t,taskdir", "work on the lists in DIR", cxxopts::value()) + ("d,delete-if-empty", "delete the task file if it becomes empty") + ("g,grep", "print only tasks that contain WORD", cxxopts::value()) + ("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>(); + for (const auto &s : v) { + str += s + " "; + } + str = trim(str); + + cout << "sha256('" << str << "'): " << sha256(str) << endl; + } + std::string taskdir; + if (result.count("taskdir")) { + taskdir = result["taskdir"].as(); + } else { + namespace fs = std::filesystem; + taskdir = fs::current_path(); + } + + std::cout << "Current path is " << taskdir << '\n'; + std::cout << "Saw " << arguments.size() << " arguments" << std::endl; +} \ No newline at end of file -- cgit v1.2.3