Use Logger::stdout()

This commit is contained in:
Eelco Dolstra 2020-04-16 13:46:37 +02:00
parent 696c026006
commit 8f41847394
8 changed files with 24 additions and 34 deletions

View file

@ -50,7 +50,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand
if (!dryRun) if (!dryRun)
store->addToStore(info, sink.s); store->addToStore(info, sink.s);
std::cout << fmt("%s\n", store->printStorePath(info.path)); logger->stdout("%s", store->printStorePath(info.path));
} }
}; };

View file

@ -55,16 +55,15 @@ struct CmdEval : MixJSON, InstallableCommand
auto v = installable->toValue(*state).first; auto v = installable->toValue(*state).first;
PathSet context; PathSet context;
stopProgressBar();
if (raw) { if (raw) {
stopProgressBar();
std::cout << state->coerceToString(noPos, *v, context); std::cout << state->coerceToString(noPos, *v, context);
} else if (json) { } else if (json) {
JSONPlaceholder jsonOut(std::cout); JSONPlaceholder jsonOut(std::cout);
printValueAsJSON(*state, true, *v, jsonOut, context); printValueAsJSON(*state, true, *v, jsonOut, context);
} else { } else {
state->forceValueDeep(*v); state->forceValueDeep(*v);
std::cout << *v << "\n"; logger->stdout("%s", *v);
} }
} }
}; };

View file

@ -1,7 +1,6 @@
#include "command.hh" #include "command.hh"
#include "common-args.hh" #include "common-args.hh"
#include "shared.hh" #include "shared.hh"
#include "progress-bar.hh"
#include "eval.hh" #include "eval.hh"
#include "eval-inline.hh" #include "eval-inline.hh"
#include "flake/flake.hh" #include "flake/flake.hh"
@ -61,12 +60,10 @@ struct CmdFlakeList : EvalCommand
auto registries = getRegistries(store); auto registries = getRegistries(store);
stopProgressBar();
for (auto & registry : registries) { for (auto & registry : registries) {
for (auto & entry : registry->entries) { for (auto & entry : registry->entries) {
// FIXME: format nicely // FIXME: format nicely
std::cout << fmt("%s %s %s\n", logger->stdout("%s %s %s",
registry->type == Registry::Flag ? "flags " : registry->type == Registry::Flag ? "flags " :
registry->type == Registry::User ? "user " : registry->type == Registry::User ? "user " :
registry->type == Registry::System ? "system" : registry->type == Registry::System ? "system" :
@ -80,17 +77,17 @@ struct CmdFlakeList : EvalCommand
static void printFlakeInfo(const Store & store, const Flake & flake) static void printFlakeInfo(const Store & store, const Flake & flake)
{ {
std::cout << fmt("Resolved URL: %s\n", flake.resolvedRef.to_string()); logger->stdout("Resolved URL: %s", flake.resolvedRef.to_string());
std::cout << fmt("Locked URL: %s\n", flake.lockedRef.to_string()); logger->stdout("Locked URL: %s", flake.lockedRef.to_string());
if (flake.description) if (flake.description)
std::cout << fmt("Description: %s\n", *flake.description); logger->stdout("Description: %s", *flake.description);
std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath)); logger->stdout("Path: %s", store.printStorePath(flake.sourceInfo->storePath));
if (auto rev = flake.lockedRef.input->getRev()) 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) 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) 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")); std::put_time(std::localtime(&*flake.sourceInfo->info.lastModified), "%F %T"));
} }
@ -156,11 +153,10 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON
void run(nix::ref<nix::Store> store) override void run(nix::ref<nix::Store> store) override
{ {
auto flake = getFlake(); auto flake = getFlake();
stopProgressBar();
if (json) { if (json) {
auto json = flakeToJson(*store, flake); auto json = flakeToJson(*store, flake);
std::cout << json.dump() << std::endl; logger->stdout(json.dump());
} else } else
printFlakeInfo(*store, flake); printFlakeInfo(*store, flake);
} }
@ -177,12 +173,10 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON
{ {
auto flake = lockFlake(); auto flake = lockFlake();
stopProgressBar();
if (json) if (json)
std::cout << flake.lockFile.toJson() << "\n"; logger->stdout(flake.lockFile.toJson());
else { else {
std::cout << fmt("%s\n", flake.flake.lockedRef); logger->stdout("%s", flake.flake.lockedRef);
std::function<void(const Node & node, const std::string & prefix)> recurse; std::function<void(const Node & node, const std::string & prefix)> recurse;
@ -191,7 +185,7 @@ struct CmdFlakeListInputs : FlakeCommand, MixJSON
for (const auto & [i, input] : enumerate(node.inputs)) { for (const auto & [i, input] : enumerate(node.inputs)) {
//auto tree2 = tree.child(i + 1 == inputs.inputs.size()); //auto tree2 = tree.child(i + 1 == inputs.inputs.size());
bool last = i + 1 == node.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, prefix + (last ? treeLast : treeConn), input.first,
std::dynamic_pointer_cast<const LockedNode>(input.second)->lockedRef); std::dynamic_pointer_cast<const LockedNode>(input.second)->lockedRef);
recurse(*input.second, prefix + (last ? treeNull : treeLine)); recurse(*input.second, prefix + (last ? treeNull : treeLine));

View file

@ -60,8 +60,7 @@ struct CmdHash : Command
Hash h = hashSink->finish().first; Hash h = hashSink->finish().first;
if (truncate && h.hashSize > 20) h = compressHash(h, 20); if (truncate && h.hashSize > 20) h = compressHash(h, 20);
std::cout << format("%1%\n") % logger->stdout(h.to_string(base, base == SRI));
h.to_string(base, base == SRI);
} }
} }
}; };
@ -95,7 +94,7 @@ struct CmdToBase : Command
void run() override void run() override
{ {
for (auto s : args) 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));
} }
}; };

View file

@ -34,16 +34,14 @@ struct MixLs : virtual Args, MixJSON
(st.isExecutable ? "-r-xr-xr-x" : "-r--r--r--") : (st.isExecutable ? "-r-xr-xr-x" : "-r--r--r--") :
st.type == FSAccessor::Type::tSymlink ? "lrwxrwxrwx" : st.type == FSAccessor::Type::tSymlink ? "lrwxrwxrwx" :
"dr-xr-xr-x"; "dr-xr-xr-x";
std::cout << auto line = fmt("%s %20d %s", tp, st.fileSize, relPath);
(format("%s %20d %s") % tp % st.fileSize % relPath);
if (st.type == FSAccessor::Type::tSymlink) if (st.type == FSAccessor::Type::tSymlink)
std::cout << " -> " << accessor->readLink(curPath) line += " -> " + accessor->readLink(curPath);
; logger->stdout(line);
std::cout << "\n";
if (recursive && st.type == FSAccessor::Type::tDirectory) if (recursive && st.type == FSAccessor::Type::tDirectory)
doPath(st, curPath, relPath, false); doPath(st, curPath, relPath, false);
} else { } else {
std::cout << relPath << "\n"; logger->stdout(relPath);
if (recursive) { if (recursive) {
auto st = accessor->stat(curPath); auto st = accessor->stat(curPath);
if (st.type == FSAccessor::Type::tDirectory) if (st.type == FSAccessor::Type::tDirectory)

View file

@ -385,7 +385,7 @@ struct CmdProfileInfo : virtual EvalCommand, virtual StoreCommand, MixDefaultPro
for (size_t i = 0; i < manifest.elements.size(); ++i) { for (size_t i = 0; i < manifest.elements.size(); ++i) {
auto & element(manifest.elements[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->originalRef.to_string() + "#" + element.source->attrPath : "-",
element.source ? element.source->resolvedRef.to_string() + "#" + element.source->attrPath : "-", element.source ? element.source->resolvedRef.to_string() + "#" + element.source->attrPath : "-",
concatStringsSep(" ", store->printStorePathSet(element.storePaths))); concatStringsSep(" ", store->printStorePathSet(element.storePaths)));

View file

@ -23,7 +23,7 @@ struct CmdShowConfig : Command, MixJSON
std::map<std::string, Config::SettingInfo> settings; std::map<std::string, Config::SettingInfo> settings;
globalConfig.getSettings(settings); globalConfig.getSettings(settings);
for (auto & s : settings) for (auto & s : settings)
std::cout << s.first + " = " + s.second.value + "\n"; logger->stdout(s.first + " = " + s.second.value);
} }
} }
}; };

View file

@ -149,7 +149,7 @@ struct CmdWhyDepends : SourceExprCommand
auto pathS = store->printStorePath(node.path); auto pathS = store->printStorePath(node.path);
assert(node.dist != inf); assert(node.dist != inf);
std::cout << fmt("%s%s%s%s" ANSI_NORMAL "\n", logger->stdout("%s%s%s%s" ANSI_NORMAL,
firstPad, firstPad,
node.visited ? "\e[38;5;244m" : "", node.visited ? "\e[38;5;244m" : "",
firstPad != "" ? "" : "", firstPad != "" ? "" : "",