diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-08-12 15:53:48 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-08-12 15:53:48 -0700 |
commit | 78e3f55368cd7ca5e3ca291f18990501eac9e1ff (patch) | |
tree | c11e5193106d6248cc7b7a9331336817aa62dedc /001help.cc | |
parent | 4f95cdb0103a95b90c5676b5a79d55afaaa80aa5 (diff) | |
download | mu-78e3f55368cd7ca5e3ca291f18990501eac9e1ff.tar.gz |
3170 - multiple --options at the commandline
The mu commandline now has four parts: options, commands (of which we only have one so far: 'test'), files/directories and ingredients to pass to 'main'. That cleans up the hacky ordering constraint we had earlier. I've also cleaned up the usage message.
Diffstat (limited to '001help.cc')
-rw-r--r-- | 001help.cc | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/001help.cc b/001help.cc index fa5c3547..ea76db25 100644 --- a/001help.cc +++ b/001help.cc @@ -5,28 +5,52 @@ if (argc <= 1 || is_equal(argv[1], "--help")) { // this is the functionality later layers will provide // currently no automated tests for commandline arg parsing - cerr << "To load files and run 'main':\n" - << " mu file1.mu file2.mu ...\n" - << "To run all tests:\n" - << " mu test\n" - << "To load files and then run all tests:\n" - << " mu test file1.mu file2.mu ...\n" - << "To load files and run only the tests in explicitly loaded files (for apps):\n" - << " mu --test-only-app test file1.mu file2.mu ...\n" - << "'--test-only-app' must come before all other args\n" - << "'test' must come before all other args except '--test-only-app'\n" - << "To load all files with a numeric prefix in a directory:\n" - << " mu directory1\n" - << "You can test directories just like files.\n" - << "To pass ingredients to a mu program, provide them after '--':\n" - << " mu file_or_dir1 file_or_dir2 ... -- ingredient1 ingredient2 ...\n" + if (argc <= 1) { + cerr << "Please provide a Mu program to run.\n" + << "\n"; + } + cerr << "Usage:\n" + << " mu [options] [test] [files]\n" + << "or:\n" + << " mu [options] [test] [files] -- [ingredients for function/recipe 'main']\n" + << "Square brackets surround optional arguments.\n" + << "\n" + << "Examples:\n" + << " To load files and run 'main':\n" + << " mu file1.mu file2.mu ...\n" + << " To run all tests:\n" + << " mu test\n" + << " To load files and then run all tests:\n" + << " mu test file1.mu file2.mu ...\n" + << " To load files and run only the tests in explicitly loaded files (for apps):\n" + << " mu --test-only-app test file1.mu file2.mu ...\n" + << " To load all files with a numeric prefix in a directory:\n" + << " mu directory1 directory2 ...\n" + << " You can test directories just like files.\n" + << " mu test directory1 directory2 ...\n" + << " To pass ingredients to a mu program, provide them after '--':\n" + << " mu file_or_dir1 file_or_dir2 ... -- ingredient1 ingredient2 ...\n" << "\n" - << "To browse a trace generated by a previous run:\n" - << " mu browse-trace file\n" + << " To browse a trace generated by a previous run:\n" + << " mu browse-trace file\n" ; return 0; } +//: Support for option parsing. +//: Options always begin with '--' and are always the first arguments. An +//: option will never follow a non-option. +:(before "End Commandline Parsing") +char** arg = &argv[1]; +while (argc > 1 && starts_with(*arg, "--")) { + if (false) + ; // no-op branch just so any further additions can consistently always start with 'else' + // End Commandline Options(*arg) + else + cerr << "skipping unknown option " << *arg << '\n'; + --argc; ++argv; ++arg; +} + //:: Helper function used by the above fragment of code (and later layers too, //:: who knows?). //: The :(code) directive appends function definitions to the end of the @@ -198,14 +222,6 @@ bool has_data(istream& in) { return in && !in.eof(); } -////: A hack to support faster debugging. -:(before "End Globals") -bool Test_only_app = false; -:(before "End Commandline Parsing") -if (argc > 1 && is_equal(argv[1], "--test-only-app")) { - Test_only_app = true; --argc; ++argv; -} - :(before "End Includes") #include <assert.h> |