From c6dce94e537f394cb3126d0883de7dcb4a42ea01 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 21 May 2018 13:59:57 +0200 Subject: Implement config-list command, adjust config-add/create diagnostics --- bdep/config.cxx | 87 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 13 deletions(-) (limited to 'bdep/config.cxx') diff --git a/bdep/config.cxx b/bdep/config.cxx index 8193140..84aa77d 100644 --- a/bdep/config.cxx +++ b/bdep/config.cxx @@ -4,6 +4,8 @@ #include +#include // cout + #include #include #include @@ -12,6 +14,19 @@ using namespace std; namespace bdep { + template + void + print_configuration (O& o, const shared_ptr& c) + { + char s (' '); + + if (c->name) o << '@' << *c->name << ' '; + /* */ o << c->path << ' ' << *c->id; + if (c->default_) {o << s << "default"; s = ',';} + if (c->forward) {o << s << "forwarded"; s = ',';} + if (c->auto_sync) {o << s << "auto-synchronized"; s = ',';} + } + // Translate the configuration directory that is actually a name (@foo or // -@foo) to the real directory (prj-foo) and name (@foo). // @@ -145,13 +160,8 @@ namespace bdep if (verb) { diag_record dr (text); - /* */ dr << what << " configuration "; - if (r->name) dr << '@' << *r->name << ' '; - /* */ dr << r->path << " (" << *r->id; - if (r->default_) dr << ", default"; - if (r->forward) dr << ", forwarded"; - if (r->auto_sync) dr << ", auto-synchronized"; - /* */ dr << ')'; + dr << what << " configuration "; + print_configuration (dr, r); } return r; @@ -287,6 +297,57 @@ namespace bdep } static int + cmd_config_list (const cmd_config_options& o, cli::scanner&) + { + tracer trace ("config_list"); + + dir_path prj (find_project (o)); + database db (open (prj, trace)); + + transaction t (db.begin ()); + + configurations cfgs; + if (o.config_specified () || // Note: handling --all|-a ourselves. + o.config_id_specified () || + o.config_name_specified ()) + { + cfgs = find_configurations (o, + prj, + t, + false /* fallback_default */, + false /* validate */); + } + else + { + using query = bdep::query; + + // We want to show the default configuration first, then sort them + // by name, and then by path. + // + for (auto c: pointer_result ( + db.query ("ORDER BY" + + query::default_ + "DESC," + + query::name + "IS NULL," + + query::name + "," + + query::path))) + cfgs.push_back (move (c)); + } + + t.commit (); + + + for (const shared_ptr& c: cfgs) + { + //@@ TODO: use tabular layout facility when ready. + + print_configuration (cout, c); + cout << endl; + } + + return 0; + } + + static int cmd_config_remove (const cmd_config_options& o, cli::scanner&) { tracer trace ("config_remove"); @@ -396,30 +457,30 @@ namespace bdep parse_command (scan, "config subcommand", "bdep help config")); - // Validate options/subcommands. // if (const char* n = cmd_config_validate_add (o)) { - if (!(c.add () || c.create () || c.set ())) - fail << n << " not valid for this command"; + if (!c.add () && !c.create () && !c.set ()) + fail << n << " not valid for this subcommand"; if (o.wipe () && !c.create ()) - fail << "--wipe is not valid for this command"; + fail << "--wipe is not valid for this subcommand"; } // --all // if (o.all ()) { - if (!c.remove ()) - fail << "--all not valid for this command"; + if (!c.list () && !c.remove () && !c.set ()) + fail << "--all not valid for this subcommand"; } // Dispatch to subcommand function. // if (c.add ()) return cmd_config_add (o, scan); if (c.create ()) return cmd_config_create (o, scan); + if (c.list ()) return cmd_config_list (o, scan); if (c.remove ()) return cmd_config_remove (o, scan); if (c.rename ()) return cmd_config_rename (o, scan); if (c.set ()) return cmd_config_set (o, scan); -- cgit v1.1