aboutsummaryrefslogtreecommitdiff
path: root/bdep/sync.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-09-20 21:05:04 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-09-22 17:41:12 +0300
commit7cf3492e05e304fa4fdb17763a2bec9363dfcef5 (patch)
treef83db215283d70a91fef3a0869fc381727733356 /bdep/sync.cxx
parentaeaa89ac75ac83e3953817de74bb901260b6ac81 (diff)
Allow options and arguments in any order inside argument groups in sync
Also optimize options/arguments parsing in bdep.cxx.
Diffstat (limited to 'bdep/sync.cxx')
-rw-r--r--bdep/sync.cxx29
1 files changed, 20 insertions, 9 deletions
diff --git a/bdep/sync.cxx b/bdep/sync.cxx
index ea76b17..d03f18a 100644
--- a/bdep/sync.cxx
+++ b/bdep/sync.cxx
@@ -4,7 +4,7 @@
#include <bdep/sync.hxx>
#include <list>
-#include <cstring> // strchr()
+#include <cstring> // strchr(), strcmp()
#include <libbpkg/manifest.hxx>
@@ -1305,6 +1305,12 @@ namespace bdep
{
while (gs.more ())
{
+ // Stop (rather than fail) on unknown option to handle
+ // -@<cfg-name>.
+ //
+ if (po.parse (gs, cli::unknown_mode::stop) && !gs.more ())
+ break;
+
const char* a (gs.peek ());
// Handle @<cfg-name> & -@<cfg-name>.
@@ -1316,15 +1322,24 @@ namespace bdep
if (n.empty ())
fail << "missing configuration name in '" << a << "'";
- po.config_name ().emplace_back (move (n), gs.position ());
+ po.config_name ().emplace_back (move (n));
po.config_name_specified (true);
gs.next ();
- continue;
}
+ //
+ // Handle unknown option and argument.
+ //
+ else
+ {
+ // Don't report '-' and '--' as unknown options and let bpkg
+ // deal with arguments other than configuration variables.
+ //
+ if (a[0] == '-' && a[1] != '\0' && strcmp (a, "--") != 0)
+ throw cli::unknown_option (a);
- if (!po.parse (gs))
- break;
+ args.push_back (gs.next ());
+ }
}
}
catch (const cli::exception& e)
@@ -1440,10 +1455,6 @@ namespace bdep
}
}
- // Add the rest of group arguments (e.g., configuration variables).
- //
- for (; gs.more (); args.push_back (gs.next ())) ;
-
args.push_back ("}+");
}