aboutsummaryrefslogtreecommitdiff
path: root/bdep/init.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-14 14:29:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-14 14:29:43 +0200
commitcc7216e60cd6893974e687599682c5e6233e9b69 (patch)
tree2304123805fda221d189034b2b85b3aac56055f4 /bdep/init.cxx
parent6be9c7746f92aa721782a4d0eaff5f901fc528cd (diff)
Initial implementation of new command
Diffstat (limited to 'bdep/init.cxx')
-rw-r--r--bdep/init.cxx180
1 files changed, 103 insertions, 77 deletions
diff --git a/bdep/init.cxx b/bdep/init.cxx
index a86079f..f41a62b 100644
--- a/bdep/init.cxx
+++ b/bdep/init.cxx
@@ -16,6 +16,99 @@ using namespace std;
namespace bdep
{
+ shared_ptr<configuration>
+ cmd_init_config (const configuration_name_options& o,
+ const dir_path& prj,
+ database& db,
+ const dir_path& cfg,
+ bool ca, bool cc)
+ {
+ const char* m (!ca ? "--config-create" :
+ !cc ? "--config-add" :
+ nullptr);
+
+ if (m == nullptr)
+ fail << "both --config-add and --config-create specified";
+
+ optional<string> name;
+ if (size_t n = o.config_name ().size ())
+ {
+ if (n > 1)
+ fail << "multiple configuration names specified for " << m;
+
+ name = 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];
+ }
+
+ return ca
+ ? cmd_config_add (prj,
+ db,
+ cfg,
+ move (name),
+ nullopt /* default */, // @@ TODO: --[no]-default
+ move (id))
+ : nullptr; // @@ TODO: create
+ }
+
+ void
+ cmd_init (const common_options& o,
+ const dir_path& prj,
+ database& db,
+ const configurations& cfgs,
+ const package_locations& pkgs)
+ {
+ // We do each configuration in a separate transaction so that our state
+ // reflects the bpkg configuration as closely as possible.
+ //
+ for (const shared_ptr<configuration>& c: cfgs)
+ {
+ transaction t (db.begin ());
+
+ // Add project repository to the configuration. Note that we don't fetch
+ // it since sync is going to do it anyway.
+ //
+ run_bpkg (o,
+ "add",
+ "-d", c->path,
+ "--type", "dir",
+ prj);
+
+ for (const package_location& p: pkgs)
+ {
+ if (find_if (c->packages.begin (),
+ c->packages.end (),
+ [&p] (const package_state& s)
+ {
+ return p.name == s.name;
+ }) != c->packages.end ())
+ {
+ if (verb)
+ info << "package " << p.name << " is already initialized "
+ << "in configuration " << *c;
+
+ continue;
+ }
+
+ c->packages.push_back (package_state {p.name});
+ }
+
+ db.update (c);
+ t.commit ();
+
+ //@@ --no-sync for some reason?
+ //
+ cmd_sync (o, prj, c);
+ }
+ }
+
int
cmd_init (const cmd_init_options& o, cli::scanner&)
{
@@ -68,40 +161,14 @@ namespace bdep
configurations cfgs;
if (ca || cc)
{
- const char* m (!ca ? "--config-create" :
- !cc ? "--config-add" :
- nullptr);
-
- if (m == nullptr)
- fail << "both --config-add and --config-create specified";
-
- optional<string> name;
- if (size_t n = o.config_name ().size ())
- {
- if (n > 1)
- fail << "multiple configuration names specified for " << m;
-
- name = 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];
- }
-
cfgs.push_back (
- ca
- ? cmd_config_add (prj,
- db,
- o.config_add (),
- move (name),
- nullopt /* default */, // @@ TODO: --[no]-default
- move (id))
- : nullptr); // @@ TODO: create
+ cmd_init_config (
+ o,
+ prj,
+ db,
+ ca ? o.config_add () : o.config_create (),
+ ca,
+ cc));
// Fall through.
}
@@ -116,52 +183,11 @@ namespace bdep
t.commit ();
}
- // Initialize each package in each configuration skipping those that are
- // already initialized. Do each configuration in a separate transaction so
- // that our state reflects the bpkg configuration as closely as possible.
- // Then synchronize each configuration.
+ // Initialize each package in each configuration.
//
- for (const shared_ptr<configuration>& c: cfgs)
- {
- transaction t (db.begin ());
-
- // Add project repository to the configuration. Note that we don't fetch
- // it since sync is going to do it anyway.
- //
- run_bpkg (o,
- "add",
- "-d", c->path,
- "--type", "dir",
- prj);
-
- for (const package_location& p: pp.packages)
- {
- if (find_if (c->packages.begin (),
- c->packages.end (),
- [&p] (const package_state& s)
- {
- return p.name == s.name;
- }) != c->packages.end ())
- {
- if (verb)
- info << "package " << p.name << " is already initialized "
- << "in configuration " << *c;
-
- continue;
- }
-
- c->packages.push_back (package_state {p.name});
- }
-
- db.update (c);
- t.commit ();
-
- //@@ --no-sync for some reason?
- //
- cmd_sync (o, prj, c);
- }
+ cmd_init (o, prj, db, cfgs, pp.packages);
- //@@ TODO: print project/package(s) being initialized.
+ //@@ TODO: print project/package(s) being initialized? (analog to new?)
return 0;
}