aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-05-21 11:48:23 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-05-22 08:07:05 +0200
commit9e1330b726c5453755bcaffd1b746d5982357861 (patch)
tree90c5bbadb5b5f9f51615013ca9e9a66bd7812750
parent2ededcf152a4982e9f3caabdd2c91b6966b619d0 (diff)
Implement config-add and config-create subcommands
-rw-r--r--bdep/config.cxx123
-rw-r--r--bdep/config.hxx8
-rw-r--r--bdep/fetch.cxx4
-rw-r--r--bdep/init.cxx16
-rw-r--r--bdep/project.hxx6
5 files changed, 131 insertions, 26 deletions
diff --git a/bdep/config.cxx b/bdep/config.cxx
index 8da6211..796f534 100644
--- a/bdep/config.cxx
+++ b/bdep/config.cxx
@@ -157,12 +157,6 @@ namespace bdep
return r;
}
- static int
- cmd_config_add (const cmd_config_options&, cli::scanner&)
- {
- fail << "@@ TODO" << endf;
- }
-
shared_ptr<configuration>
cmd_config_create (const common_options& co,
const configuration_add_options& ao,
@@ -200,9 +194,96 @@ namespace bdep
}
static int
- cmd_config_create (const cmd_config_options&, cli::scanner&)
+ cmd_config_add (const cmd_config_options& o, cli::scanner& args)
{
- fail << "@@ TODO" << endf;
+ tracer trace ("config_add");
+
+ optional<string> name;
+ optional<uint64_t> id;
+ cmd_config_validate_add (o, "config add", name, id);
+
+ string arg;
+ if (args.more ())
+ arg = args.next ();
+ else if (name)
+ {
+ // Reverse into the shortcut form expected by translate_path_name().
+ //
+ arg = '@' + *name;
+ name = nullopt;
+ }
+ else
+ fail << "configuration directory argument expected";
+
+ dir_path path;
+ try
+ {
+ path = dir_path (move (arg));
+ }
+ catch (const invalid_path& e)
+ {
+ fail << "invalid configuration directory '" << arg << "'";
+ }
+
+ dir_path prj (find_project (o));
+ database db (open (prj, trace));
+
+ cmd_config_add (o,
+ prj,
+ db,
+ move (path),
+ move (name),
+ move (id));
+ return 0;
+ }
+
+ static int
+ cmd_config_create (const cmd_config_options& o, cli::scanner& args)
+ {
+ tracer trace ("config_create");
+
+ optional<string> name;
+ optional<uint64_t> id;
+ cmd_config_validate_add (o, "config create", name, id);
+
+ // 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 ();
+ else if (name)
+ {
+ // Reverse into the shortcut form expected by translate_path_name().
+ //
+ arg = '@' + *name;
+ name = nullopt;
+ }
+ else
+ fail << "configuration directory argument expected";
+
+ dir_path path;
+ try
+ {
+ path = dir_path (move (arg));
+ }
+ catch (const invalid_path& e)
+ {
+ fail << "invalid configuration directory '" << arg << "'";
+ }
+
+ dir_path prj (find_project (o));
+ database db (open (prj, trace));
+
+ cmd_config_create (o,
+ o,
+ prj,
+ db,
+ move (path),
+ args,
+ move (name),
+ move (id));
+ return 0;
}
static int
@@ -250,6 +331,32 @@ namespace bdep
o.wipe () ? "--wipe" : nullptr);
}
+ void
+ cmd_config_validate_add (const configuration_name_options& o,
+ const char* what,
+ optional<string>& name,
+ optional<uint64_t> id)
+ {
+ name = nullopt;
+ id = nullopt;
+
+ if (size_t n = o.config_name ().size ())
+ {
+ if (n > 1)
+ fail << "multiple configuration names specified for " << what;
+
+ name = o.config_name ()[0];
+ }
+
+ if (size_t n = o.config_id ().size ())
+ {
+ if (n > 1)
+ fail << "multiple configuration ids specified for " << what;
+
+ id = o.config_id ()[0];
+ }
+ }
+
int
cmd_config (const cmd_config_options& o, cli::scanner& scan)
{
diff --git a/bdep/config.hxx b/bdep/config.hxx
index 4ab8547..dc19ea1 100644
--- a/bdep/config.hxx
+++ b/bdep/config.hxx
@@ -39,6 +39,14 @@ namespace bdep
//
const char*
cmd_config_validate_add (const configuration_add_options&);
+
+ // Validate setting configuration name and/or id if specified.
+ //
+ void
+ cmd_config_validate_add (const configuration_name_options&,
+ const char* what,
+ optional<string>& name,
+ optional<uint64_t> id);
}
#endif // BDEP_CONFIG_HXX
diff --git a/bdep/fetch.cxx b/bdep/fetch.cxx
index a5c219f..487292d 100644
--- a/bdep/fetch.cxx
+++ b/bdep/fetch.cxx
@@ -32,9 +32,7 @@ namespace bdep
{
tracer trace ("fetch");
- dir_path prj (
- find_project_packages (o, true /* ignore_packages */).project);
-
+ dir_path prj (find_project (o));
database db (open (prj, trace));
transaction t (db.begin ());
diff --git a/bdep/init.cxx b/bdep/init.cxx
index dfe3a68..1adeb9a 100644
--- a/bdep/init.cxx
+++ b/bdep/init.cxx
@@ -33,22 +33,8 @@ namespace bdep
fail << "both --config-add and --config-create specified";
optional<string> nm;
- if (size_t n = o.config_name ().size ())
- {
- if (n > 1)
- fail << "multiple configuration names specified for " << m;
-
- nm = o.config_name ()[0];
- }
-
optional<uint64_t> id;
- if (size_t n = o.config_id ().size ())
- {
- if (n > 1)
- fail << "multiple configuration ids specified for " << m;
-
- id = o.config_id ()[0];
- }
+ cmd_config_validate_add (o, m, nm, id);
return ca
? cmd_config_add ( ao, prj, db, cfg, move (nm), move (id))
diff --git a/bdep/project.hxx b/bdep/project.hxx
index fe2b766..a01e5d7 100644
--- a/bdep/project.hxx
+++ b/bdep/project.hxx
@@ -178,6 +178,12 @@ namespace bdep
bool ignore_packages = false,
bool load_packages = true);
+ inline dir_path
+ find_project (const project_options& o)
+ {
+ return find_project_packages (o, true /* ignore_packages */).project;
+ }
+
// Verify all the packages are present in all the configurations.
//
void