mirror of
https://github.com/NixOS/nix.git
synced 2025-11-12 21:46:01 +01:00
Merge pull request #4336 from NixOS/manpages
Documentation for nix subcommands
This commit is contained in:
commit
a93916b190
81 changed files with 3245 additions and 485 deletions
|
|
@ -254,6 +254,8 @@ nlohmann::json Args::toJSON()
|
|||
res["description"] = description();
|
||||
res["flags"] = std::move(flags);
|
||||
res["args"] = std::move(args);
|
||||
auto s = doc();
|
||||
if (s != "") res.emplace("doc", stripIndentation(s));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -351,38 +353,6 @@ void printTable(std::ostream & out, const Table2 & table)
|
|||
}
|
||||
}
|
||||
|
||||
void Command::printHelp(const string & programName, std::ostream & out)
|
||||
{
|
||||
Args::printHelp(programName, out);
|
||||
|
||||
auto exs = examples();
|
||||
if (!exs.empty()) {
|
||||
out << "\n" ANSI_BOLD "Examples:" ANSI_NORMAL "\n";
|
||||
for (auto & ex : exs)
|
||||
out << "\n"
|
||||
<< " " << ex.description << "\n" // FIXME: wrap
|
||||
<< " $ " << ex.command << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
nlohmann::json Command::toJSON()
|
||||
{
|
||||
auto exs = nlohmann::json::array();
|
||||
|
||||
for (auto & example : examples()) {
|
||||
auto ex = nlohmann::json::object();
|
||||
ex["description"] = example.description;
|
||||
ex["command"] = chomp(stripIndentation(example.command));
|
||||
exs.push_back(std::move(ex));
|
||||
}
|
||||
|
||||
auto res = Args::toJSON();
|
||||
res["examples"] = std::move(exs);
|
||||
auto s = doc();
|
||||
if (s != "") res.emplace("doc", stripIndentation(s));
|
||||
return res;
|
||||
}
|
||||
|
||||
MultiCommand::MultiCommand(const Commands & commands)
|
||||
: commands(commands)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ public:
|
|||
/* Return a short one-line description of the command. */
|
||||
virtual std::string description() { return ""; }
|
||||
|
||||
/* Return documentation about this command, in Markdown format. */
|
||||
virtual std::string doc() { return ""; }
|
||||
|
||||
protected:
|
||||
|
||||
static const size_t ArityAny = std::numeric_limits<size_t>::max();
|
||||
|
|
@ -225,28 +228,11 @@ struct Command : virtual Args
|
|||
virtual void prepare() { };
|
||||
virtual void run() = 0;
|
||||
|
||||
/* Return documentation about this command, in Markdown format. */
|
||||
virtual std::string doc() { return ""; }
|
||||
|
||||
struct Example
|
||||
{
|
||||
std::string description;
|
||||
std::string command;
|
||||
};
|
||||
|
||||
typedef std::list<Example> Examples;
|
||||
|
||||
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;
|
||||
|
||||
nlohmann::json toJSON() override;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::function<ref<Command>()>> Commands;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue