Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
help.cpp
Go to the documentation of this file.
1#include "help.hpp"
2
3#include <iostream>
4
6 const std::vector<std::pair<std::vector<std::string>, CommandsRegistry::CommandFactory>>& commands)
7 : internal_commands(commands) {}
8
10 const std::vector<std::pair<std::vector<std::string>, CommandsRegistry::CommandFactory>>& commands,
11 const std::string command_name_)
12 : internal_commands(commands), command_name(command_name_) {}
13
14bool Help::validate([[maybe_unused]] const ParsedOptions& options) {
15 return true;
16}
17
18bool Help::run([[maybe_unused]] const ParsedOptions& options) {
19 std::string title_str = Config::config().program_name;
20 title_str += " ";
21 if (!command_name.empty()) {
22 title_str += command_name;
23 title_str += " ";
24 }
25 title_str += " - Available commands:";
26 std::cout << wrapped(title_str, 0);
27 std::cout << "\n";
28
29 for (const auto& [name, _] : internal_commands) {
30 if (name.empty()) continue;
31 std::cout << " " << name[0] << "\n";
32 }
33 std::cout << "\n";
34
35 std::string use_str = "Use '";
36 use_str += Config::config().program_name;
37 use_str += " ";
38 if (!command_name.empty()) {
39 use_str += command_name;
40 use_str += " ";
41 }
42 use_str += "<command> --help' for more information on a command.";
43 std::cout << wrapped(use_str, 0);
44
45 return true;
46}
static Config & config()
Gets the singleton configuration instance.
Definition config.cpp:37
std::string program_name
Name of the program.
Definition config.hpp:41
bool validate(const ParsedOptions &options) override
Validate the arguments already analyzed.
Definition help.cpp:14
bool run(const ParsedOptions &options) override
Displays help information about available commands.
Definition help.cpp:18
Help(const std::vector< std::pair< std::vector< std::string >, CommandsRegistry::CommandFactory > > &commands)
Definition help.cpp:5
std::function< std::unique_ptr< ICommand >()> CommandFactory
Wrapped wrapped(const std::string &text, size_t spaces=1, bool use_first_line=true)
Definition utils.cpp:90