Skip to content

Commit 2b305a9

Browse files
committed
Fix CLI readable-to-varfile conversion ordering
Create non-varfile tokenized files with the requested name/model up front and delay archive updates until after content is loaded, so --name/--archive do not refresh metadata on an empty payload.
1 parent a31a4e1 commit 2b305a9

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

cli/cli.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,19 @@ int main(int argc, char** argv)
225225
TH_Tokenized::initTokens();
226226
}
227227

228-
TIVarFile file = iformat == VARFILE ? TIVarFile::loadFromFile(ipath) : TIVarFile::createNew(varvarType);
229-
228+
string requestedName;
230229
if (result.count("name"))
231230
{
232-
string name = result["name"].as<string>();
233-
file.setVarName(name);
231+
requestedName = result["name"].as<string>();
234232
}
235233

234+
TIModel requestedModel{"84+CE"};
236235
if (result.count("calc"))
237236
{
238237
string modelStr = result["calc"].as<string>();
239238
try
240239
{
241-
TIModel model{modelStr};
242-
file.setCalcModel(model);
240+
requestedModel = TIModel{modelStr};
243241
} catch (invalid_argument& e)
244242
{
245243
cout << modelStr << "is not a valid calc model." << endl;
@@ -253,7 +251,21 @@ int main(int argc, char** argv)
253251
}
254252
}
255253

256-
file.setArchived(result["archive"].as<bool>());
254+
TIVarFile file = iformat == VARFILE
255+
? TIVarFile::loadFromFile(ipath)
256+
: TIVarFile::createNew(varvarType, requestedName, requestedModel);
257+
258+
if (iformat == VARFILE)
259+
{
260+
if (result.count("name"))
261+
{
262+
file.setVarName(requestedName);
263+
}
264+
if (result.count("calc"))
265+
{
266+
file.setCalcModel(requestedModel);
267+
}
268+
}
257269

258270
if (iformat == RAW)
259271
{
@@ -294,6 +306,8 @@ int main(int argc, char** argv)
294306
file.setContentFromString(str.str(), contentOptions);
295307
}
296308

309+
file.setArchived(result["archive"].as<bool>());
310+
297311
switch (oformat)
298312
{
299313
case RAW:

0 commit comments

Comments
 (0)