Command: Remove examples()

This commit is contained in:
Eelco Dolstra 2020-12-23 13:21:31 +01:00
parent c9279b831e
commit 1047cb1e53
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 0 additions and 49 deletions

View file

@ -20,11 +20,6 @@ let
(attrNames def.commands))
+ "\n"
else "")
+ (if def.examples or [] != []
then
"# Examples\n\n"
+ concatStrings (map ({ description, command }: "${description}\n\n```console\n${command}\n```\n\n") def.examples)
else "")
+ (if def ? doc
then def.doc + "\n\n"
else "")

View file

@ -353,36 +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);
return res;
}
MultiCommand::MultiCommand(const Commands & commands)
: commands(commands)
{

View file

@ -228,25 +228,11 @@ struct Command : virtual Args
virtual void prepare() { };
virtual void run() = 0;
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;