@@ -67,6 +67,7 @@ struct ProgOptions
6767 std::unique_ptr<std::string> mInputCode = nullptr ;
6868 std::vector<std::string> mInputVDBFiles = {};
6969 std::string mOutputVDBFile = " " ;
70+ bool mCopyFileMeta = false ;
7071 bool mVerbose = false ;
7172 openvdb::ax::CompilerOptions::OptLevel mOptLevel =
7273 openvdb::ax::CompilerOptions::OptLevel::O3;
@@ -154,13 +155,14 @@ auto usage_execute(const bool verbose)
154155 " \n " ;
155156 }
156157 os <<
157- " [a.vdb, b.vdb ... ] list of input files\n "
158- " -s [code], -f [file] input code to execute as a string or from a file.\n " <<
159- " -o [file.vdb] write the result to a given vdb file\n " <<
160- " --opt [level] optimization level [NONE, O0, O1, O2, Os, Oz, O3 (default)]\n " <<
161- " --werror warnings as errors\n " <<
162- " --max-errors [n] maximum error messages, 0 (default) allows all error messages\n " <<
163- " --threads [n] number of threads to use, 0 (default) uses all available.\n " ;
158+ " -i [file.vdb] append an input vdb file to be read\n "
159+ " -s [code], -f [file] input code to execute as a string or from a file.\n " <<
160+ " -o [file.vdb] write the result to a given vdb file\n " <<
161+ " --opt [level] optimization level [NONE, O0, O1, O2, Os, Oz, O3 (default)]\n " <<
162+ " --werror warnings as errors\n " <<
163+ " --max-errors [n] maximum error messages, 0 (default) allows all error messages\n " <<
164+ " --threads [n] number of threads to use, 0 (default) uses all available.\n " <<
165+ " --copy-file-metadata copy the file level metadata of the first input to the output.\n " ;
164166 if (verbose) {
165167 os << ' \n ' <<
166168 " Notes:\n " <<
@@ -415,6 +417,7 @@ main(int argc, char *argv[])
415417#define axtime () getTime()
416418
417419 bool multiSnippet = false ;
420+ bool dashInputHasBeenUsed = false , positionalInputHasBeenUsed = false ;
418421 for (int i = 1 ; i < argc; ++i) {
419422 std::string arg = argv[i];
420423 if (arg[0 ] == ' -' ) {
@@ -427,11 +430,22 @@ main(int argc, char *argv[])
427430 multiSnippet |= static_cast <bool >(opts.mInputCode );
428431 opts.mInputCode .reset (new std::string ());
429432 loadSnippetFile (argv[i], *opts.mInputCode );
433+ } else if (parser.check (i, " -i" )) {
434+ if (positionalInputHasBeenUsed) {
435+ fatal (" unrecognized positional argument: \" " + opts.mInputVDBFiles .back () + " \" . use -i and -o for vdb files" );
436+ }
437+ dashInputHasBeenUsed = true ;
438+ opts.mInputVDBFiles .emplace_back (argv[++i]);
430439 } else if (parser.check (i, " -v" , 0 )) {
431440 opts.mVerbose = true ;
432441 } else if (parser.check (i, " --threads" )) {
433442 opts.threads = atoi (argv[++i]);
443+ } else if (parser.check (i, " --copy-file-metadata" , 0 )) {
444+ opts.mCopyFileMeta = true ;
434445 } else if (parser.check (i, " -o" )) {
446+ if (positionalInputHasBeenUsed) {
447+ fatal (" unrecognized positional argument: \" " + opts.mInputVDBFiles .back () + " \" . use -i and -o for vdb files" );
448+ }
435449 opts.mOutputVDBFile = argv[++i];
436450 } else if (parser.check (i, " --max-errors" )) {
437451 opts.mMaxErrors = atoi (argv[++i]);
@@ -469,28 +483,34 @@ main(int argc, char *argv[])
469483 fatal (" \" " + arg + " \" is not a valid option" );
470484 }
471485 } else if (!arg.empty ()) {
486+ if (dashInputHasBeenUsed) {
487+ fatal (" unrecognized positional argument: \" " + arg + " \" . use -i and -o for vdb files" );
488+ }
472489
473- bool addToFileList = true ;
474490 if (opts.mMode == ProgOptions::Mode::Default) {
491+ bool skip = true ;
475492 if (arg == " analyze" ) opts.mMode = ProgOptions::Analyze;
476493 else if (arg == " functions" ) opts.mMode = ProgOptions::Functions;
477- else if (arg == " execute" ) {
494+ else if (arg == " execute" ) opts.mMode = ProgOptions::Execute;
495+ else {
496+ skip = false ;
478497 opts.mMode = ProgOptions::Execute;
479- addToFileList = false ;
480- }
481- else opts.mMode = ProgOptions::Execute;
482- }
483- else {
484- // if mode has already been set, no more positional arguments are expected
485- // (except for execute which takes in and out)
486- if (opts.mMode != ProgOptions::Mode::Execute) {
487- fatal (" unrecognized positional argument: \" " + arg + " \" " );
488498 }
499+ if (skip) continue ;
489500 }
490501
491- if (addToFileList) {
502+ // @todo remove positional vdb in/out file arg support
503+ if (opts.mInputVDBFiles .empty ()) {
504+ positionalInputHasBeenUsed = true ;
505+ OPENVDB_LOG_WARN (" position arguments [input.vdb <output.vdb>] are deprecated. use -i and -o" );
492506 opts.mInputVDBFiles .emplace_back (arg);
493507 }
508+ else if (opts.mOutputVDBFile .empty ()) {
509+ opts.mOutputVDBFile = arg;
510+ }
511+ else {
512+ fatal (" unrecognized positional argument: \" " + arg + " \" " );
513+ }
494514 } else {
495515 usage ();
496516 }
@@ -503,9 +523,12 @@ main(int argc, char *argv[])
503523 if (opts.mMode == ProgOptions::Mode::Execute) {
504524 opts.mInitCompile = true ;
505525 if (opts.mInputVDBFiles .empty ()) {
506- fatal (" no vdb files have been provided. " );
526+ fatal (" no vdb files have been provided" );
507527 }
508528 }
529+ else if (!opts.mInputVDBFiles .empty ()) {
530+ fatal (modeString (opts.mMode ) + " does not take input vdb files" );
531+ }
509532
510533 if (opts.mVerbose ) {
511534 axlog (" OpenVDB AX " << openvdb::getLibraryVersionString () << ' \n ' );
@@ -599,7 +622,7 @@ main(int argc, char *argv[])
599622 auto in = file.getGrids ();
600623 grids.insert (grids.end (), in->begin (), in->end ());
601624 // choose the first files metadata
602- if (!meta) meta = file.getMetadata ();
625+ if (opts. mCopyFileMeta && !meta) meta = file.getMetadata ();
603626 file.close ();
604627 axlog (" : " << axtime () << ' \n ' );
605628 } catch (openvdb::Exception& e) {
@@ -624,8 +647,11 @@ main(int argc, char *argv[])
624647 printFunctions (opts.mFunctionNamesOnly ,
625648 opts.mFunctionSearch ,
626649 std::cout);
650+ return EXIT_SUCCESS;
651+ }
652+ else {
653+ fatal (" vdb_ax functions requires a valid option" );
627654 }
628- return EXIT_SUCCESS;
629655 }
630656
631657 // set up logger
0 commit comments