diff options
| -rw-r--r-- | CMakeLists.txt | 8 | ||||
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | examples/bash_completion.sh | 13 | ||||
| -rw-r--r-- | examples/completion.cxx | 27 | ||||
| -rw-r--r-- | examples/gitlike.cxx (renamed from gitlike.cxx) | 0 | 
5 files changed, 55 insertions, 0 deletions
| diff --git a/CMakeLists.txt b/CMakeLists.txt index 322e8d1..d0aaa69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,14 @@ add_executable(argstest-multiple-inclusion test/multiple_inclusion_1.cxx test/mu  target_link_libraries(argstest-multiple-inclusion args)  set_property(TARGET argstest-multiple-inclusion PROPERTY CXX_STANDARD 11) +add_executable(gitlike examples/gitlike.cxx) +target_link_libraries(gitlike args) +set_property(TARGET gitlike PROPERTY CXX_STANDARD 11) + +add_executable(completion examples/completion.cxx) +target_link_libraries(completion args) +set_property(TARGET completion PROPERTY CXX_STANDARD 11) +  enable_testing()  add_test(NAME "test" COMMAND argstest)  add_test(NAME "test-multiple-inclusion" COMMAND argstest-multiple-inclusion) @@ -63,6 +63,7 @@ It:  * Allows one value flag to take a specific number of values (like `--foo first    second`, where --foo slurps both arguments).  * Allows you to have value flags only optionally accept values +* Provides autocompletion for bash  # What does it not do? @@ -179,10 +180,16 @@ int main(int argc, char **argv)  {      args::ArgumentParser parser("This is a test program.", "This goes after the options.");      args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"}); +    args::CompletionFlag completion(parser, {"complete"});      try      {          parser.ParseCLI(argc, argv);      } +    catch (args::Completion e) +    { +        std::cout << e.what(); +        return 0; +    }      catch (args::Help)      {          std::cout << parser; diff --git a/examples/bash_completion.sh b/examples/bash_completion.sh new file mode 100644 index 0000000..54937ad --- /dev/null +++ b/examples/bash_completion.sh @@ -0,0 +1,13 @@ +_args() { +    _init_completion -n 2> /dev/null +    local program comparg + +    program="${COMP_WORDS[0]}" +    comparg="--complete" # replace this with your flag + +    COMPREPLY=($("$program" "$comparg" bash "$COMP_CWORD" "${COMP_WORDS[@]}" 2> /dev/null)) +    [[ $COMPREPLY ]] && return +    _filedir +} + +complete -F _args completion diff --git a/examples/completion.cxx b/examples/completion.cxx new file mode 100644 index 0000000..3122c30 --- /dev/null +++ b/examples/completion.cxx @@ -0,0 +1,27 @@ +/* Copyright © 2016-2017 Taylor C. Richberger <taywee@gmx.com> and Pavel Belikov + * This code is released under the license described in the LICENSE file + */ + +#include "args.hxx" +#include <iostream> + +int main(int argc, const char **argv) +{ +    args::ArgumentParser p("parser"); +    args::CompletionFlag c(p, {"complete"}); +    args::ValueFlag<std::string> f(p, "name", "description", {'f', "foo"}, "abc"); +    args::ValueFlag<std::string> b(p, "name", "description", {'b', "bar"}, "abc"); +    args::MapFlag<std::string, int> m(p, "mappos", "mappos", {'m', "map"}, {{"1",1}, {"2", 2}}); +    args::Positional<std::string> pos(p, "name", "desc"); + +    try +    { +        p.ParseCLI(argc, argv); +    } +    catch (args::Completion &e) +    { +        std::cout << e.what(); +    } + +    return 0; +} diff --git a/gitlike.cxx b/examples/gitlike.cxx index aa0e20e..aa0e20e 100644 --- a/gitlike.cxx +++ b/examples/gitlike.cxx | 
