|
| 1 | +#include "CLI.h" |
| 2 | +#include "CLIResult.h" |
| 3 | +#include "ConfigTS.h" |
| 4 | +//#include "TSXformTypeString.h" |
| 5 | +#include <Util/CoutBuf.hpp> |
| 6 | + |
| 7 | +#include <EnjoLibBoost/ProgramOptions.hpp> |
| 8 | + |
| 9 | +using namespace EnjoLib; |
| 10 | + |
| 11 | +CLI::CLI(){} |
| 12 | +CLI::~CLI(){} |
| 13 | + |
| 14 | +EnjoLib::Result<CLIResult> CLI::GetConfigs(int argc, char ** argv) const |
| 15 | +{ |
| 16 | + //const char * OPT_PLUGIN = "plugin"; |
| 17 | + |
| 18 | + const char * OPT_MIN_MONTH = "min-month"; |
| 19 | + const char * OPT_MIN_YEAR = "min-year"; |
| 20 | + const char * OPT_MAX_MONTH = "max-month"; |
| 21 | + const char * OPT_MAX_YEAR = "max-year"; |
| 22 | + //const char * OPT_LATEST_DATE = "latest-date"; |
| 23 | + const char * OPT_SYMBOL = "sym"; |
| 24 | + const char * OPT_PERIOD = "per"; |
| 25 | + |
| 26 | + EnjoLib::ProgramOptionsState popState; |
| 27 | + ////popState.AddStr(OPT_PLUGIN, "Plugin name"); |
| 28 | + popState.AddInt(OPT_MIN_MONTH, "Start month"); /// TODO: Option Add(char*, char*, int & refVal);. A new class beside the old one or replace the old one? |
| 29 | + popState.AddInt(OPT_MIN_YEAR, "Start year"); |
| 30 | + popState.AddInt(OPT_MAX_MONTH, "End month"); |
| 31 | + popState.AddInt(OPT_MAX_YEAR, "End year"); |
| 32 | + popState.AddStr(OPT_SYMBOL, "Symbol name"); |
| 33 | + popState.AddStr(OPT_PERIOD, "Period name"); |
| 34 | + |
| 35 | + popState.ReadArgs(argc, argv); |
| 36 | + const EnjoLib::ProgramOptions pops(popState); |
| 37 | + |
| 38 | + ConfigSym confSym; |
| 39 | + |
| 40 | + if (pops.IsHelpRequested()) |
| 41 | + { |
| 42 | + /// TODO: Try also to react also on -h by adding here: |
| 43 | + /** |
| 44 | + bool ProgramOptions::IsHelpRequested() const |
| 45 | + { |
| 46 | + return GetBoolFromMap(ProgramOptionsState::OPT_HELP); |
| 47 | + } |
| 48 | + return GetBoolFromMap(ProgramOptionsState::OPT_HELP || return GetBoolFromMap(ProgramOptionsState::OPT_HELP_MIN);); |
| 49 | + const char * OPT_HELP_MIN = "h"; |
| 50 | + */ |
| 51 | + ELO |
| 52 | + LOG << pops.GetHelp() << Nl; |
| 53 | + |
| 54 | + LOG << GetAdditionalHelp(); |
| 55 | + LOG << Nl; |
| 56 | + LOG << "The default path of the script is: " << ConfigTS::DEFAULT_SCRIPT_FILE_NAME << Nl; |
| 57 | + LOG << "\n(C) 2012-2022 mj-xmr. Licensed under AGPLv3.\n"; |
| 58 | + LOG << "https://github.com/mj-xmr/tsqsim\n"; |
| 59 | + LOG << "\nRemember to be happy.\n\n"; |
| 60 | + return EnjoLib::Result<CLIResult>(CLIResult(confSym), false); |
| 61 | + } |
| 62 | + |
| 63 | + confSym.dates.Set0(); |
| 64 | + |
| 65 | + confSym.dates.monthStart = pops.GetIntFromMap(OPT_MIN_MONTH); |
| 66 | + confSym.dates.yearStart = pops.GetIntFromMap(OPT_MIN_YEAR); |
| 67 | + confSym.dates.monthEnd = pops.GetIntFromMap(OPT_MAX_MONTH); |
| 68 | + confSym.dates.yearEnd = pops.GetIntFromMap(OPT_MAX_YEAR); |
| 69 | + confSym.symbol = pops.GetStrFromMap(OPT_SYMBOL); |
| 70 | + confSym.period = pops.GetStrFromMap(OPT_PERIOD); |
| 71 | + |
| 72 | + //auto pluginName = pops.GetStrFromMap (OPT_PLUGIN); |
| 73 | + |
| 74 | + CLIResult res(confSym); |
| 75 | + |
| 76 | + return EnjoLib::Result<CLIResult>(CLIResult(confSym), true); |
| 77 | +} |
0 commit comments