aboutsummaryrefslogtreecommitdiff
path: root/bdep/new.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-12-13 12:01:21 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-12-13 12:01:21 +0200
commit151c64b5d7ae3c2f506f8a94603957f53e0b2dbb (patch)
tree4f088bb8d12e227d9fdc5ebeb50e8999e65d700c /bdep/new.cxx
parent1d85dec79e6b5dab3b1a7988f95603a8918e2993 (diff)
Allow specifying directory component as part of package name in bdep-new
The behavior is equivalent to specifying the directory with --output-dir|-o: bdep new foo/hello bdep new -o foo/hello hello
Diffstat (limited to 'bdep/new.cxx')
-rw-r--r--bdep/new.cxx30
1 files changed, 30 insertions, 0 deletions
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 ())