// file : bdep/config.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #include #include #include #include using namespace std; namespace bdep { shared_ptr cmd_config_add (const dir_path& prj, database& db, dir_path path, optional name, optional def, optional id) { if (!exists (path)) fail << "configuration directory " << path << " does not exist"; transaction t (db.begin ()); using count = configuration_count; using query = bdep::query; // By default the first added configuration is the default. // if (!def) def = (db.query_value () == 0); // Make sure the configuration path is absolute and normalized. Also // derive relative to project directory path is possible. // path.complete (); path.normalize (); optional rel_path; try {rel_path = path.relative (prj);} catch (const invalid_path&) {} shared_ptr r ( new configuration { id, name, path, move (rel_path), *def, {} /* packages */}); try { db.persist (r); } catch (const odb::exception&) { // See if this is id, name, or path conflict. // if (id && db.query_value (query::id == *id) != 0) fail << "configuration with id " << *id << " already exists " << "in project " << prj; if (name && db.query_value (query::name == *name) != 0) fail << "configuration with name '" << *name << "' already exists " << "in project " << prj; if (db.query_value (query::path == path.string ()) != 0) fail << "configuration with path " << path << " already exists " << "in project " << prj; // Hm, what could that be? // throw; } t.commit (); if (verb) { diag_record dr (text); /* */ dr << "added configuration "; if (r->name) dr << '@' << *r->name << ' '; /* */ dr << r->path << " (" << *r->id; if (r->default_) dr << ", default"; /* */ dr << ')'; } return r; } int cmd_config (const cmd_config_options& o, cli::scanner&) { //@@ TODO: get subcommand and pass to tracer. tracer trace ("config"); //@@ TODO: validate project/config options for subcommands. for (const string& n: o.config_name ()) text << n; return 0; } }