MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / parseCommandLine

Method parseCommandLine

src/openms/source/DATASTRUCTURES/Param.cpp:822–891  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

820 }
821
822 void Param::parseCommandLine(const int argc, const char** argv, const std::string& prefix)
823 {
824 //determine prefix
825 std::string prefix2 = prefix;
826 if (!prefix2.empty())
827 {
828 //prefix2.ensureLastChar(':');
829 if (prefix2.back() != ':')
830 {
831 prefix2.append(1, ':');
832 }
833 }
834
835 //parse arguments
836 std::string arg, arg1;
837 for (int i = 1; i < argc; ++i)
838 {
839 //load the current and next argument: arg and arg1 ("" at the last argument)
840 arg = argv[i];
841 arg1 = "";
842 if (i + 1 < argc)
843 {
844 arg1 = argv[i + 1];
845 }
846
847 //it is a option when it starts with a '-' and the second character is not a number
848 bool arg_is_option = false;
849 if (arg.size() >= 2 && arg[0] == '-' && arg[1] != '0' && arg[1] != '1' && arg[1] != '2' && arg[1] != '3' && arg[1] != '4' && arg[1] != '5' && arg[1] != '6' && arg[1] != '7' && arg[1] != '8' && arg[1] != '9')
850 {
851 arg_is_option = true;
852 }
853 bool arg1_is_option = false;
854 if (arg1.size() >= 2 && arg1[0] == '-' && arg1[1] != '0' && arg1[1] != '1' && arg1[1] != '2' && arg1[1] != '3' && arg1[1] != '4' && arg1[1] != '5' && arg1[1] != '6' && arg1[1] != '7' && arg1[1] != '8' && arg1[1] != '9')
855 {
856 arg1_is_option = true;
857 }
858 //cout << "Parse: '"<< arg << "' '" << arg1 << "'" << std::endl;
859
860 //flag (option without text argument)
861 if (arg_is_option && arg1_is_option)
862 {
863 root_.insert(ParamEntry(arg, std::string(), ""), prefix2);
864 }
865 //option with argument
866 else if (arg_is_option && !arg1_is_option)
867 {
868 root_.insert(ParamEntry(arg, arg1, ""), prefix2);
869 ++i;
870 }
871 //just text arguments (not preceded by an option)
872 else
873 {
874
875 ParamEntry* misc_entry = root_.findEntryRecursive(prefix2 + "misc");
876 if (misc_entry == nullptr)
877 {
878 std::vector<std::string> sl;
879 sl.push_back(arg);

Callers 6

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
Param_test.cppFile · 0.80

Calls 11

ParamEntryFunction · 0.85
stringClass · 0.85
backMethod · 0.80
findEntryRecursiveMethod · 0.80
emptyMethod · 0.45
appendMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
push_backMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected