forked from lix-project/lix
Merge remote-tracking branch 'origin/master' into flakes
This commit is contained in:
commit
6f3244ce45
|
@ -56,6 +56,3 @@
|
|||
#include <sys/wait.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.hh"
|
||||
#include "args.hh"
|
||||
|
|
|
@ -12,43 +12,47 @@ namespace nix {
|
|||
|
||||
MixEvalArgs::MixEvalArgs()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("arg")
|
||||
.description("argument to be passed to Nix functions")
|
||||
.labels({"name", "expr"})
|
||||
.handler([&](std::vector<std::string> ss) { autoArgs[ss[0]] = 'E' + ss[1]; });
|
||||
|
||||
mkFlag()
|
||||
.longName("argstr")
|
||||
.description("string-valued argument to be passed to Nix functions")
|
||||
.labels({"name", "string"})
|
||||
.handler([&](std::vector<std::string> ss) { autoArgs[ss[0]] = 'S' + ss[1]; });
|
||||
|
||||
mkFlag()
|
||||
.shortName('I')
|
||||
.longName("include")
|
||||
.description("add a path to the list of locations used to look up <...> file names")
|
||||
.label("path")
|
||||
.handler([&](std::string s) { searchPath.push_back(s); });
|
||||
|
||||
mkFlag()
|
||||
.longName("impure")
|
||||
.description("allow access to mutable paths and repositories")
|
||||
.handler([&](std::vector<std::string> ss) {
|
||||
evalSettings.pureEval = false;
|
||||
addFlag({
|
||||
.longName = "arg",
|
||||
.description = "argument to be passed to Nix functions",
|
||||
.labels = {"name", "expr"},
|
||||
.handler = {[&](std::string name, std::string expr) { autoArgs[name] = 'E' + expr; }}
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("override-flake")
|
||||
.labels({"original-ref", "resolved-ref"})
|
||||
.description("override a flake registry value")
|
||||
.arity(2)
|
||||
.handler([&](std::vector<std::string> ss) {
|
||||
auto from = parseFlakeRef(ss[0], absPath("."));
|
||||
auto to = parseFlakeRef(ss[1], absPath("."));
|
||||
addFlag({
|
||||
.longName = "argstr",
|
||||
.description = "string-valued argument to be passed to Nix functions",
|
||||
.labels = {"name", "string"},
|
||||
.handler = {[&](std::string name, std::string s) { autoArgs[name] = 'S' + s; }},
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "include",
|
||||
.shortName = 'I',
|
||||
.description = "add a path to the list of locations used to look up <...> file names",
|
||||
.labels = {"path"},
|
||||
.handler = {[&](std::string s) { searchPath.push_back(s); }}
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "impure",
|
||||
.description = "allow access to mutable paths and repositories",
|
||||
.handler = {[&]() {
|
||||
evalSettings.pureEval = false;
|
||||
}},
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "override-flake",
|
||||
.description = "override a flake registry value",
|
||||
.labels = {"original-ref", "resolved-ref"},
|
||||
.handler = {[&](std::string _from, std::string _to) {
|
||||
auto from = parseFlakeRef(_from, absPath("."));
|
||||
auto to = parseFlakeRef(_to, absPath("."));
|
||||
fetchers::Attrs extraAttrs;
|
||||
if (to.subdir != "") extraAttrs["dir"] = to.subdir;
|
||||
fetchers::overrideRegistry(from.input, to.input, extraAttrs);
|
||||
}}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,42 +6,46 @@ namespace nix {
|
|||
MixCommonArgs::MixCommonArgs(const string & programName)
|
||||
: programName(programName)
|
||||
{
|
||||
mkFlag()
|
||||
.longName("verbose")
|
||||
.shortName('v')
|
||||
.description("increase verbosity level")
|
||||
.handler([]() { verbosity = (Verbosity) (verbosity + 1); });
|
||||
addFlag({
|
||||
.longName = "verbose",
|
||||
.shortName = 'v',
|
||||
.description = "increase verbosity level",
|
||||
.handler = {[]() { verbosity = (Verbosity) (verbosity + 1); }},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("quiet")
|
||||
.description("decrease verbosity level")
|
||||
.handler([]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; });
|
||||
addFlag({
|
||||
.longName = "quiet",
|
||||
.description = "decrease verbosity level",
|
||||
.handler = {[]() { verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError; }},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("debug")
|
||||
.description("enable debug output")
|
||||
.handler([]() { verbosity = lvlDebug; });
|
||||
addFlag({
|
||||
.longName = "debug",
|
||||
.description = "enable debug output",
|
||||
.handler = {[]() { verbosity = lvlDebug; }},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("option")
|
||||
.labels({"name", "value"})
|
||||
.description("set a Nix configuration option (overriding nix.conf)")
|
||||
.arity(2)
|
||||
.handler([](std::vector<std::string> ss) {
|
||||
addFlag({
|
||||
.longName = "option",
|
||||
.description = "set a Nix configuration option (overriding nix.conf)",
|
||||
.labels = {"name", "value"},
|
||||
.handler = {[](std::string name, std::string value) {
|
||||
try {
|
||||
globalConfig.set(ss[0], ss[1]);
|
||||
globalConfig.set(name, value);
|
||||
} catch (UsageError & e) {
|
||||
warn(e.what());
|
||||
}
|
||||
}},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("max-jobs")
|
||||
.shortName('j')
|
||||
.label("jobs")
|
||||
.description("maximum number of parallel builds")
|
||||
.handler([=](std::string s) {
|
||||
addFlag({
|
||||
.longName = "max-jobs",
|
||||
.shortName = 'j',
|
||||
.description = "maximum number of parallel builds",
|
||||
.labels = Strings{"jobs"},
|
||||
.handler = {[=](std::string s) {
|
||||
settings.set("max-jobs", s);
|
||||
}}
|
||||
});
|
||||
|
||||
std::string cat = "config";
|
||||
|
|
|
@ -165,28 +165,32 @@ LegacyArgs::LegacyArgs(const std::string & programName,
|
|||
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg)
|
||||
: MixCommonArgs(programName), parseArg(parseArg)
|
||||
{
|
||||
mkFlag()
|
||||
.longName("no-build-output")
|
||||
.shortName('Q')
|
||||
.description("do not show build output")
|
||||
.set(&settings.verboseBuild, false);
|
||||
addFlag({
|
||||
.longName = "no-build-output",
|
||||
.shortName = 'Q',
|
||||
.description = "do not show build output",
|
||||
.handler = {&settings.verboseBuild, false},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("keep-failed")
|
||||
.shortName('K')
|
||||
.description("keep temporary directories of failed builds")
|
||||
.set(&(bool&) settings.keepFailed, true);
|
||||
addFlag({
|
||||
.longName = "keep-failed",
|
||||
.shortName ='K',
|
||||
.description = "keep temporary directories of failed builds",
|
||||
.handler = {&(bool&) settings.keepFailed, true},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("keep-going")
|
||||
.shortName('k')
|
||||
.description("keep going after a build fails")
|
||||
.set(&(bool&) settings.keepGoing, true);
|
||||
addFlag({
|
||||
.longName = "keep-going",
|
||||
.shortName ='k',
|
||||
.description = "keep going after a build fails",
|
||||
.handler = {&(bool&) settings.keepGoing, true},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("fallback")
|
||||
.description("build from source if substitution fails")
|
||||
.set(&(bool&) settings.tryFallback, true);
|
||||
addFlag({
|
||||
.longName = "fallback",
|
||||
.description = "build from source if substitution fails",
|
||||
.handler = {&(bool&) settings.tryFallback, true},
|
||||
});
|
||||
|
||||
auto intSettingAlias = [&](char shortName, const std::string & longName,
|
||||
const std::string & description, const std::string & dest) {
|
||||
|
@ -205,11 +209,12 @@ LegacyArgs::LegacyArgs(const std::string & programName,
|
|||
mkFlag(0, "no-gc-warning", "disable warning about not using '--add-root'",
|
||||
&gcWarning, false);
|
||||
|
||||
mkFlag()
|
||||
.longName("store")
|
||||
.label("store-uri")
|
||||
.description("URI of the Nix store to use")
|
||||
.dest(&(std::string&) settings.storeUri);
|
||||
addFlag({
|
||||
.longName = "store",
|
||||
.description = "URI of the Nix store to use",
|
||||
.labels = {"store-uri"},
|
||||
.handler = {&(std::string&) settings.storeUri},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -167,21 +167,24 @@ template<> void BaseSetting<SandboxMode>::toJSON(JSONPlaceholder & out)
|
|||
|
||||
template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::string & category)
|
||||
{
|
||||
args.mkFlag()
|
||||
.longName(name)
|
||||
.description("Enable sandboxing.")
|
||||
.handler([=](std::vector<std::string> ss) { override(smEnabled); })
|
||||
.category(category);
|
||||
args.mkFlag()
|
||||
.longName("no-" + name)
|
||||
.description("Disable sandboxing.")
|
||||
.handler([=](std::vector<std::string> ss) { override(smDisabled); })
|
||||
.category(category);
|
||||
args.mkFlag()
|
||||
.longName("relaxed-" + name)
|
||||
.description("Enable sandboxing, but allow builds to disable it.")
|
||||
.handler([=](std::vector<std::string> ss) { override(smRelaxed); })
|
||||
.category(category);
|
||||
args.addFlag({
|
||||
.longName = name,
|
||||
.description = "Enable sandboxing.",
|
||||
.category = category,
|
||||
.handler = {[=]() { override(smEnabled); }}
|
||||
});
|
||||
args.addFlag({
|
||||
.longName = "no-" + name,
|
||||
.description = "Disable sandboxing.",
|
||||
.category = category,
|
||||
.handler = {[=]() { override(smDisabled); }}
|
||||
});
|
||||
args.addFlag({
|
||||
.longName = "relaxed-" + name,
|
||||
.description = "Enable sandboxing, but allow builds to disable it.",
|
||||
.category = category,
|
||||
.handler = {[=]() { override(smRelaxed); }}
|
||||
});
|
||||
}
|
||||
|
||||
void MaxBuildJobsSetting::set(const std::string & str)
|
||||
|
|
|
@ -779,8 +779,10 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source *
|
|||
return std::make_exception_ptr(Error(status, error));
|
||||
}
|
||||
|
||||
else if (msg == STDERR_NEXT)
|
||||
printError(chomp(readString(from)));
|
||||
else if (msg == STDERR_NEXT) {
|
||||
string s = chomp(readString(from));
|
||||
printMsg(lvlVomit, "stderr %s", s);
|
||||
}
|
||||
|
||||
else if (msg == STDERR_START_ACTIVITY) {
|
||||
auto act = readNum<ActivityId>(from);
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
namespace nix
|
||||
{
|
||||
/* Some ANSI escape sequences. */
|
||||
#define ANSI_NORMAL "\e[0m"
|
||||
#define ANSI_BOLD "\e[1m"
|
||||
#define ANSI_FAINT "\e[2m"
|
||||
#define ANSI_RED "\e[31;1m"
|
||||
#define ANSI_GREEN "\e[32;1m"
|
||||
#define ANSI_YELLOW "\e[33;1m"
|
||||
#define ANSI_BLUE "\e[34;1m"
|
||||
namespace nix {
|
||||
|
||||
/* Some ANSI escape sequences. */
|
||||
#define ANSI_NORMAL "\e[0m"
|
||||
#define ANSI_BOLD "\e[1m"
|
||||
#define ANSI_FAINT "\e[2m"
|
||||
#define ANSI_ITALIC "\e[3m"
|
||||
#define ANSI_RED "\e[31;1m"
|
||||
#define ANSI_GREEN "\e[32;1m"
|
||||
#define ANSI_YELLOW "\e[33;1m"
|
||||
#define ANSI_BLUE "\e[34;1m"
|
||||
|
||||
}
|
||||
|
|
|
@ -3,16 +3,14 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
Args::FlagMaker Args::mkFlag()
|
||||
{
|
||||
return FlagMaker(*this);
|
||||
}
|
||||
|
||||
Args::FlagMaker::~FlagMaker()
|
||||
void Args::addFlag(Flag && flag_)
|
||||
{
|
||||
auto flag = std::make_shared<Flag>(std::move(flag_));
|
||||
if (flag->handler.arity != ArityAny)
|
||||
assert(flag->handler.arity == flag->labels.size());
|
||||
assert(flag->longName != "");
|
||||
args.longFlags[flag->longName] = flag;
|
||||
if (flag->shortName) args.shortFlags[flag->shortName] = flag;
|
||||
longFlags[flag->longName] = flag;
|
||||
if (flag->shortName) shortFlags[flag->shortName] = flag;
|
||||
}
|
||||
|
||||
void Args::parseCmdline(const Strings & _cmdline)
|
||||
|
@ -61,7 +59,7 @@ void Args::parseCmdline(const Strings & _cmdline)
|
|||
|
||||
void Args::printHelp(const string & programName, std::ostream & out)
|
||||
{
|
||||
std::cout << "Usage: " << programName << " <FLAGS>...";
|
||||
std::cout << fmt(ANSI_BOLD "Usage:" ANSI_NORMAL " %s " ANSI_ITALIC "FLAGS..." ANSI_NORMAL, programName);
|
||||
for (auto & exp : expectedArgs) {
|
||||
std::cout << renderLabels({exp.label});
|
||||
// FIXME: handle arity > 1
|
||||
|
@ -72,11 +70,11 @@ void Args::printHelp(const string & programName, std::ostream & out)
|
|||
|
||||
auto s = description();
|
||||
if (s != "")
|
||||
std::cout << "\nSummary: " << s << ".\n";
|
||||
std::cout << "\n" ANSI_BOLD "Summary:" ANSI_NORMAL " " << s << ".\n";
|
||||
|
||||
if (longFlags.size()) {
|
||||
std::cout << "\n";
|
||||
std::cout << "Flags:\n";
|
||||
std::cout << ANSI_BOLD "Flags:" ANSI_NORMAL "\n";
|
||||
printFlags(out);
|
||||
}
|
||||
}
|
||||
|
@ -101,15 +99,14 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
|
|||
auto process = [&](const std::string & name, const Flag & flag) -> bool {
|
||||
++pos;
|
||||
std::vector<std::string> args;
|
||||
for (size_t n = 0 ; n < flag.arity; ++n) {
|
||||
for (size_t n = 0 ; n < flag.handler.arity; ++n) {
|
||||
if (pos == end) {
|
||||
if (flag.arity == ArityAny) break;
|
||||
throw UsageError(format("flag '%1%' requires %2% argument(s)")
|
||||
% name % flag.arity);
|
||||
if (flag.handler.arity == ArityAny) break;
|
||||
throw UsageError("flag '%s' requires %d argument(s)", name, flag.handler.arity);
|
||||
}
|
||||
args.push_back(*pos++);
|
||||
}
|
||||
flag.handler(std::move(args));
|
||||
flag.handler.fun(std::move(args));
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -157,17 +154,18 @@ bool Args::processArgs(const Strings & args, bool finish)
|
|||
return res;
|
||||
}
|
||||
|
||||
Args::FlagMaker & Args::FlagMaker::mkHashTypeFlag(HashType * ht)
|
||||
Args::Flag Args::Flag::mkHashTypeFlag(std::string && longName, HashType * ht)
|
||||
{
|
||||
arity(1);
|
||||
label("type");
|
||||
description("hash algorithm ('md5', 'sha1', 'sha256', or 'sha512')");
|
||||
handler([ht](std::string s) {
|
||||
return Flag {
|
||||
.longName = std::move(longName),
|
||||
.description = "hash algorithm ('md5', 'sha1', 'sha256', or 'sha512')",
|
||||
.labels = {"hash-algo"},
|
||||
.handler = {[ht](std::string s) {
|
||||
*ht = parseHashType(s);
|
||||
if (*ht == htUnknown)
|
||||
throw UsageError("unknown hash type '%1%'", s);
|
||||
});
|
||||
return *this;
|
||||
}}
|
||||
};
|
||||
}
|
||||
|
||||
Strings argvToStrings(int argc, char * * argv)
|
||||
|
@ -183,7 +181,7 @@ std::string renderLabels(const Strings & labels)
|
|||
std::string res;
|
||||
for (auto label : labels) {
|
||||
for (auto & c : label) c = std::toupper(c);
|
||||
res += " <" + label + ">";
|
||||
res += " " ANSI_ITALIC + label + ANSI_NORMAL;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -192,10 +190,10 @@ void printTable(std::ostream & out, const Table2 & table)
|
|||
{
|
||||
size_t max = 0;
|
||||
for (auto & row : table)
|
||||
max = std::max(max, row.first.size());
|
||||
max = std::max(max, filterANSIEscapes(row.first, true).size());
|
||||
for (auto & row : table) {
|
||||
out << " " << row.first
|
||||
<< std::string(max - row.first.size() + 2, ' ')
|
||||
<< std::string(max - filterANSIEscapes(row.first, true).size() + 2, ' ')
|
||||
<< row.second << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -206,8 +204,7 @@ void Command::printHelp(const string & programName, std::ostream & out)
|
|||
|
||||
auto exs = examples();
|
||||
if (!exs.empty()) {
|
||||
out << "\n";
|
||||
out << "Examples:\n";
|
||||
out << "\n" ANSI_BOLD "Examples:" ANSI_NORMAL "\n";
|
||||
for (auto & ex : exs)
|
||||
out << "\n"
|
||||
<< " " << ex.description << "\n" // FIXME: wrap
|
||||
|
@ -223,49 +220,55 @@ MultiCommand::MultiCommand(const Commands & commands)
|
|||
auto i = commands.find(ss[0]);
|
||||
if (i == commands.end())
|
||||
throw UsageError("'%s' is not a recognised command", ss[0]);
|
||||
command = i->second();
|
||||
command->_name = ss[0];
|
||||
command = {ss[0], i->second()};
|
||||
}});
|
||||
|
||||
categories[Command::catDefault] = "Available commands";
|
||||
}
|
||||
|
||||
void MultiCommand::printHelp(const string & programName, std::ostream & out)
|
||||
{
|
||||
if (command) {
|
||||
command->printHelp(programName + " " + command->name(), out);
|
||||
command->second->printHelp(programName + " " + command->first, out);
|
||||
return;
|
||||
}
|
||||
|
||||
out << "Usage: " << programName << " <COMMAND> <FLAGS>... <ARGS>...\n";
|
||||
out << fmt(ANSI_BOLD "Usage:" ANSI_NORMAL " %s " ANSI_ITALIC "COMMAND FLAGS... ARGS..." ANSI_NORMAL "\n", programName);
|
||||
|
||||
out << "\n";
|
||||
out << "Common flags:\n";
|
||||
out << "\n" ANSI_BOLD "Common flags:" ANSI_NORMAL "\n";
|
||||
printFlags(out);
|
||||
|
||||
out << "\n";
|
||||
out << "Available commands:\n";
|
||||
std::map<Command::Category, std::map<std::string, ref<Command>>> commandsByCategory;
|
||||
|
||||
for (auto & [name, commandFun] : commands) {
|
||||
auto command = commandFun();
|
||||
commandsByCategory[command->category()].insert_or_assign(name, command);
|
||||
}
|
||||
|
||||
for (auto & [category, commands] : commandsByCategory) {
|
||||
out << fmt("\n" ANSI_BOLD "%s:" ANSI_NORMAL "\n", categories[category]);
|
||||
|
||||
Table2 table;
|
||||
for (auto & i : commands) {
|
||||
auto command = i.second();
|
||||
command->_name = i.first;
|
||||
for (auto & [name, command] : commands) {
|
||||
auto descr = command->description();
|
||||
if (!descr.empty())
|
||||
table.push_back(std::make_pair(command->name(), descr));
|
||||
table.push_back(std::make_pair(name, descr));
|
||||
}
|
||||
printTable(out, table);
|
||||
}
|
||||
}
|
||||
|
||||
bool MultiCommand::processFlag(Strings::iterator & pos, Strings::iterator end)
|
||||
{
|
||||
if (Args::processFlag(pos, end)) return true;
|
||||
if (command && command->processFlag(pos, end)) return true;
|
||||
if (command && command->second->processFlag(pos, end)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MultiCommand::processArgs(const Strings & args, bool finish)
|
||||
{
|
||||
if (command)
|
||||
return command->processArgs(args, finish);
|
||||
return command->second->processArgs(args, finish);
|
||||
else
|
||||
return Args::processArgs(args, finish);
|
||||
}
|
||||
|
|
|
@ -32,13 +32,59 @@ protected:
|
|||
struct Flag
|
||||
{
|
||||
typedef std::shared_ptr<Flag> ptr;
|
||||
|
||||
struct Handler
|
||||
{
|
||||
std::function<void(std::vector<std::string>)> fun;
|
||||
size_t arity;
|
||||
|
||||
Handler() {}
|
||||
|
||||
Handler(std::function<void(std::vector<std::string>)> && fun)
|
||||
: fun(std::move(fun))
|
||||
, arity(ArityAny)
|
||||
{ }
|
||||
|
||||
Handler(std::function<void()> && handler)
|
||||
: fun([handler{std::move(handler)}](std::vector<std::string>) { handler(); })
|
||||
, arity(0)
|
||||
{ }
|
||||
|
||||
Handler(std::function<void(std::string)> && handler)
|
||||
: fun([handler{std::move(handler)}](std::vector<std::string> ss) {
|
||||
handler(std::move(ss[0]));
|
||||
})
|
||||
, arity(1)
|
||||
{ }
|
||||
|
||||
Handler(std::function<void(std::string, std::string)> && handler)
|
||||
: fun([handler{std::move(handler)}](std::vector<std::string> ss) {
|
||||
handler(std::move(ss[0]), std::move(ss[1]));
|
||||
})
|
||||
, arity(2)
|
||||
{ }
|
||||
|
||||
template<class T>
|
||||
Handler(T * dest)
|
||||
: fun([=](std::vector<std::string> ss) { *dest = ss[0]; })
|
||||
, arity(1)
|
||||
{ }
|
||||
|
||||
template<class T>
|
||||
Handler(T * dest, const T & val)
|
||||
: fun([=](std::vector<std::string> ss) { *dest = val; })
|
||||
, arity(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
std::string longName;
|
||||
char shortName = 0;
|
||||
std::string description;
|
||||
Strings labels;
|
||||
size_t arity = 0;
|
||||
std::function<void(std::vector<std::string>)> handler;
|
||||
std::string category;
|
||||
Strings labels;
|
||||
Handler handler;
|
||||
|
||||
static Flag mkHashTypeFlag(std::string && longName, HashType * ht);
|
||||
};
|
||||
|
||||
std::map<std::string, Flag::ptr> longFlags;
|
||||
|
@ -65,49 +111,7 @@ protected:
|
|||
|
||||
public:
|
||||
|
||||
class FlagMaker
|
||||
{
|
||||
Args & args;
|
||||
Flag::ptr flag;
|
||||
friend class Args;
|
||||
FlagMaker(Args & args) : args(args), flag(std::make_shared<Flag>()) { }
|
||||
public:
|
||||
~FlagMaker();
|
||||
FlagMaker & longName(const std::string & s) { flag->longName = s; return *this; }
|
||||
FlagMaker & shortName(char s) { flag->shortName = s; return *this; }
|
||||
FlagMaker & description(const std::string & s) { flag->description = s; return *this; }
|
||||
FlagMaker & label(const std::string & l) { flag->arity = 1; flag->labels = {l}; return *this; }
|
||||
FlagMaker & labels(const Strings & ls) { flag->arity = ls.size(); flag->labels = ls; return *this; }
|
||||
FlagMaker & arity(size_t arity) { flag->arity = arity; return *this; }
|
||||
FlagMaker & handler(std::function<void(std::vector<std::string>)> handler) { flag->handler = handler; return *this; }
|
||||
FlagMaker & handler(std::function<void()> handler) { flag->handler = [handler](std::vector<std::string>) { handler(); }; return *this; }
|
||||
FlagMaker & handler(std::function<void(std::string)> handler) {
|
||||
flag->arity = 1;
|
||||
flag->handler = [handler](std::vector<std::string> ss) { handler(std::move(ss[0])); };
|
||||
return *this;
|
||||
}
|
||||
FlagMaker & category(const std::string & s) { flag->category = s; return *this; }
|
||||
|
||||
template<class T>
|
||||
FlagMaker & dest(T * dest)
|
||||
{
|
||||
flag->arity = 1;
|
||||
flag->handler = [=](std::vector<std::string> ss) { *dest = ss[0]; };
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
FlagMaker & set(T * dest, const T & val)
|
||||
{
|
||||
flag->arity = 0;
|
||||
flag->handler = [=](std::vector<std::string> ss) { *dest = val; };
|
||||
return *this;
|
||||
}
|
||||
|
||||
FlagMaker & mkHashTypeFlag(HashType * ht);
|
||||
};
|
||||
|
||||
FlagMaker mkFlag();
|
||||
void addFlag(Flag && flag);
|
||||
|
||||
/* Helper functions for constructing flags / positional
|
||||
arguments. */
|
||||
|
@ -116,13 +120,13 @@ public:
|
|||
const std::string & label, const std::string & description,
|
||||
std::function<void(std::string)> fun)
|
||||
{
|
||||
mkFlag()
|
||||
.shortName(shortName)
|
||||
.longName(longName)
|
||||
.labels({label})
|
||||
.description(description)
|
||||
.arity(1)
|
||||
.handler([=](std::vector<std::string> ss) { fun(ss[0]); });
|
||||
addFlag({
|
||||
.longName = longName,
|
||||
.shortName = shortName,
|
||||
.description = description,
|
||||
.labels = {label},
|
||||
.handler = {[=](std::string s) { fun(s); }}
|
||||
});
|
||||
}
|
||||
|
||||
void mkFlag(char shortName, const std::string & name,
|
||||
|
@ -135,11 +139,12 @@ public:
|
|||
void mkFlag(char shortName, const std::string & longName, const std::string & description,
|
||||
T * dest, const T & value)
|
||||
{
|
||||
mkFlag()
|
||||
.shortName(shortName)
|
||||
.longName(longName)
|
||||
.description(description)
|
||||
.handler([=](std::vector<std::string> ss) { *dest = value; });
|
||||
addFlag({
|
||||
.longName = longName,
|
||||
.shortName = shortName,
|
||||
.description = description,
|
||||
.handler = {[=]() { *dest = value; }}
|
||||
});
|
||||
}
|
||||
|
||||
template<class I>
|
||||
|
@ -155,17 +160,17 @@ public:
|
|||
void mkFlag(char shortName, const std::string & longName,
|
||||
const std::string & description, std::function<void(I)> fun)
|
||||
{
|
||||
mkFlag()
|
||||
.shortName(shortName)
|
||||
.longName(longName)
|
||||
.labels({"N"})
|
||||
.description(description)
|
||||
.arity(1)
|
||||
.handler([=](std::vector<std::string> ss) {
|
||||
addFlag({
|
||||
.longName = longName,
|
||||
.shortName = shortName,
|
||||
.description = description,
|
||||
.labels = {"N"},
|
||||
.handler = {[=](std::string s) {
|
||||
I n;
|
||||
if (!string2Int(ss[0], n))
|
||||
if (!string2Int(s, n))
|
||||
throw UsageError("flag '--%s' requires a integer argument", longName);
|
||||
fun(n);
|
||||
}}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -192,17 +197,10 @@ public:
|
|||
run() method. */
|
||||
struct Command : virtual Args
|
||||
{
|
||||
private:
|
||||
std::string _name;
|
||||
|
||||
friend class MultiCommand;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Command() { }
|
||||
|
||||
std::string name() { return _name; }
|
||||
|
||||
virtual void prepare() { };
|
||||
virtual void run() = 0;
|
||||
|
||||
|
@ -216,6 +214,12 @@ public:
|
|||
|
||||
virtual Examples examples() { return Examples(); }
|
||||
|
||||
typedef int Category;
|
||||
|
||||
static constexpr Category catDefault = 0;
|
||||
|
||||
virtual Category category() { return catDefault; }
|
||||
|
||||
void printHelp(const string & programName, std::ostream & out) override;
|
||||
};
|
||||
|
||||
|
@ -228,7 +232,10 @@ class MultiCommand : virtual Args
|
|||
public:
|
||||
Commands commands;
|
||||
|
||||
std::shared_ptr<Command> command;
|
||||
std::map<Command::Category, std::string> categories;
|
||||
|
||||
// Selected command, if any.
|
||||
std::optional<std::pair<std::string, ref<Command>>> command;
|
||||
|
||||
MultiCommand(const Commands & commands);
|
||||
|
||||
|
|
|
@ -177,12 +177,13 @@ void BaseSetting<T>::toJSON(JSONPlaceholder & out)
|
|||
template<typename T>
|
||||
void BaseSetting<T>::convertToArg(Args & args, const std::string & category)
|
||||
{
|
||||
args.mkFlag()
|
||||
.longName(name)
|
||||
.description(description)
|
||||
.arity(1)
|
||||
.handler([=](std::vector<std::string> ss) { overriden = true; set(ss[0]); })
|
||||
.category(category);
|
||||
args.addFlag({
|
||||
.longName = name,
|
||||
.description = description,
|
||||
.category = category,
|
||||
.labels = {"value"},
|
||||
.handler = {[=](std::string s) { overriden = true; set(s); }},
|
||||
});
|
||||
}
|
||||
|
||||
template<> void BaseSetting<std::string>::set(const std::string & str)
|
||||
|
@ -227,16 +228,18 @@ template<> std::string BaseSetting<bool>::to_string() const
|
|||
|
||||
template<> void BaseSetting<bool>::convertToArg(Args & args, const std::string & category)
|
||||
{
|
||||
args.mkFlag()
|
||||
.longName(name)
|
||||
.description(description)
|
||||
.handler([=](std::vector<std::string> ss) { override(true); })
|
||||
.category(category);
|
||||
args.mkFlag()
|
||||
.longName("no-" + name)
|
||||
.description(description)
|
||||
.handler([=](std::vector<std::string> ss) { override(false); })
|
||||
.category(category);
|
||||
args.addFlag({
|
||||
.longName = name,
|
||||
.description = description,
|
||||
.category = category,
|
||||
.handler = {[=]() { override(true); }}
|
||||
});
|
||||
args.addFlag({
|
||||
.longName = "no-" + name,
|
||||
.description = description,
|
||||
.category = category,
|
||||
.handler = {[=]() { override(false); }}
|
||||
});
|
||||
}
|
||||
|
||||
template<> void BaseSetting<Strings>::set(const std::string & str)
|
||||
|
|
|
@ -63,6 +63,16 @@ public:
|
|||
writeToStderr(prefix + filterANSIEscapes(fs.s, !tty) + "\n");
|
||||
}
|
||||
|
||||
void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override
|
||||
{
|
||||
if (type == resBuildLogLine || type == resPostBuildLogLine) {
|
||||
assert(0 < fields.size());
|
||||
assert(fields[0].type == Logger::Field::tString);
|
||||
auto lastLine = fields[0].s;
|
||||
log(lvlInfo, lastLine);
|
||||
}
|
||||
}
|
||||
|
||||
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
||||
const std::string & s, const Fields & fields, ActivityId parent)
|
||||
override
|
||||
|
|
|
@ -14,12 +14,13 @@ struct CmdAddToStore : MixDryRun, StoreCommand
|
|||
{
|
||||
expectArg("path", &path);
|
||||
|
||||
mkFlag()
|
||||
.longName("name")
|
||||
.shortName('n')
|
||||
.description("name component of the store path")
|
||||
.labels({"name"})
|
||||
.dest(&namePart);
|
||||
addFlag({
|
||||
.longName = "name",
|
||||
.shortName = 'n',
|
||||
.description = "name component of the store path",
|
||||
.labels = {"name"},
|
||||
.handler = {&namePart},
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -33,6 +34,8 @@ struct CmdAddToStore : MixDryRun, StoreCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
if (!namePart) namePart = baseNameOf(path);
|
||||
|
|
|
@ -12,17 +12,19 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
|
|||
|
||||
CmdBuild()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("out-link")
|
||||
.shortName('o')
|
||||
.description("path of the symlink to the build result")
|
||||
.labels({"path"})
|
||||
.dest(&outLink);
|
||||
addFlag({
|
||||
.longName = "out-link",
|
||||
.shortName = 'o',
|
||||
.description = "path of the symlink to the build result",
|
||||
.labels = {"path"},
|
||||
.handler = {&outLink},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("no-link")
|
||||
.description("do not create a symlink to the build result")
|
||||
.set(&outLink, Path(""));
|
||||
addFlag({
|
||||
.longName = "no-link",
|
||||
.description = "do not create a symlink to the build result",
|
||||
.handler = {&outLink, Path("")},
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
|
|
@ -30,9 +30,11 @@ struct CmdCatStore : StoreCommand, MixCat
|
|||
|
||||
std::string description() override
|
||||
{
|
||||
return "print the contents of a store file on stdout";
|
||||
return "print the contents of a file in the Nix store on stdout";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
cat(store->getFSAccessor());
|
||||
|
@ -51,9 +53,11 @@ struct CmdCatNar : StoreCommand, MixCat
|
|||
|
||||
std::string description() override
|
||||
{
|
||||
return "print the contents of a file inside a NAR file";
|
||||
return "print the contents of a file inside a NAR file on stdout";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
cat(makeNarAccessor(make_ref<std::string>(readFile(narPath))));
|
||||
|
|
|
@ -35,16 +35,18 @@ StorePathsCommand::StorePathsCommand(bool recursive)
|
|||
: recursive(recursive)
|
||||
{
|
||||
if (recursive)
|
||||
mkFlag()
|
||||
.longName("no-recursive")
|
||||
.description("apply operation to specified paths only")
|
||||
.set(&this->recursive, false);
|
||||
addFlag({
|
||||
.longName = "no-recursive",
|
||||
.description = "apply operation to specified paths only",
|
||||
.handler = {&this->recursive, false},
|
||||
});
|
||||
else
|
||||
mkFlag()
|
||||
.longName("recursive")
|
||||
.shortName('r')
|
||||
.description("apply operation to closure of the specified paths")
|
||||
.set(&this->recursive, true);
|
||||
addFlag({
|
||||
.longName = "recursive",
|
||||
.shortName = 'r',
|
||||
.description = "apply operation to closure of the specified paths",
|
||||
.handler = {&this->recursive, true},
|
||||
});
|
||||
|
||||
mkFlag(0, "all", "apply operation to the entire store", &all);
|
||||
}
|
||||
|
@ -101,11 +103,12 @@ Strings editorFor(const Pos & pos)
|
|||
|
||||
MixProfile::MixProfile()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("profile")
|
||||
.description("profile to update")
|
||||
.labels({"path"})
|
||||
.dest(&profile);
|
||||
addFlag({
|
||||
.longName = "profile",
|
||||
.description = "profile to update",
|
||||
.labels = {"path"},
|
||||
.handler = {&profile},
|
||||
});
|
||||
}
|
||||
|
||||
void MixProfile::updateProfile(const StorePath & storePath)
|
||||
|
@ -145,28 +148,30 @@ MixDefaultProfile::MixDefaultProfile()
|
|||
profile = getDefaultProfile();
|
||||
}
|
||||
|
||||
MixEnvironment::MixEnvironment() : ignoreEnvironment(false) {
|
||||
mkFlag()
|
||||
.longName("ignore-environment")
|
||||
.shortName('i')
|
||||
.description("clear the entire environment (except those specified with --keep)")
|
||||
.set(&ignoreEnvironment, true);
|
||||
MixEnvironment::MixEnvironment() : ignoreEnvironment(false)
|
||||
{
|
||||
addFlag({
|
||||
.longName = "ignore-environment",
|
||||
.shortName = 'i',
|
||||
.description = "clear the entire environment (except those specified with --keep)",
|
||||
.handler = {&ignoreEnvironment, true},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("keep")
|
||||
.shortName('k')
|
||||
.description("keep specified environment variable")
|
||||
.arity(1)
|
||||
.labels({"name"})
|
||||
.handler([&](std::vector<std::string> ss) { keep.insert(ss.front()); });
|
||||
addFlag({
|
||||
.longName = "keep",
|
||||
.shortName = 'k',
|
||||
.description = "keep specified environment variable",
|
||||
.labels = {"name"},
|
||||
.handler = {[&](std::string s) { keep.insert(s); }},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("unset")
|
||||
.shortName('u')
|
||||
.description("unset specified environment variable")
|
||||
.arity(1)
|
||||
.labels({"name"})
|
||||
.handler([&](std::vector<std::string> ss) { unset.insert(ss.front()); });
|
||||
addFlag({
|
||||
.longName = "unset",
|
||||
.shortName = 'u',
|
||||
.description = "unset specified environment variable",
|
||||
.labels = {"name"},
|
||||
.handler = {[&](std::string s) { unset.insert(s); }},
|
||||
});
|
||||
}
|
||||
|
||||
void MixEnvironment::setEnviron() {
|
||||
|
|
|
@ -16,6 +16,10 @@ class EvalState;
|
|||
struct Pos;
|
||||
class Store;
|
||||
|
||||
static constexpr Command::Category catSecondary = 100;
|
||||
static constexpr Command::Category catUtility = 101;
|
||||
static constexpr Command::Category catNixInstallation = 102;
|
||||
|
||||
/* A command that requires a Nix store. */
|
||||
struct StoreCommand : virtual Command
|
||||
{
|
||||
|
|
|
@ -19,27 +19,32 @@ struct CmdCopy : StorePathsCommand
|
|||
CmdCopy()
|
||||
: StorePathsCommand(true)
|
||||
{
|
||||
mkFlag()
|
||||
.longName("from")
|
||||
.labels({"store-uri"})
|
||||
.description("URI of the source Nix store")
|
||||
.dest(&srcUri);
|
||||
mkFlag()
|
||||
.longName("to")
|
||||
.labels({"store-uri"})
|
||||
.description("URI of the destination Nix store")
|
||||
.dest(&dstUri);
|
||||
addFlag({
|
||||
.longName = "from",
|
||||
.description = "URI of the source Nix store",
|
||||
.labels = {"store-uri"},
|
||||
.handler = {&srcUri},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("no-check-sigs")
|
||||
.description("do not require that paths are signed by trusted keys")
|
||||
.set(&checkSigs, NoCheckSigs);
|
||||
addFlag({
|
||||
.longName = "to",
|
||||
.description = "URI of the destination Nix store",
|
||||
.labels = {"store-uri"},
|
||||
.handler = {&dstUri},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("substitute-on-destination")
|
||||
.shortName('s')
|
||||
.description("whether to try substitutes on the destination store (only supported by SSH)")
|
||||
.set(&substitute, Substitute);
|
||||
addFlag({
|
||||
.longName = "no-check-sigs",
|
||||
.description = "do not require that paths are signed by trusted keys",
|
||||
.handler = {&checkSigs, NoCheckSigs},
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "substitute-on-destination",
|
||||
.shortName = 's',
|
||||
.description = "whether to try substitutes on the destination store (only supported by SSH)",
|
||||
.handler = {&substitute, Substitute},
|
||||
});
|
||||
|
||||
realiseMode = Build;
|
||||
}
|
||||
|
@ -77,6 +82,8 @@ struct CmdCopy : StorePathsCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catSecondary; }
|
||||
|
||||
ref<Store> createStore() override
|
||||
{
|
||||
return srcUri.empty() ? StoreCommand::createStore() : openStore(srcUri);
|
||||
|
|
|
@ -242,15 +242,15 @@ struct CmdDevShell : Common, MixEnvironment
|
|||
|
||||
CmdDevShell()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("command")
|
||||
.shortName('c')
|
||||
.description("command and arguments to be executed insted of an interactive shell")
|
||||
.labels({"command", "args"})
|
||||
.arity(ArityAny)
|
||||
.handler([&](std::vector<std::string> ss) {
|
||||
addFlag({
|
||||
.longName = "command",
|
||||
.shortName = 'c',
|
||||
.description = "command and arguments to be executed insted of an interactive shell",
|
||||
.labels = {"command", "args"},
|
||||
.handler = {[&](std::vector<std::string> ss) {
|
||||
if (ss.empty()) throw UsageError("--command requires at least one argument");
|
||||
command = ss;
|
||||
}}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -337,6 +337,8 @@ struct CmdPrintDevEnv : Common
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
auto buildEnvironment = getBuildEnvironment(store).first;
|
||||
|
|
|
@ -40,9 +40,11 @@ struct CmdDoctor : StoreCommand
|
|||
|
||||
std::string description() override
|
||||
{
|
||||
return "check your system for potential problems and print a PASS or FAIL for each check.";
|
||||
return "check your system for potential problems and print a PASS or FAIL for each check";
|
||||
}
|
||||
|
||||
Category category() override { return catNixInstallation; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
logger->log("Running checks against store uri: " + store->getUri());
|
||||
|
|
|
@ -20,6 +20,8 @@ struct CmdDumpPath : StorePathCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store, const StorePath & storePath) override
|
||||
{
|
||||
FdSink sink(STDOUT_FILENO);
|
||||
|
|
|
@ -25,6 +25,8 @@ struct CmdEdit : InstallableCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catSecondary; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
auto state = getEvalState();
|
||||
|
|
|
@ -45,6 +45,8 @@ struct CmdEval : MixJSON, InstallableCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catSecondary; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
if (raw && json)
|
||||
|
|
|
@ -204,10 +204,11 @@ struct CmdFlakeCheck : FlakeCommand
|
|||
|
||||
CmdFlakeCheck()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("no-build")
|
||||
.description("do not build checks")
|
||||
.set(&build, false);
|
||||
addFlag({
|
||||
.longName = "no-build",
|
||||
.description = "do not build checks",
|
||||
.handler = {&build, false}
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -577,12 +578,13 @@ struct CmdFlakeClone : FlakeCommand
|
|||
|
||||
CmdFlakeClone()
|
||||
{
|
||||
mkFlag()
|
||||
.shortName('f')
|
||||
.longName("dest")
|
||||
.label("path")
|
||||
.description("destination path")
|
||||
.dest(&destDir);
|
||||
addFlag({
|
||||
.longName = "dest",
|
||||
.shortName = 'f',
|
||||
.description = "destination path",
|
||||
.labels = {"path"},
|
||||
.handler = {&destDir}
|
||||
});
|
||||
}
|
||||
|
||||
void run(nix::ref<nix::Store> store) override
|
||||
|
@ -600,11 +602,12 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun
|
|||
|
||||
CmdFlakeArchive()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("to")
|
||||
.labels({"store-uri"})
|
||||
.description("URI of the destination Nix store")
|
||||
.dest(&dstUri);
|
||||
addFlag({
|
||||
.longName = "to",
|
||||
.description = "URI of the destination Nix store",
|
||||
.labels = {"store-uri"},
|
||||
.handler = {&dstUri}
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -677,15 +680,17 @@ struct CmdFlakeShow : FlakeCommand
|
|||
|
||||
CmdFlakeShow()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("legacy")
|
||||
.description("show the contents of the 'legacyPackages' output")
|
||||
.set(&showLegacy, true);
|
||||
addFlag({
|
||||
.longName = "legacy",
|
||||
.description = "show the contents of the 'legacyPackages' output",
|
||||
.handler = {&showLegacy, true}
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("no-eval-cache")
|
||||
.description("do not use the flake evaluation cache")
|
||||
.handler([&]() { useEvalCache = false; });
|
||||
addFlag({
|
||||
.longName = "no-eval-cache",
|
||||
.description = "do not use the flake evaluation cache",
|
||||
.handler = {[&]() { useEvalCache = false; }}
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -849,8 +854,8 @@ struct CmdFlake : virtual MultiCommand, virtual Command
|
|||
{
|
||||
if (!command)
|
||||
throw UsageError("'nix flake' requires a sub-command.");
|
||||
command->prepare();
|
||||
command->run();
|
||||
command->second->prepare();
|
||||
command->second->run();
|
||||
}
|
||||
|
||||
void printHelp(const string & programName, std::ostream & out) override
|
||||
|
|
|
@ -23,9 +23,7 @@ struct CmdHash : Command
|
|||
mkFlag(0, "base64", "print hash in base-64", &base, Base64);
|
||||
mkFlag(0, "base32", "print hash in base-32 (Nix-specific)", &base, Base32);
|
||||
mkFlag(0, "base16", "print hash in base-16", &base, Base16);
|
||||
mkFlag()
|
||||
.longName("type")
|
||||
.mkHashTypeFlag(&ht);
|
||||
addFlag(Flag::mkHashTypeFlag("type", &ht));
|
||||
#if 0
|
||||
mkFlag()
|
||||
.longName("modulo")
|
||||
|
@ -43,6 +41,8 @@ struct CmdHash : Command
|
|||
: "print cryptographic hash of the NAR serialisation of a path";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run() override
|
||||
{
|
||||
for (auto path : paths) {
|
||||
|
@ -76,9 +76,7 @@ struct CmdToBase : Command
|
|||
|
||||
CmdToBase(Base base) : base(base)
|
||||
{
|
||||
mkFlag()
|
||||
.longName("type")
|
||||
.mkHashTypeFlag(&ht);
|
||||
addFlag(Flag::mkHashTypeFlag("type", &ht));
|
||||
expectArgs("strings", &args);
|
||||
}
|
||||
|
||||
|
@ -91,6 +89,8 @@ struct CmdToBase : Command
|
|||
"SRI");
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run() override
|
||||
{
|
||||
for (auto s : args)
|
||||
|
|
|
@ -19,65 +19,73 @@ namespace nix {
|
|||
|
||||
MixFlakeOptions::MixFlakeOptions()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("recreate-lock-file")
|
||||
.description("recreate lock file from scratch")
|
||||
.set(&lockFlags.recreateLockFile, true);
|
||||
|
||||
mkFlag()
|
||||
.longName("no-update-lock-file")
|
||||
.description("do not allow any updates to the lock file")
|
||||
.set(&lockFlags.updateLockFile, false);
|
||||
|
||||
mkFlag()
|
||||
.longName("no-write-lock-file")
|
||||
.description("do not write the newly generated lock file")
|
||||
.set(&lockFlags.writeLockFile, false);
|
||||
|
||||
mkFlag()
|
||||
.longName("no-registries")
|
||||
.description("don't use flake registries")
|
||||
.set(&lockFlags.useRegistries, false);
|
||||
|
||||
mkFlag()
|
||||
.longName("commit-lock-file")
|
||||
.description("commit changes to the lock file")
|
||||
.set(&lockFlags.commitLockFile, true);
|
||||
|
||||
mkFlag()
|
||||
.longName("update-input")
|
||||
.description("update a specific flake input")
|
||||
.label("input-path")
|
||||
.handler([&](std::vector<std::string> ss) {
|
||||
lockFlags.inputUpdates.insert(flake::parseInputPath(ss[0]));
|
||||
addFlag({
|
||||
.longName = "recreate-lock-file",
|
||||
.description = "recreate lock file from scratch",
|
||||
.handler = {&lockFlags.recreateLockFile, true}
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("override-input")
|
||||
.description("override a specific flake input (e.g. 'dwarffs/nixpkgs')")
|
||||
.arity(2)
|
||||
.labels({"input-path", "flake-url"})
|
||||
.handler([&](std::vector<std::string> ss) {
|
||||
addFlag({
|
||||
.longName = "no-update-lock-file",
|
||||
.description = "do not allow any updates to the lock file",
|
||||
.handler = {&lockFlags.updateLockFile, false}
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "no-write-lock-file",
|
||||
.description = "do not write the newly generated lock file",
|
||||
.handler = {&lockFlags.writeLockFile, false}
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "no-registries",
|
||||
.description = "don't use flake registries",
|
||||
.handler = {&lockFlags.useRegistries, false}
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "commit-lock-file",
|
||||
.description = "commit changes to the lock file",
|
||||
.handler = {&lockFlags.commitLockFile, true}
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "update-input",
|
||||
.description = "update a specific flake input",
|
||||
.labels = {"input-path"},
|
||||
.handler = {[&](std::string s) {
|
||||
lockFlags.inputUpdates.insert(flake::parseInputPath(s));
|
||||
}}
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "override-input",
|
||||
.description = "override a specific flake input (e.g. 'dwarffs/nixpkgs')",
|
||||
.labels = {"input-path", "flake-url"},
|
||||
.handler = {[&](std::string inputPath, std::string flakeRef) {
|
||||
lockFlags.inputOverrides.insert_or_assign(
|
||||
flake::parseInputPath(ss[0]),
|
||||
parseFlakeRef(ss[1], absPath(".")));
|
||||
flake::parseInputPath(inputPath),
|
||||
parseFlakeRef(flakeRef, absPath(".")));
|
||||
}}
|
||||
});
|
||||
}
|
||||
|
||||
SourceExprCommand::SourceExprCommand()
|
||||
{
|
||||
mkFlag()
|
||||
.shortName('f')
|
||||
.longName("file")
|
||||
.label("file")
|
||||
.description("evaluate attributes from FILE")
|
||||
.dest(&file);
|
||||
addFlag({
|
||||
.longName = "file",
|
||||
.shortName = 'f',
|
||||
.description = "evaluate FILE rather than the default",
|
||||
.labels = {"file"},
|
||||
.handler = {&file}
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("expr")
|
||||
.label("expr")
|
||||
.description("evaluate attributes from EXPR")
|
||||
.dest(&expr);
|
||||
addFlag({
|
||||
.longName ="expr",
|
||||
.description = "evaluate attributes from EXPR",
|
||||
.labels = {"expr"},
|
||||
.handler = {&expr}
|
||||
});
|
||||
}
|
||||
|
||||
Strings SourceExprCommand::getDefaultFlakeAttrPaths()
|
||||
|
|
|
@ -31,6 +31,8 @@ struct CmdLog : InstallableCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catSecondary; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
settings.readOnlyMode = true;
|
||||
|
|
|
@ -100,9 +100,11 @@ struct CmdLsStore : StoreCommand, MixLs
|
|||
|
||||
std::string description() override
|
||||
{
|
||||
return "show information about a store path";
|
||||
return "show information about a path in the Nix store";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
list(store->getFSAccessor());
|
||||
|
@ -131,9 +133,11 @@ struct CmdLsNar : Command, MixLs
|
|||
|
||||
std::string description() override
|
||||
{
|
||||
return "show information about the contents of a NAR file";
|
||||
return "show information about a path inside a NAR file";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run() override
|
||||
{
|
||||
list(makeNarAccessor(make_ref<std::string>(readFile(narPath, true))));
|
||||
|
|
|
@ -59,15 +59,22 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
|
|||
|
||||
NixArgs() : MultiCommand(*RegisterCommand::commands), MixCommonArgs("nix")
|
||||
{
|
||||
mkFlag()
|
||||
.longName("help")
|
||||
.description("show usage information")
|
||||
.handler([&]() { showHelpAndExit(); });
|
||||
categories.clear();
|
||||
categories[Command::catDefault] = "Main commands";
|
||||
categories[catSecondary] = "Infrequently used commands";
|
||||
categories[catUtility] = "Utility/scripting commands";
|
||||
categories[catNixInstallation] = "Commands for upgrading or troubleshooting your Nix installation";
|
||||
|
||||
mkFlag()
|
||||
.longName("help-config")
|
||||
.description("show configuration options")
|
||||
.handler([&]() {
|
||||
addFlag({
|
||||
.longName = "help",
|
||||
.description = "show usage information",
|
||||
.handler = {[&]() { showHelpAndExit(); }},
|
||||
});
|
||||
|
||||
addFlag({
|
||||
.longName = "help-config",
|
||||
.description = "show configuration options",
|
||||
.handler = {[&]() {
|
||||
std::cout << "The following configuration options are available:\n\n";
|
||||
Table2 tbl;
|
||||
std::map<std::string, Config::SettingInfo> settings;
|
||||
|
@ -76,28 +83,33 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
|
|||
tbl.emplace_back(s.first, s.second.description);
|
||||
printTable(std::cout, tbl);
|
||||
throw Exit();
|
||||
}},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("print-build-logs")
|
||||
.shortName('L')
|
||||
.description("print full build logs on stderr")
|
||||
.set(&printBuildLogs, true);
|
||||
addFlag({
|
||||
.longName = "print-build-logs",
|
||||
.shortName = 'L',
|
||||
.description = "print full build logs on stderr",
|
||||
.handler = {&printBuildLogs, true},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("version")
|
||||
.description("show version information")
|
||||
.handler([&]() { printVersion(programName); });
|
||||
addFlag({
|
||||
.longName = "version",
|
||||
.description = "show version information",
|
||||
.handler = {[&]() { printVersion(programName); }},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("no-net")
|
||||
.description("disable substituters and consider all previously downloaded files up-to-date")
|
||||
.handler([&]() { useNet = false; });
|
||||
addFlag({
|
||||
.longName = "no-net",
|
||||
.description = "disable substituters and consider all previously downloaded files up-to-date",
|
||||
.handler = {[&]() { useNet = false; }},
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("refresh")
|
||||
.description("consider all previously downloaded files out-of-date")
|
||||
.handler([&]() { refresh = true; });
|
||||
addFlag({
|
||||
.longName = "refresh",
|
||||
.description = "consider all previously downloaded files out-of-date",
|
||||
.handler = {[&]() { refresh = true; }},
|
||||
});
|
||||
}
|
||||
|
||||
void printFlags(std::ostream & out) override
|
||||
|
@ -105,8 +117,8 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
|
|||
Args::printFlags(out);
|
||||
std::cout <<
|
||||
"\n"
|
||||
"In addition, most configuration settings can be overriden using '--<name> <value>'.\n"
|
||||
"Boolean settings can be overriden using '--<name>' or '--no-<name>'. See 'nix\n"
|
||||
"In addition, most configuration settings can be overriden using '--" ANSI_ITALIC "name value" ANSI_NORMAL "'.\n"
|
||||
"Boolean settings can be overriden using '--" ANSI_ITALIC "name" ANSI_NORMAL "' or '--no-" ANSI_ITALIC "name" ANSI_NORMAL "'. See 'nix\n"
|
||||
"--help-config' for a list of configuration settings.\n";
|
||||
}
|
||||
|
||||
|
@ -115,10 +127,10 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
|
|||
MultiCommand::printHelp(programName, out);
|
||||
|
||||
#if 0
|
||||
out << "\nFor full documentation, run 'man " << programName << "' or 'man " << programName << "-<COMMAND>'.\n";
|
||||
out << "\nFor full documentation, run 'man " << programName << "' or 'man " << programName << "-" ANSI_ITALIC "COMMAND" ANSI_NORMAL "'.\n";
|
||||
#endif
|
||||
|
||||
std::cout << "\nNote: this program is EXPERIMENTAL and subject to change.\n";
|
||||
std::cout << "\nNote: this program is " ANSI_RED "EXPERIMENTAL" ANSI_NORMAL " and subject to change.\n";
|
||||
}
|
||||
|
||||
void showHelpAndExit()
|
||||
|
@ -186,8 +198,8 @@ void mainWrapped(int argc, char * * argv)
|
|||
if (args.refresh)
|
||||
settings.tarballTtl = 0;
|
||||
|
||||
args.command->prepare();
|
||||
args.command->run();
|
||||
args.command->second->prepare();
|
||||
args.command->second->run();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
|
|||
},
|
||||
};
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store, StorePaths storePaths) override
|
||||
{
|
||||
auto paths = store->topoSortPaths(storePathsToSet(storePaths));
|
||||
|
|
|
@ -23,6 +23,8 @@ struct CmdOptimiseStore : StoreCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
store->optimiseStore();
|
||||
|
|
|
@ -29,6 +29,8 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
|
|||
return "query information about store paths";
|
||||
}
|
||||
|
||||
Category category() override { return catSecondary; }
|
||||
|
||||
Examples examples() override
|
||||
{
|
||||
return {
|
||||
|
|
|
@ -21,6 +21,8 @@ struct CmdPingStore : StoreCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
store->connect();
|
||||
|
|
|
@ -413,8 +413,8 @@ struct CmdProfile : virtual MultiCommand, virtual Command
|
|||
{
|
||||
if (!command)
|
||||
throw UsageError("'nix profile' requires a sub-command.");
|
||||
command->prepare();
|
||||
command->run();
|
||||
command->second->prepare();
|
||||
command->second->run();
|
||||
}
|
||||
|
||||
void printHelp(const string & programName, std::ostream & out) override
|
||||
|
|
|
@ -63,15 +63,15 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
|
|||
|
||||
CmdShell()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("command")
|
||||
.shortName('c')
|
||||
.description("command and arguments to be executed; defaults to '$SHELL'")
|
||||
.labels({"command", "args"})
|
||||
.arity(ArityAny)
|
||||
.handler([&](std::vector<std::string> ss) {
|
||||
addFlag({
|
||||
.longName = "command",
|
||||
.shortName = 'c',
|
||||
.description = "command and arguments to be executed; defaults to '$SHELL'",
|
||||
.labels = {"command", "args"},
|
||||
.handler = {[&](std::vector<std::string> ss) {
|
||||
if (ss.empty()) throw UsageError("--command requires at least one argument");
|
||||
command = ss;
|
||||
}}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -84,8 +84,8 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment
|
|||
{
|
||||
return {
|
||||
Example{
|
||||
"To start a shell providing GNU Hello from NixOS 17.03:",
|
||||
"nix shell -f channel:nixos-17.03 hello"
|
||||
"To start a shell providing GNU Hello from NixOS 20.03:",
|
||||
"nix shell nixpkgs/nixos-20.03#hello"
|
||||
},
|
||||
Example{
|
||||
"To start a shell providing youtube-dl from your 'nixpkgs' channel:",
|
||||
|
|
|
@ -13,6 +13,8 @@ struct CmdShowConfig : Command, MixJSON
|
|||
return "show the Nix configuration";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run() override
|
||||
{
|
||||
if (json) {
|
||||
|
|
|
@ -15,11 +15,12 @@ struct CmdShowDerivation : InstallablesCommand
|
|||
|
||||
CmdShowDerivation()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("recursive")
|
||||
.shortName('r')
|
||||
.description("include the dependencies of the specified derivations")
|
||||
.set(&recursive, true);
|
||||
addFlag({
|
||||
.longName = "recursive",
|
||||
.shortName = 'r',
|
||||
.description = "include the dependencies of the specified derivations",
|
||||
.handler = {&recursive, true}
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -41,6 +42,8 @@ struct CmdShowDerivation : InstallablesCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
auto drvPaths = toDerivations(store, installables, true);
|
||||
|
|
|
@ -13,13 +13,13 @@ struct CmdCopySigs : StorePathsCommand
|
|||
|
||||
CmdCopySigs()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("substituter")
|
||||
.shortName('s')
|
||||
.labels({"store-uri"})
|
||||
.description("use signatures from specified store")
|
||||
.arity(1)
|
||||
.handler([&](std::vector<std::string> ss) { substituterUris.push_back(ss[0]); });
|
||||
addFlag({
|
||||
.longName = "substituter",
|
||||
.shortName = 's',
|
||||
.description = "use signatures from specified store",
|
||||
.labels = {"store-uri"},
|
||||
.handler = {[&](std::string s) { substituterUris.push_back(s); }},
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -27,6 +27,8 @@ struct CmdCopySigs : StorePathsCommand
|
|||
return "copy path signatures from substituters (like binary caches)";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store, StorePaths storePaths) override
|
||||
{
|
||||
if (substituterUris.empty())
|
||||
|
@ -98,12 +100,13 @@ struct CmdSignPaths : StorePathsCommand
|
|||
|
||||
CmdSignPaths()
|
||||
{
|
||||
mkFlag()
|
||||
.shortName('k')
|
||||
.longName("key-file")
|
||||
.label("file")
|
||||
.description("file containing the secret signing key")
|
||||
.dest(&secretKeyFile);
|
||||
addFlag({
|
||||
.longName = "key-file",
|
||||
.shortName = 'k',
|
||||
.description = "file containing the secret signing key",
|
||||
.labels = {"file"},
|
||||
.handler = {&secretKeyFile}
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -111,6 +114,8 @@ struct CmdSignPaths : StorePathsCommand
|
|||
return "sign the specified paths";
|
||||
}
|
||||
|
||||
Category category() override { return catUtility; }
|
||||
|
||||
void run(ref<Store> store, StorePaths storePaths) override
|
||||
{
|
||||
if (secretKeyFile.empty())
|
||||
|
|
|
@ -16,18 +16,20 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
|||
|
||||
CmdUpgradeNix()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("profile")
|
||||
.shortName('p')
|
||||
.labels({"profile-dir"})
|
||||
.description("the Nix profile to upgrade")
|
||||
.dest(&profileDir);
|
||||
addFlag({
|
||||
.longName = "profile",
|
||||
.shortName = 'p',
|
||||
.description = "the Nix profile to upgrade",
|
||||
.labels = {"profile-dir"},
|
||||
.handler = {&profileDir}
|
||||
});
|
||||
|
||||
mkFlag()
|
||||
.longName("nix-store-paths-url")
|
||||
.labels({"url"})
|
||||
.description("URL of the file that contains the store paths of the latest Nix release")
|
||||
.dest(&storePathsUrl);
|
||||
addFlag({
|
||||
.longName = "nix-store-paths-url",
|
||||
.description = "URL of the file that contains the store paths of the latest Nix release",
|
||||
.labels = {"url"},
|
||||
.handler = {&storePathsUrl}
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -49,6 +51,8 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catNixInstallation; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
evalSettings.pureEval = true;
|
||||
|
|
|
@ -20,13 +20,13 @@ struct CmdVerify : StorePathsCommand
|
|||
{
|
||||
mkFlag(0, "no-contents", "do not verify the contents of each store path", &noContents);
|
||||
mkFlag(0, "no-trust", "do not verify whether each store path is trusted", &noTrust);
|
||||
mkFlag()
|
||||
.longName("substituter")
|
||||
.shortName('s')
|
||||
.labels({"store-uri"})
|
||||
.description("use signatures from specified store")
|
||||
.arity(1)
|
||||
.handler([&](std::vector<std::string> ss) { substituterUris.push_back(ss[0]); });
|
||||
addFlag({
|
||||
.longName = "substituter",
|
||||
.shortName = 's',
|
||||
.description = "use signatures from specified store",
|
||||
.labels = {"store-uri"},
|
||||
.handler = {[&](std::string s) { substituterUris.push_back(s); }}
|
||||
});
|
||||
mkIntFlag('n', "sigs-needed", "require that each path has at least N valid signatures", &sigsNeeded);
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,8 @@ struct CmdVerify : StorePathsCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catSecondary; }
|
||||
|
||||
void run(ref<Store> store, StorePaths storePaths) override
|
||||
{
|
||||
std::vector<ref<Store>> substituters;
|
||||
|
|
|
@ -37,11 +37,12 @@ struct CmdWhyDepends : SourceExprCommand
|
|||
expectArg("package", &_package);
|
||||
expectArg("dependency", &_dependency);
|
||||
|
||||
mkFlag()
|
||||
.longName("all")
|
||||
.shortName('a')
|
||||
.description("show all edges in the dependency graph leading from 'package' to 'dependency', rather than just a shortest path")
|
||||
.set(&all, true);
|
||||
addFlag({
|
||||
.longName = "all",
|
||||
.shortName = 'a',
|
||||
.description = "show all edges in the dependency graph leading from 'package' to 'dependency', rather than just a shortest path",
|
||||
.handler = {&all, true},
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -67,6 +68,8 @@ struct CmdWhyDepends : SourceExprCommand
|
|||
};
|
||||
}
|
||||
|
||||
Category category() override { return catSecondary; }
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
auto package = parseInstallable(store, _package);
|
||||
|
|
Loading…
Reference in a new issue