aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-28 08:54:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-28 08:54:19 +0200
commit08a439c5d4e4f8c6a448f4f85b60b5fef6d7ca15 (patch)
tree41acd3f6df3ba8f144d16002598f4d0b604d1872
parent749cd532f72108b26a78cd2f0012e6abd72b3ce8 (diff)
Warn about unexpected arguments
-rw-r--r--bpkg/bpkg.cxx122
1 files changed, 67 insertions, 55 deletions
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index 3ac5002..059d7c5 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -142,73 +142,85 @@ try
// Handle commands.
//
-
- // help
- //
- if (cmd.help ())
+ for (;;)
{
- assert (h);
- help (ho, "help", help_options::print_usage);
- return 0;
- }
-
+ // help
+ //
+ if (cmd.help ())
+ {
+ assert (h);
+ help (ho, "help", help_options::print_usage);
+ break;
+ }
- // Commands.
- //
- // if (cmd.pkg_verify ())
- // {
- // if (h)
- // help (ho, "pkg-verify", pkg_verify_options::print_usage);
- // else
- // pkg_verify (parse<pkg_verify_options> (co, args), args);
- //
- // return 0;
- // }
- //
-#define ANY_COMMAND(OBJ, CMD) \
- if (cmd.OBJ##_##CMD ()) \
- { \
- if (h) \
- help (ho, #OBJ"-"#CMD, OBJ##_##CMD##_options::print_usage); \
- else \
- OBJ##_##CMD (parse<OBJ##_##CMD##_options> (co, args), args); \
- \
- return 0; \
- }
+ // Commands.
+ //
+ // if (cmd.pkg_verify ())
+ // {
+ // if (h)
+ // help (ho, "pkg-verify", pkg_verify_options::print_usage);
+ // else
+ // pkg_verify (parse<pkg_verify_options> (co, args), args);
+ //
+ // return 0;
+ // }
+ //
+#define ANY_COMMAND(OBJ, CMD) \
+ if (cmd.OBJ##_##CMD ()) \
+ { \
+ if (h) \
+ help (ho, #OBJ"-"#CMD, OBJ##_##CMD##_options::print_usage); \
+ else \
+ OBJ##_##CMD (parse<OBJ##_##CMD##_options> (co, args), args); \
+ \
+ break; \
+ }
- // pkg-* commands
- //
+ // pkg-* commands
+ //
#define PKG_COMMAND(CMD) ANY_COMMAND(pkg, CMD)
- PKG_COMMAND (verify);
- PKG_COMMAND (status);
- PKG_COMMAND (fetch);
- PKG_COMMAND (unpack);
- PKG_COMMAND (purge);
- PKG_COMMAND (configure);
- PKG_COMMAND (disfigure);
- PKG_COMMAND (update);
- PKG_COMMAND (clean);
-
- // cfg-* commands
- //
+ PKG_COMMAND (verify);
+ PKG_COMMAND (status);
+ PKG_COMMAND (fetch);
+ PKG_COMMAND (unpack);
+ PKG_COMMAND (purge);
+ PKG_COMMAND (configure);
+ PKG_COMMAND (disfigure);
+ PKG_COMMAND (update);
+ PKG_COMMAND (clean);
+
+ // cfg-* commands
+ //
#define CFG_COMMAND(CMD) ANY_COMMAND(cfg, CMD)
- CFG_COMMAND (create);
+ CFG_COMMAND (create);
- // rep-* commands
- //
+ // rep-* commands
+ //
#define REP_COMMAND(CMD) ANY_COMMAND(rep, CMD)
- REP_COMMAND (add);
- REP_COMMAND (fetch);
- REP_COMMAND (info);
- REP_COMMAND (create);
+ REP_COMMAND (add);
+ REP_COMMAND (fetch);
+ REP_COMMAND (info);
+ REP_COMMAND (create);
+
+ assert (false);
+ fail << "unhandled command";
+ }
- // @@ Would be nice to check that args doesn't contain any junk left.
+ // Warn if args contain some leftover junk. We already successfully
+ // performed the command so failing would probably be misleading.
+ //
+ if (args.more ())
+ {
+ diag_record dr;
+ dr << warn << "ignoring unexpected argument(s)";
+ while (args.more ())
+ dr << " '" << args.next () << "'";
+ }
- assert (false); // Unhandled command.
- return 1;
+ return 0;
}
catch (const failed&)
{