diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-04-10 20:28:55 +0100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-04-10 20:28:55 +0100 |
| commit | f6eea456d4c5fc948828ea13de3179420f10f79a (patch) | |
| tree | 022862fc73f2c49a3e203f65d2548f69111b3598 /src | |
| parent | 1f74ca1a4f2574f6b14f50dbfe15bf86cfffb17f (diff) | |
| parent | 16068321c1db5753de1a5f6c51859e7c843aa501 (diff) | |
Merge remote-tracking branch 'lenormf/fix-help-flag'
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/main.cc b/src/main.cc index 347428f1..d0ccdf58 100644 --- a/src/main.cc +++ b/src/main.cc @@ -801,12 +801,33 @@ int main(int argc, char* argv[]) { "ui", { true, "set the type of user interface to use (ncurses, dummy, or json)" } }, { "l", { false, "list existing sessions" } }, { "clear", { false, "clear dead sessions" } }, - { "ro", { false, "readonly mode" } } } + { "ro", { false, "readonly mode" } }, + { "help", { false, "display a help message and quit" } } } }; + try { + auto show_usage = [&]() + { + write_stdout(format("Usage: {} [options] [file]... [+<line>[:<col>]|+:]\n\n" + "Options:\n" + "{}\n" + "Prefixing a positional argument with a plus (`+`) sign will place the\n" + "cursor at a given set of coordinates, or the end of the buffer if the plus\n" + "sign is followed only by a colon (`:`)\n", + argv[0], generate_switches_doc(param_desc.switches))); + return 0; + }; + + if (contains(ConstArrayView<char*>{argv+1, (size_t)argc-1}, StringView{"--help"})) + return show_usage(); + ParametersParser parser(params, param_desc); + const bool show_help_message = (bool)parser.get_switch("help"); + if (show_help_message) + return show_usage(); + const bool list_sessions = (bool)parser.get_switch("l"); const bool clear_sessions = (bool)parser.get_switch("clear"); if (list_sessions or clear_sessions) |
