forked from lix-project/lix
nix --help: Show usage examples
This commit is contained in:
parent
1b0088ebb2
commit
69e3ffb076
|
@ -5,6 +5,21 @@ namespace nix {
|
||||||
|
|
||||||
Commands * RegisterCommand::commands = 0;
|
Commands * RegisterCommand::commands = 0;
|
||||||
|
|
||||||
|
void Command::printHelp(const string & programName, std::ostream & out)
|
||||||
|
{
|
||||||
|
Args::printHelp(programName, out);
|
||||||
|
|
||||||
|
auto exs = examples();
|
||||||
|
if (!exs.empty()) {
|
||||||
|
out << "\n";
|
||||||
|
out << "Examples:\n";
|
||||||
|
for (auto & ex : exs)
|
||||||
|
out << "\n"
|
||||||
|
<< " " << ex.description << "\n" // FIXME: wrap
|
||||||
|
<< " $ " << ex.command << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MultiCommand::MultiCommand(const Commands & _commands)
|
MultiCommand::MultiCommand(const Commands & _commands)
|
||||||
: commands(_commands)
|
: commands(_commands)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,18 @@ struct Command : virtual Args
|
||||||
virtual std::string name() = 0;
|
virtual std::string name() = 0;
|
||||||
virtual void prepare() { };
|
virtual void prepare() { };
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
|
||||||
|
struct Example
|
||||||
|
{
|
||||||
|
std::string description;
|
||||||
|
std::string command;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::list<Example> Examples;
|
||||||
|
|
||||||
|
virtual Examples examples() { return Examples(); }
|
||||||
|
|
||||||
|
void printHelp(const string & programName, std::ostream & out) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Store;
|
class Store;
|
||||||
|
|
|
@ -36,6 +36,20 @@ struct CmdVerify : StorePathsCommand
|
||||||
return "verify the integrity of store paths";
|
return "verify the integrity of store paths";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Examples examples() override
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
Example{
|
||||||
|
"To verify the entire Nix store:",
|
||||||
|
"nix verify --all"
|
||||||
|
},
|
||||||
|
Example{
|
||||||
|
"To check whether each path in the closure of Firefox has at least 2 signatures:",
|
||||||
|
"nix verify -r -n2 --no-contents $(type -p firefox)"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void run(ref<Store> store, Paths storePaths) override
|
void run(ref<Store> store, Paths storePaths) override
|
||||||
{
|
{
|
||||||
restoreAffinity(); // FIXME
|
restoreAffinity(); // FIXME
|
||||||
|
|
Loading…
Reference in a new issue