MCPcopy Create free account
hub / github.com/avast/retdec / registerArg

Method registerArg

src/unpackertool/arg_handler.cpp:68–94  ·  view source on GitHub ↗

* Register a command-line argument to the handler. The registration may fail if * there is already an argument with the specified short or long option. * * @param opt Short option of an argument. * @param longOpt Long option of an argument. * @param hasInput True if the argument has an input, defaultly false. * * @return True if the registration was successful, otherwise false. */

Source from the content-addressed store, hash-verified

66 * @return True if the registration was successful, otherwise false.
67 */
68bool ArgHandler::registerArg(char opt, const std::string& longOpt, bool hasInput /*= false*/)
69{
70 // '-' is reserved character for long options
71 if (opt == '-')
72 return false;
73
74 std::string shortOpt(&opt, 1);
75 // Test if there is command with that option
76 if (_argMap.find(shortOpt) != _argMap.end())
77 return false;
78
79 // Test also long option if it is not missing
80 if (!longOpt.empty())
81 {
82 if (_argMap.find(longOpt) != _argMap.end())
83 return false;
84 }
85
86 _argMap[shortOpt] = new ArgInfo(opt, longOpt, hasInput);
87 if (!longOpt.empty())
88 {
89 // Long option and short option are both using the same ArgInfo
90 _argMap[longOpt] = _argMap[shortOpt];
91 }
92
93 return true;
94}
95
96/**
97 * Array like access to the command-line arguments. Accessor is short option.

Callers 1

_mainFunction · 0.80

Calls 2

endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected