From a2e7f2beb522d9c7cda01ecfcb552d8e0c46b088 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 May 2018 14:00:14 +0200 Subject: Implement shortcut config add/create versions Now: $ bdep init -C ../hello-clang @clang ... Can be rewritten as: $ bdep init -C @clang ... --- bdep/bdep.cli | 13 +++++++++++-- bdep/config.cli | 5 +++++ bdep/config.cxx | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/bdep/bdep.cli b/bdep/bdep.cli index 595e9d9..a4e8c41 100644 --- a/bdep/bdep.cli +++ b/bdep/bdep.cli @@ -188,8 +188,17 @@ namespace bdep $ bdep init -A ../hello-clang @clang \ - We can now use the \l{bdep-status(1)} command to examine the status - of our project in its configurations: + If the configuration directory is next to the project and its name is + in the \c{\i{prj-name}\b{-}\i{cfg-name}} form, then the shortcut + version of the \c{init} can be used instead: + + \ + $ bdep init -C @gcc cc config.cxx=g++ + $ bdep init -A @clang + \ + + After initialization we can use the \l{bdep-status(1)} command to + examine the status of our project in its configurations: \ $ bdep status -a diff --git a/bdep/config.cli b/bdep/config.cli index 0a5dd74..e087693 100644 --- a/bdep/config.cli +++ b/bdep/config.cli @@ -80,6 +80,11 @@ namespace bdep such names as a more convenient way to specify build configurations (see \l{bdep-projects-configs(1)} for details). + As a shortcut, if \ci{cfg-name} is not specified and \ci{cfg-dir} is + a simple path that starts with \cb{@}, then it is treated as the name + and the configuration directory is assumed to be + \c{\i{prj-dir}\b{-}\i{cfg-name}}. + Unless the \cb{--no-default} option is specified, the first added or created build configuration is designated as the default. Several \cb{bdep} commands use such a configuration by default if no diff --git a/bdep/config.cxx b/bdep/config.cxx index 45cba1f..28289fb 100644 --- a/bdep/config.cxx +++ b/bdep/config.cxx @@ -12,6 +12,27 @@ using namespace std; namespace bdep { + // Translate the configuration directory that is actually a name (@foo) to + // the real directory (prj-foo) and name (@foo). + // + static inline void + translate_path_name (const dir_path& prj, + dir_path& path, + optional name) + { + if (name || !path.simple () || path.string ().front () != '@') + return; + + string n (move (path).string ()); // Move out. + n.erase (0, 1); // Remove leading '@'. + + path = prj; + path += '-'; + path += n; + + name = move (n); + } + shared_ptr cmd_config_add (const configuration_add_options& ao, const dir_path& prj, @@ -21,6 +42,8 @@ namespace bdep optional id, const char* what) { + translate_path_name (prj, path, name); + if (!exists (path)) fail << "configuration directory " << path << " does not exist"; @@ -142,6 +165,8 @@ namespace bdep optional name, optional id) { + translate_path_name (prj, path, name); + // Call bpkg to create the configuration. // { -- cgit v1.1