diff options
Diffstat (limited to 'third_party/nix/src/nix/command.cc')
-rw-r--r-- | third_party/nix/src/nix/command.cc | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/third_party/nix/src/nix/command.cc b/third_party/nix/src/nix/command.cc index 4c1220668c8a..b35fb1be9898 100644 --- a/third_party/nix/src/nix/command.cc +++ b/third_party/nix/src/nix/command.cc @@ -14,10 +14,11 @@ void Command::printHelp(const string& programName, std::ostream& out) { if (!exs.empty()) { out << "\n"; out << "Examples:\n"; - for (auto& ex : exs) + for (auto& ex : exs) { out << "\n" << " " << ex.description << "\n" // FIXME: wrap << " $ " << ex.command << "\n"; + } } } @@ -26,8 +27,9 @@ MultiCommand::MultiCommand(const Commands& _commands) : commands(_commands) { "command", 1, true, [=](std::vector<std::string> ss) { assert(!command); auto i = commands.find(ss[0]); - if (i == commands.end()) + if (i == commands.end()) { throw UsageError("'%s' is not a recognised command", ss[0]); + } command = i->second; }}); } @@ -50,8 +52,9 @@ void MultiCommand::printHelp(const string& programName, std::ostream& out) { Table2 table; for (auto& command : commands) { auto descr = command.second->description(); - if (!descr.empty()) + if (!descr.empty()) { table.push_back(std::make_pair(command.second->name(), descr)); + } } printTable(out, table); @@ -72,16 +75,19 @@ bool MultiCommand::processFlag(Strings::iterator& pos, Strings::iterator end) { } bool MultiCommand::processArgs(const Strings& args, bool finish) { - if (command) + if (command) { return command->processArgs(args, finish); - else + } else { return Args::processArgs(args, finish); + } } StoreCommand::StoreCommand() {} ref<Store> StoreCommand::getStore() { - if (!_store) _store = createStore(); + if (!_store) { + _store = createStore(); + } return ref<Store>(_store); } @@ -90,17 +96,18 @@ ref<Store> StoreCommand::createStore() { return openStore(); } void StoreCommand::run() { run(getStore()); } StorePathsCommand::StorePathsCommand(bool recursive) : recursive(recursive) { - if (recursive) + if (recursive) { mkFlag() .longName("no-recursive") .description("apply operation to specified paths only") .set(&this->recursive, false); - else + } else { mkFlag() .longName("recursive") .shortName('r') .description("apply operation to closure of the specified paths") .set(&this->recursive, true); + } mkFlag(0, "all", "apply operation to the entire store", &all); } @@ -109,16 +116,18 @@ void StorePathsCommand::run(ref<Store> store) { Paths storePaths; if (all) { - if (installables.size()) + if (installables.size()) { throw UsageError("'--all' does not expect arguments"); + } for (auto& p : store->queryAllValidPaths()) { storePaths.push_back(p); } } else { - for (auto& p : toStorePaths(store, NoBuild, installables)) + for (auto& p : toStorePaths(store, NoBuild, installables)) { storePaths.push_back(p); + } if (recursive) { PathSet closure; @@ -134,8 +143,9 @@ void StorePathsCommand::run(ref<Store> store) { void StorePathCommand::run(ref<Store> store) { auto storePaths = toStorePaths(store, NoBuild, installables); - if (storePaths.size() != 1) + if (storePaths.size() != 1) { throw UsageError("this command requires exactly one store path"); + } run(store, *storePaths.begin()); } |