MCPcopy Create free account
hub / github.com/ariccio/altWinDirStat / ParseCommandLine

Method ParseCommandLine

Reference code/osImageTool/OSImageTool.cpp:79–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77#define HANDLESTROPTION(var) (arg[2] ? !(var= arg.substr(2)).empty() : i+1 != args.end() ? !(var= *(++i)).empty() : 0)
78
79bool COSImageToolApp::ParseCommandLine(const string& cmdline)
80{
81 StringList args;
82 if (!SplitString(cmdline, args, false))
83 {
84 g_err.Set("Error in commandline");
85 return false;
86 }
87
88 int argsfound=0;
89 for (StringList::iterator i= args.begin() ; i!=args.end() ; ++i)
90 {
91 string& arg= *i;
92 if (arg[0]=='-') switch(arg[1])
93 {
94 case 'r':
95 if (!HANDLESTROPTION(m_cmdsourcename))
96 {
97 g_err.Set("Error in commandline, '-r' needs a parameter");
98 return false;
99 }
100 break;
101 case 'w':
102 if (!HANDLESTROPTION(m_cmdtargetname))
103 {
104 g_err.Set("Error in commandline, '-w' needs a parameter");
105 return false;
106 }
107 break;
108 case 'a':
109 m_bAuto= true;
110 break;
111 case 'f':
112 g_cfg.bCheckFilesize= false;
113 break;
114 case '-':
115 if (arg=="--register")
116 m_bDoRegisterSelf= true;
117 else {
118 g_err.Set(stringformat("unknown option: %s", arg.c_str()));
119 return false;
120 }
121 break;
122 default:
123 g_err.Set(stringformat("unknown option: %s", arg.c_str()));
124 return false;
125 }
126 else switch(argsfound)
127 {
128 case 0:
129 default:
130 g_err.Set(stringformat("unknown argument: %s", arg.c_str()));
131 return false;
132 }
133 }
134 return true;
135}
136

Callers

nothing calls this directly

Calls 5

SplitStringFunction · 0.85
stringformatFunction · 0.85
beginMethod · 0.80
SetMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected