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/config.cxx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'bdep/config.cxx') 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