aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bdep/new.cli3
-rw-r--r--bdep/new.cxx30
2 files changed, 33 insertions, 0 deletions
diff --git a/bdep/new.cli b/bdep/new.cli
index 3ec489c..cdc84c3 100644
--- a/bdep/new.cli
+++ b/bdep/new.cli
@@ -44,6 +44,9 @@ namespace bdep
\cb{--source} first create according to <spec> a new \cb{build2}
project/package called <name> in the <name> subdirectory of the current
working directory (unless overridden with \c{\b{--output-dir}|\b{-o}}).
+ If <name> contains a directory component, then the project/package is
+ created in this directory, as if it was specified with
+ \c{\b{--output-dir}|\b{-o}}.
The first form then, unless the \cb{--no-init} option is specified,
initializes an empty project database as if by executing the
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 2a8a52d..e870648 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -524,7 +524,37 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args)
//
string a;
if (args.more ())
+ {
a = args.next ();
+
+ // Reduce name with a directory component to the simple name with
+ // --output-dir case.
+ //
+ if (path::traits_type::find_separator (a) != string::npos)
+ {
+ try
+ {
+ dir_path p (move (a));
+ a = p.leaf ().string ();
+
+ if (!p.simple ())
+ {
+ if (o.output_dir_specified ())
+ {
+ fail << "both --output-dir|-o and directory component in name "
+ << "specified";
+ }
+
+ o.output_dir (move (p));
+ o.output_dir_specified (true);
+ }
+ }
+ catch (const invalid_path& e)
+ {
+ fail << "invalid path '" << e.path << "'";
+ }
+ }
+ }
else
{
if (!o.output_dir_specified ())