about summary refs log tree commit diff
path: root/third_party/nix/src/nix/command.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-19T19·47+0100
committerVincent Ambo <tazjin@google.com>2020-05-19T19·51+0100
commit39087321811e81e26a1a47d6967df1088dcf0e95 (patch)
tree57110be423eeb7869e9960466f4b17c0ea7cd961 /third_party/nix/src/nix/command.cc
parentcf40d08908ede4061eb15513b770c98877844b8b (diff)
style(3p/nix): Final act in the brace-wrapping saga r/777
This last change set was generated by a full clang-tidy run (including
compilation):

    clang-tidy -p ~/projects/nix-build/ \
      -checks=-*,readability-braces-around-statements -fix src/*/*.cc

Actually running clang-tidy requires some massaging to make it play
nice with Nix + meson, I'll be adding a wrapper or something for that soon.
Diffstat (limited to 'third_party/nix/src/nix/command.cc')
-rw-r--r--third_party/nix/src/nix/command.cc32
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 4c1220668c..b35fb1be98 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());
 }