diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2022-07-19 20:20:47 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2022-07-20 13:48:26 +0300 |
commit | ddafa0f3475fe532a66879b807b0a8f47ecb201e (patch) | |
tree | 569a72699c810c9157c7ba1a6465d1af839017f1 /bdep | |
parent | 03cb180e90129ef3435dc8ad81deff1810a5c5bf (diff) |
Fail if no module specified for being created configuration
Diffstat (limited to 'bdep')
-rw-r--r-- | bdep/bdep.cxx | 4 | ||||
-rw-r--r-- | bdep/config.cli | 2 | ||||
-rw-r--r-- | bdep/config.cxx | 56 | ||||
-rw-r--r-- | bdep/init.cli | 2 | ||||
-rw-r--r-- | bdep/init.cxx | 36 | ||||
-rw-r--r-- | bdep/new.cli | 2 | ||||
-rw-r--r-- | bdep/new.cxx | 55 |
7 files changed, 145 insertions, 12 deletions
diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx index 9731aaa..3061650 100644 --- a/bdep/bdep.cxx +++ b/bdep/bdep.cxx @@ -530,7 +530,7 @@ try // Temp dir is initialized manually for these commands. // - COMMAND_IMPL (new_, new, "new", false, false); + COMMAND_IMPL (new_, new, "new", true, false); COMMAND_IMPL (sync, sync, "sync", false, false); COMMAND_IMPL (init, init, "init", true, true); @@ -540,7 +540,7 @@ try COMMAND_IMPL (release, release, "release", false, true); COMMAND_IMPL (publish, publish, "publish", false, true); COMMAND_IMPL (deinit, deinit, "deinit", false, true); - COMMAND_IMPL (config, config, "config", false, true); + COMMAND_IMPL (config, config, "config", true, true); COMMAND_IMPL (test, test, "test", false, true); COMMAND_IMPL (update, update, "update", false, true); COMMAND_IMPL (clean, clean, "clean", false, true); diff --git a/bdep/config.cli b/bdep/config.cli index b5b7225..261115c 100644 --- a/bdep/config.cli +++ b/bdep/config.cli @@ -32,7 +32,7 @@ namespace bdep \c{<cfg-spec> = \b{@}<cfg-name> | \b{--config}|\b{-c} <cfg-dir>\n <prj-spec> = \b{--directory}|\b{-d} <prj-dir>\n - <cfg-args> = [\b{--} <bpkg-options>] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]} + <cfg-args> = [\b{--} [<bpkg-options>]] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]} \h|DESCRIPTION| diff --git a/bdep/config.cxx b/bdep/config.cxx index 38888e1..0960909 100644 --- a/bdep/config.cxx +++ b/bdep/config.cxx @@ -660,12 +660,36 @@ namespace bdep optional<uint64_t> id; cmd_config_validate_add (o, "config create", name, id); + // Skip `--` which separates the directory argument, if any, as for + // example in: + // + // $ bdep config create -- @gcc cc config.cxx=g++ + // + bool sep (false); + if (args.more () && args.peek () == string ("--")) + { + sep = true; + args.next (); + } + // Note that the shortcut will only work if there are no cfg-args which // is not very likely. Oh, well. // string arg; if (args.more ()) + { arg = args.next (); + + // Skip `--` which separates the bpkg options, if any, as for example in: + // + // $ bdep config create ../foo-gcc -- -v cc config.cxx=g++ + // + if (args.more () && args.peek () == string ("--")) + { + sep = true; + args.next (); + } + } else if (name) { // Reverse into the shortcut form expected by translate_path_name(). @@ -689,8 +713,38 @@ namespace bdep dir_path prj (find_project (o)); database db (open (prj, trace)); + // Read the configuration arguments. + // + // Also make sure that at least one module is specified, unless the `--` + // separator is specified (in which case we assume that the user knows + // what they are doing). + // strings cfg_args; - for (; args.more (); cfg_args.push_back (args.next ())) ; + bool module (false); + + while (args.more ()) + { + string a (args.next ()); + + // Assume the argument is a module unless it is a variable (note that it + // can't be --existing|-e since no --). + // + // Note: the arguments can't be bpkg options if unseparated. + // + if (!sep) + { + if (a.find ('=') == string::npos) + module = true; + } + + cfg_args.push_back (move (a)); + } + + if (!sep && !module) + fail << "no module(s) specified for configuration to be created" << + info << "for example, for C/C++ configuration specify 'cc'" << + info << "use '--' to create configuration without modules" << + info << "for example: bdep config create ... --"; cmd_config_create (o, o, diff --git a/bdep/init.cli b/bdep/init.cli index 9ca9a44..ed44efa 100644 --- a/bdep/init.cli +++ b/bdep/init.cli @@ -30,7 +30,7 @@ namespace bdep <pkg-spec> = (\b{--directory}|\b{-d} <pkg-dir>)... | <prj-spec>\n <prj-spec> = \b{--directory}|\b{-d} <prj-dir>\n <pkg-args> = (\b{?}<pkg> | <cfg-var>)...\n - <cfg-args> = [\b{--} <bpkg-options>] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]} + <cfg-args> = [\b{--} [<bpkg-options>]] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]} \h|DESCRIPTION| diff --git a/bdep/init.cxx b/bdep/init.cxx index 7533b4d..4599628 100644 --- a/bdep/init.cxx +++ b/bdep/init.cxx @@ -359,8 +359,12 @@ namespace bdep // Skip the first `--` separator, if any. // + bool sep (false); if (args.more () && args.peek () == string ("--")) + { + sep = true; args.next (); + } configurations cfgs; { @@ -374,8 +378,36 @@ namespace bdep // Read the configuration arguments until we reach the second `--` // separator or eos. // - for (string a; args.more () && (a = args.next ()) != "--"; ) - cfg_args.push_back (move (a)); + // Also make sure that there is at least one module unless the `--` + // separator is specified (see cmd_config_create() for details). + // + bool module (false); + while (args.more ()) + { + string a (args.next ()); + + if (a == "--") + { + sep = true; + break; + } + else + { + if (!sep) + { + if (a.find ('=') == string::npos) + module = true; + } + + cfg_args.push_back (move (a)); + } + } + + if (!sep && !module) + fail << "no module(s) specified for configuration to be created" << + info << "for example, for C/C++ configuration specify 'cc'" << + info << "use '--' to create configuration without modules" << + info << "for example: bdep init -C ... --"; } cfgs.push_back ( diff --git a/bdep/new.cli b/bdep/new.cli index cdc84c3..8f3b094 100644 --- a/bdep/new.cli +++ b/bdep/new.cli @@ -33,7 +33,7 @@ namespace bdep <type> \ \ \ \ = \b{--type}|\b{-t} (\b{exe}|\b{lib}|\b{bare}|\b{empty})[\b{,}<type-opt>...]\n <vcs> \ \ \ \ \ = \b{--vcs}|\b{-s} \ (\b{git}|\b{none})[\b{,}<vcs-opt>...]\n <prj-spec> = \b{--directory}|\b{-d} <prj-dir>\n - <cfg-args> = [\b{--} <bpkg-options>] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]} + <cfg-args> = [\b{--} [<bpkg-options>]] [\b{--existing}|\b{-e} | (<module> | <cfg-var>)...]} \h|DESCRIPTION| diff --git a/bdep/new.cxx b/bdep/new.cxx index ad267b8..8f0c836 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -519,6 +519,17 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) vcs vc (o.vcs ()); bool vc_o (o.vcs_specified ()); + // Skip `--` which separates the name argument, if any, as for example in: + // + // $ bdep new -- hello + // + bool sep (false); + if (args.more () && args.peek () == string ("--")) + { + sep = true; + args.next (); + } + // Check if we have the argument (name). If not, then we use the specified // output or current working directory name. // @@ -527,6 +538,16 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) { a = args.next (); + // Skip `--` which separates the bpkg options, if any, as for example in: + // + // $ bdep new -C @cfg hello -- -v cc config.cxx=g++ + // + if (args.more () && args.peek () == string ("--")) + { + sep = true; + args.next (); + } + // Reduce name with a directory component to the simple name with // --output-dir case. // @@ -593,6 +614,36 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) << " name: " << e; } + strings cfg_args; + if (cc) + { + // Read the configuration arguments. + // + // Also make sure that there is at least one module unless the `--` + // separator is specified (see cmd_config_create() for details). + // + bool module (false); + + while (args.more ()) + { + string a (args.next ()); + + if (!sep) + { + if (a.find ('=') == string::npos) + module = true; + } + + cfg_args.push_back (move (a)); + } + + if (!sep && !module) + fail << "no module(s) specified for configuration to be created" << + info << "for example, for C/C++ configuration specify 'cc'" << + info << "use '--' to create configuration without modules" << + info << "for example: bdep new -C ... --"; + } + // Full package name vs base name (e.g., libhello in libhello.bash) vs the // name stem (e.g, hello in libhello). // @@ -3231,10 +3282,6 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) if (t != type::empty) // prj == pkg pkgs.push_back (package_location {move (pkgn), nullopt, dir_path ()}); - strings cfg_args; - if (cc) - for (; args.more (); cfg_args.push_back (args.next ())) ; - configurations cfgs { cmd_init_config ( o, |