Skip to content

Commit 7aa038e

Browse files
committed
Fix, versionOpt and header not defined for call to cli.parse()
1 parent f6f7847 commit 7aa038e

3 files changed

Lines changed: 58 additions & 59 deletions

File tree

libs/app/app.cpp

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static Path s_confDir;
4040
static Path s_crashDir; // where to place crash dumps
4141
static Path s_dataDir;
4242
static Path s_logDir; // where to place log files
43-
static Path s_webDir;
4443

4544

4645
/****************************************************************************
@@ -51,7 +50,7 @@ static Path s_webDir;
5150

5251
//===========================================================================
5352
static Path makeAppDir(string_view path) {
54-
auto out = appRootDir() / path;
53+
auto out = s_rootDir / path;
5554
return out;
5655
}
5756

@@ -120,33 +119,16 @@ void ConfigAppXml::onConfigChange(const XDocument & doc) {
120119
//===========================================================================
121120
static void initVars() {
122121
// Application name and version
123-
fileGetCurrentDir(&s_initialDir);
124122
auto exeName = (Path) envExecPath();
125123
if (s_appBaseName.empty())
126124
s_appBaseName = exeName.stem();
127125
if (!s_appVer)
128126
s_appVer = envExecVersion();
129-
if (s_appVer) {
130-
Cli cli;
131-
ostringstream hdr;
132-
Time8601Str ds(envExecBuildTime());
133-
auto verStr = toString(s_appVer);
134-
hdr << s_appBaseName
135-
<< " v" << verStr
136-
<< " (" << ds.view().substr(0, 10) << ")";
137-
cli.header(hdr.str())
138-
.versionOpt(verStr, s_appBaseName);
139-
}
140-
s_appName = s_appBaseName;
141-
if (s_appIndex > 1)
142-
s_appName += toChars(s_appIndex);
143-
s_appSvcName = s_appName;
144-
if (s_groupIndex > 1) {
145-
s_appSvcName += '.';
146-
s_appSvcName += toChars(s_groupIndex);
147-
}
127+
s_appIndex = 1;
128+
s_groupIndex = 1;
148129

149130
// Directories
131+
fileGetCurrentDir(&s_initialDir);
150132
s_binDir = exeName.parentPath();
151133
if (s_appFlags.any(fAppWithFiles) && s_binDir.stem() == "bin") {
152134
s_rootDir = s_binDir.parentPath();
@@ -158,7 +140,6 @@ static void initVars() {
158140
s_crashDir = makeAppDir("crash");
159141
s_dataDir = makeAppDir("data");
160142
s_logDir = makeAppDir("log");
161-
s_webDir = makeAppDir("web");
162143

163144
if (s_appFlags.any(fAppWithChdir))
164145
fileSetCurrentDir(s_rootDir);
@@ -171,11 +152,6 @@ static void initVars() {
171152

172153
//===========================================================================
173154
static void initApp() {
174-
iPlatformInitialize(PlatformInit::kBeforeAppVars);
175-
if (s_appFlags.all(fAppWithLogs | fAppWithConsole))
176-
logMonitor(consoleBasicLogger());
177-
iFileInitialize();
178-
initVars();
179155
iConfigInitialize();
180156
configMonitor("app.xml", &s_appXml);
181157
if (s_appFlags.any(fAppWithLogs))
@@ -189,8 +165,6 @@ static void initApp() {
189165
iHttpRouteInitialize();
190166
iWebAdminInitialize();
191167

192-
taskPushEvent(s_appTasks.data(), s_appTasks.size());
193-
194168
{
195169
lock_guard lk{s_runMut};
196170
if (s_runMode == kRunStopping) {
@@ -203,6 +177,8 @@ static void initApp() {
203177
}
204178
}
205179

180+
taskPushEvent(s_appTasks.data(), s_appTasks.size());
181+
206182
Cli cli;
207183
if (!cli.exec()) {
208184
// Extended parsing failed or the action completed without requesting
@@ -269,26 +245,9 @@ int Dim::appRun(
269245
s_appFlags = flags;
270246
s_appTasks.clear();
271247

272-
Cli cli;
273-
if (!s_appFlags.any(fAppWithService)) {
274-
s_appIndex = 1;
275-
s_groupIndex = 1;
276-
} else {
277-
cli.opt(&s_appIndex, "app-index", 1)
278-
.desc("Identifies service when multiple instances "
279-
"are configured.");
280-
cli.opt(&s_groupIndex, "group-index", 1)
281-
.desc("Identifies service group when there are multiple.");
282-
}
283-
284-
// The command line will be validated later by the application, right now
285-
// we just need the appIndex and groupIndex to process the configuration.
286-
auto parseOk = cli.parse(argc, argv);
287-
288248
s_appVer = ver;
289249
s_appBaseName = baseName;
290250
s_appName.clear();
291-
s_webDir.clear();
292251

293252
// Finish initialization and start.
294253
iPlatformInitialize(PlatformInit::kBeforeAll);
@@ -298,6 +257,44 @@ int Dim::appRun(
298257
logDefaultMonitor(consoleBasicLogger());
299258
iTaskInitialize();
300259
iTimerInitialize();
260+
iPlatformInitialize(PlatformInit::kBeforeAppVars);
261+
if (s_appFlags.all(fAppWithLogs | fAppWithConsole))
262+
logMonitor(consoleBasicLogger());
263+
iFileInitialize();
264+
initVars();
265+
266+
Cli cli;
267+
if (s_appVer) {
268+
ostringstream hdr;
269+
Time8601Str ds(envExecBuildTime());
270+
auto verStr = toString(s_appVer);
271+
hdr << s_appBaseName
272+
<< " v" << verStr
273+
<< " (" << ds.view().substr(0, 10) << ")";
274+
cli.header(hdr.str())
275+
.versionOpt(verStr, s_appBaseName);
276+
}
277+
if (s_appFlags.any(fAppWithService)) {
278+
cli.opt(&s_appIndex, "app-index", 1)
279+
.desc("Identifies service when multiple instances "
280+
"are configured.");
281+
cli.opt(&s_groupIndex, "group-index", 1)
282+
.desc("Identifies service group when there are multiple.");
283+
}
284+
285+
// The command line can be validated later by the application during the
286+
// cli.exec() call in initApp(), right now we just need appIndex and
287+
// groupIndex to process the configuration.
288+
auto parseOk = cli.parse(argc, argv);
289+
290+
s_appName = s_appBaseName;
291+
if (s_appIndex > 1)
292+
s_appName += toChars(s_appIndex);
293+
s_appSvcName = s_appName;
294+
if (s_groupIndex > 1) {
295+
s_appSvcName += '.';
296+
s_appSvcName += toChars(s_groupIndex);
297+
}
301298

302299
if (parseOk) {
303300
taskPushEvent(initApp);
@@ -335,6 +332,7 @@ int Dim::appRun(
335332

336333
//===========================================================================
337334
unsigned Dim::appIndex() {
335+
assert(!s_appName.empty());
338336
return s_appIndex;
339337
}
340338

@@ -362,6 +360,7 @@ const string & Dim::appName() {
362360

363361
//===========================================================================
364362
unsigned Dim::appGroupIndex() {
363+
assert(!s_appName.empty());
365364
return s_groupIndex;
366365
}
367366

@@ -395,7 +394,7 @@ const Path & Dim::appBinDir() {
395394
}
396395

397396
//===========================================================================
398-
const Path & Dim::appConfigDir() {
397+
const Path & Dim::appConfDir() {
399398
assert(!s_appName.empty());
400399
return s_confDir;
401400
}
@@ -442,8 +441,8 @@ bool Dim::appCliShutdownSignaled() {
442441
}
443442

444443
//===========================================================================
445-
bool Dim::appConfigPath(Path * out, string_view file, bool cine) {
446-
return !fileChildPath(out, appConfigDir(), file, cine);
444+
bool Dim::appConfPath(Path * out, string_view file, bool cine) {
445+
return !fileChildPath(out, appConfDir(), file, cine);
447446
}
448447

449448
//===========================================================================

libs/app/app.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,27 @@ int appExitCode();
147147
// /crash
148148
// /data
149149
// /log
150-
// /web
150+
// /web - may be changed via app.xml/App/WebRoot
151151
//
152152
// otherwise:
153153
// <binDir> directory containing this executable (is also conf dir)
154154
// LOCALAPPDATA/<AppName>
155155
// /crash
156156
// /data
157157
// /log
158-
// /web
158+
// /web - may be changed via app.xml/App/WebRoot
159159

160160
const Path & appRootDir(); // application root
161161
const Path & appInitialDir(); // current directory when appRun was called
162162
const Path & appBinDir(); // directory containing this binary
163-
const Path & appConfigDir();
163+
const Path & appConfDir();
164164
const Path & appCrashDir();
165165
const Path & appDataDir();
166166
const Path & appLogDir();
167167

168168
// False if file relative to root is not within the root path. This can happen
169169
// if file breaks out via ".." or is an absolute path.
170-
bool appConfigPath(
170+
bool appConfPath(
171171
Path * out,
172172
std::string_view file,
173173
bool createDirIfNotExist = true

libs/app/config.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void ConfigFile::monitor_UNLK(
128128
fileMonitor(s_hDir, relpath, this);
129129
} else {
130130
string fullpath;
131-
fullpath = appConfigDir();
131+
fullpath = appConfDir();
132132
fullpath += '/';
133133
fullpath += relpath;
134134
parseContent(fullpath, 0, {}, {});
@@ -169,7 +169,7 @@ void ConfigFile::parseContent(
169169
m_content = move(content);
170170
m_fullpath = fullpath;
171171
m_relpath = m_fullpath;
172-
m_relpath.remove_prefix(appConfigDir().size() + 1);
172+
m_relpath.remove_prefix(appConfDir().size() + 1);
173173

174174
// call notifiers
175175
if (m_changes > 1 && appFlags().any(fAppWithFiles))
@@ -320,7 +320,7 @@ void Dim::iConfigInitialize() {
320320
s_context.appBaseName = appBaseName();
321321
s_context.appIndex = appIndex();
322322
if (appFlags().any(fAppWithFiles))
323-
fileMonitorDir(&s_hDir, appConfigDir(), true);
323+
fileMonitorDir(&s_hDir, appConfDir(), true);
324324
}
325325

326326

@@ -341,7 +341,7 @@ static bool getFullpath(Path * out, string_view file) {
341341
if (appFlags().any(fAppWithFiles)) {
342342
result = fileMonitorPath(out, s_hDir, file);
343343
} else {
344-
result = appConfigPath(out, file, false);
344+
result = appConfPath(out, file, false);
345345
}
346346
if (!result)
347347
logMsgError() << "File outside of configuration directory: " << file;
@@ -748,7 +748,7 @@ class JsonConfigs : public IWebAdminNotify {
748748
void JsonConfigs::onHttpRequest(unsigned reqId, HttpRequest & msg) {
749749
auto res = HttpResponse(kHttpStatusOk);
750750
auto bld = initResponse(&res, reqId, msg);
751-
auto dir = appConfigDir();
751+
auto dir = appConfDir();
752752
configWriteRules(&bld, "files");
753753
bld.end();
754754
httpRouteReply(reqId, move(res));

0 commit comments

Comments
 (0)