From 8f41847394524fcac40d3b5620139ca7e94a18e3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 16 Apr 2020 13:46:37 +0200 Subject: [PATCH] Use Logger::stdout() --- src/nix/add-to-store.cc | 2 +- src/nix/eval.cc | 5 ++--- src/nix/flake.cc | 30 ++++++++++++------------------ src/nix/hash.cc | 5 ++--- src/nix/ls.cc | 10 ++++------ src/nix/profile.cc | 2 +- src/nix/show-config.cc | 2 +- src/nix/why-depends.cc | 2 +- 8 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc index 139db3657..ed02227db 100644 --- a/src/nix/add-to-store.cc +++ b/src/nix/add-to-store.cc @@ -50,7 +50,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand if (!dryRun) store->addToStore(info, sink.s); - std::cout << fmt("%s\n", store->printStorePath(info.path)); + logger->stdout("%s", store->printStorePath(info.path)); } }; diff --git a/src/nix/eval.cc b/src/nix/eval.cc index f23625161..96ca83325 100644 --- a/src/nix/eval.cc +++ b/src/nix/eval.cc @@ -55,16 +55,15 @@ struct CmdEval : MixJSON, InstallableCommand auto v = installable->toValue(*state).first; PathSet context; - stopProgressBar(); - if (raw) { + stopProgressBar(); std::cout << state->coerceToString(noPos, *v, context); } else if (json) { JSONPlaceholder jsonOut(std::cout); printValueAsJSON(*state, true, *v, jsonOut, context); } else { state->forceValueDeep(*v); - std::cout << *v << "\n"; + logger->stdout("%s", *v); } } }; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index e8ca0fd03..a8518a543 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -1,7 +1,6 @@ #include "command.hh" #include "common-args.hh" #include "shared.hh" -#include "progress-bar.hh" #include "eval.hh" #include "eval-inline.hh" #include "flake/flake.hh" @@ -61,12 +60,10 @@ struct CmdFlakeList : EvalCommand auto registries = getRegistries(store); - stopProgressBar(); - for (auto & registry : registries) { for (auto & entry : registry->entries) { // FIXME: format nicely - std::cout << fmt("%s %s %s\n", + logger->stdout("%s %s %s", registry->type == Registry::Flag ? "flags " : registry->type == Registry::User ? "user " : registry->type == Registry::System ? "system" : @@ -80,17 +77,17 @@ struct CmdFlakeList : EvalCommand static void printFlakeInfo(const Store & store, const Flake & flake) { - std::cout << fmt("Resolved URL: %s\n", flake.resolvedRef.to_string()); - std::cout << fmt("Locked URL: %s\n", flake.lockedRef.to_string()); + logger->stdout("Resolved URL: %s", flake.resolvedRef.to_string()); + logger->stdout("Locked URL: %s", flake.lockedRef.to_string()); if (flake.description) - std::cout << fmt("Description: %s\n", *flake.description); - std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath)); + logger->stdout("Description: %s", *flake.description); + logger->stdout("Path: %s", store.printStorePath(flake.sourceInfo->storePath)); if (auto rev = flake.lockedRef.input->getRev()) - std::cout << fmt("Revision: %s\n", rev->to_string(Base16, false)); + logger->stdout("Revision: %s", rev->to_string(Base16, false)); if (flake.sourceInfo->info.revCount) - std::cout << fmt("Revisions: %s\n", *flake.sourceInfo->info.revCount); + logger->stdout("Revisions: %s", *flake.sourceInfo->info.revCount); if (flake.sourceInfo->info.lastModified) - std::cout << fmt("Last modified: %s\n", + logger->stdout("Last modified: %s", std::put_time(std::localtime(&*flake.sourceInfo->info.lastModified), "%F %T")); } @@ -156,11 +153,10 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON void run(nix::ref store) override { auto flake = getFlake(); - stopProgressBar(); if (json) { auto json = flakeToJson(*store, flake); - std::cout << json.dump() << std::endl; + logger->stdout(json.dump()); } else printFlakeInfo(*store, flake); } @@ -177,12 +173,10 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON { auto flake = lockFlake(); - stopProgressBar(); - if (json) - std::cout << flake.lockFile.toJson() << "\n"; + logger->stdout(flake.lockFile.toJson()); else { - std::cout << fmt("%s\n", flake.flake.lockedRef); + logger->stdout("%s", flake.flake.lockedRef); std::function recurse; @@ -191,7 +185,7 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON for (const auto & [i, input] : enumerate(node.inputs)) { //auto tree2 = tree.child(i + 1 == inputs.inputs.size()); bool last = i + 1 == node.inputs.size(); - std::cout << fmt("%s" ANSI_BOLD "%s" ANSI_NORMAL ": %s\n", + logger->stdout("%s" ANSI_BOLD "%s" ANSI_NORMAL ": %s", prefix + (last ? treeLast : treeConn), input.first, std::dynamic_pointer_cast(input.second)->lockedRef); recurse(*input.second, prefix + (last ? treeNull : treeLine)); diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 0cc523f50..01628cf6c 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -60,8 +60,7 @@ struct CmdHash : Command Hash h = hashSink->finish().first; if (truncate && h.hashSize > 20) h = compressHash(h, 20); - std::cout << format("%1%\n") % - h.to_string(base, base == SRI); + logger->stdout(h.to_string(base, base == SRI)); } } }; @@ -95,7 +94,7 @@ struct CmdToBase : Command void run() override { for (auto s : args) - std::cout << fmt("%s\n", Hash(s, ht).to_string(base, base == SRI)); + logger->stdout(Hash(s, ht).to_string(base, base == SRI)); } }; diff --git a/src/nix/ls.cc b/src/nix/ls.cc index 3ef1f2750..8590199d7 100644 --- a/src/nix/ls.cc +++ b/src/nix/ls.cc @@ -34,16 +34,14 @@ struct MixLs : virtual Args, MixJSON (st.isExecutable ? "-r-xr-xr-x" : "-r--r--r--") : st.type == FSAccessor::Type::tSymlink ? "lrwxrwxrwx" : "dr-xr-xr-x"; - std::cout << - (format("%s %20d %s") % tp % st.fileSize % relPath); + auto line = fmt("%s %20d %s", tp, st.fileSize, relPath); if (st.type == FSAccessor::Type::tSymlink) - std::cout << " -> " << accessor->readLink(curPath) - ; - std::cout << "\n"; + line += " -> " + accessor->readLink(curPath); + logger->stdout(line); if (recursive && st.type == FSAccessor::Type::tDirectory) doPath(st, curPath, relPath, false); } else { - std::cout << relPath << "\n"; + logger->stdout(relPath); if (recursive) { auto st = accessor->stat(curPath); if (st.type == FSAccessor::Type::tDirectory) diff --git a/src/nix/profile.cc b/src/nix/profile.cc index c6a4ddd34..e473be47f 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -385,7 +385,7 @@ struct CmdProfileInfo : virtual EvalCommand, virtual StoreCommand, MixDefaultPro for (size_t i = 0; i < manifest.elements.size(); ++i) { auto & element(manifest.elements[i]); - std::cout << fmt("%d %s %s %s\n", i, + logger->stdout("%d %s %s %s", i, element.source ? element.source->originalRef.to_string() + "#" + element.source->attrPath : "-", element.source ? element.source->resolvedRef.to_string() + "#" + element.source->attrPath : "-", concatStringsSep(" ", store->printStorePathSet(element.storePaths))); diff --git a/src/nix/show-config.cc b/src/nix/show-config.cc index 87544f937..55a3255d2 100644 --- a/src/nix/show-config.cc +++ b/src/nix/show-config.cc @@ -23,7 +23,7 @@ struct CmdShowConfig : Command, MixJSON std::map settings; globalConfig.getSettings(settings); for (auto & s : settings) - std::cout << s.first + " = " + s.second.value + "\n"; + logger->stdout(s.first + " = " + s.second.value); } } }; diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index a9a5ec8f8..6037f37fe 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -149,7 +149,7 @@ struct CmdWhyDepends : SourceExprCommand auto pathS = store->printStorePath(node.path); assert(node.dist != inf); - std::cout << fmt("%s%s%s%s" ANSI_NORMAL "\n", + logger->stdout("%s%s%s%s" ANSI_NORMAL, firstPad, node.visited ? "\e[38;5;244m" : "", firstPad != "" ? "→ " : "",