From f02e85435d2b2bebc1fad6ef4b65227011fdcc0a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 19 Mar 2018 12:41:32 +0200 Subject: Switch to CLI-generated group_scanner --- bpkg/bpkg.cxx | 33 +++++++++++++++++++++++++-------- bpkg/buildfile | 5 +++-- bpkg/types-parsers.cxx | 2 -- bpkg/types-parsers.hxx | 7 ++----- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx index ba9fe95..ece9046 100644 --- a/bpkg/bpkg.cxx +++ b/bpkg/bpkg.cxx @@ -67,7 +67,10 @@ cfg_dir (...) -> const dir_path& {return empty_dir_path;} // template static O -init (const common_options& co, cli::scanner& scan, strings& args, bool tmp) +init (const common_options& co, + cli::group_scanner& scan, + strings& args, + bool tmp) { O o; static_cast (o) = co; @@ -90,15 +93,27 @@ init (const common_options& co, cli::scanner& scan, strings& args, bool tmp) // Parse the next chunk of options until we reach an argument (or eos). // - o.parse (scan); - - if (!scan.more ()) - break; + if (o.parse (scan)) + continue; // Fall through. } - args.push_back (scan.next ()); + // Copy over the argument including the group. + // + using scanner = cli::scanner; + using group_scanner = cli::group_scanner; + + args.push_back (group_scanner::escape (scan.next ())); + + scanner& gscan (scan.group ()); + if (gscan.more ()) + { + args.push_back ("+{"); + while (gscan.more ()) + args.push_back (group_scanner::escape (gscan.next ())); + args.push_back ("}"); + } } // Global initializations. @@ -161,7 +176,8 @@ try << system_error (errno, generic_category ()); // Sanitize. #endif - argv_file_scanner scan (argc, argv, "--options-file"); + argv_file_scanner argv_scan (argc, argv, "--options-file"); + group_scanner scan (argv_scan); // First parse common options and --version/--help. // @@ -179,7 +195,8 @@ try } strings argsv; // To be filled by parse() above. - vector_scanner args (argsv); + vector_scanner vect_args (argsv); + group_scanner args (vect_args); const common_options& co (o); diff --git a/bpkg/buildfile b/bpkg/buildfile index f25e08e..4c4c715 100644 --- a/bpkg/buildfile +++ b/bpkg/buildfile @@ -113,8 +113,9 @@ if $cli.configured cli.options += -I $src_root --include-with-brackets --include-prefix bpkg \ --guard-prefix BPKG --cxx-prologue "#include " \ --cli-namespace bpkg::cli --generate-vector-scanner --generate-file-scanner \ ---generate-specifier --generate-parse --page-usage 'bpkg::print_$name$_' \ ---ansi-color --include-base-last --option-length 23 +--generate-group-scanner --keep-separator --generate-specifier \ +--generate-parse --page-usage 'bpkg::print_$name$_' --ansi-color \ +--include-base-last --option-length 23 cli.cxx{common-options}: cli.options += --short-usage --long-usage # Both. cli.cxx{bpkg-options}: cli.options += --short-usage --suppress-undocumented diff --git a/bpkg/types-parsers.cxx b/bpkg/types-parsers.cxx index 41b231f..b414bb3 100644 --- a/bpkg/types-parsers.cxx +++ b/bpkg/types-parsers.cxx @@ -4,8 +4,6 @@ #include -#include // bpkg::cli namespace - namespace bpkg { namespace cli diff --git a/bpkg/types-parsers.hxx b/bpkg/types-parsers.hxx index 4f1dfc7..349eaae 100644 --- a/bpkg/types-parsers.hxx +++ b/bpkg/types-parsers.hxx @@ -11,17 +11,14 @@ #include #include + +#include // bpkg::cli namespace #include namespace bpkg { namespace cli { - class scanner; - - template - struct parser; - template <> struct parser { -- cgit v1.1