From cc7216e60cd6893974e687599682c5e6233e9b69 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 14 Mar 2018 14:29:43 +0200 Subject: Initial implementation of new command --- bdep/init.cxx | 180 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 103 insertions(+), 77 deletions(-) (limited to 'bdep/init.cxx') 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 + 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 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 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& 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 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 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& 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; } -- cgit v1.1