ArKanjo 0.5.1
A tool for find code duplicated functions in codebases
main.cpp
Go to the documentation of this file.
5
9
10int main(int argc, char* argv[]) {
11 auto& cfg = Config::config();
12 cfg.setDefaultConfig();
13
14 Orchestrator orchestrator;
15 Context ctx;
16
17 Similarity_Table similarity_table;
18
19 ctx.command_name = (argc > 1) ? argv[1] : OrchestratorHelper::DEFAULT_COMMAND;
20
21 ctx.argc = argc;
22 ctx.argv = argv;
23
24 std::unique_ptr<ICommand> command;
25 auto internal_commands = OrchestratorCommands::create_internal_commands(similarity_table);
26 orchestrator.add_step(OrchestratorHelper::setup_command_step(command, internal_commands));
27
28 OptionsCollector collector;
29 orchestrator.add_step([&command, &collector](Context&) {
30 if (!command)
31 return false;
32
34 collector.add_options(command->options());
35
36 return true;
37 });
38
39 orchestrator.add_step(collector.make_parse_step(argc, argv));
40
42
43 orchestrator.add_step([&similarity_table, &orchestrator, &command, &collector](Context& ctx) {
44 if (auto name = ctx.options.get("name"))
46
47 if (ctx.command_name != "help" && !ctx.options.has("help"))
48 orchestrator.add_step(OrchestratorHelper::similarity_step(similarity_table));
49
50 orchestrator.add_step(OrchestratorHelper::command_run_step(std::move(command), collector));
51
52 return true;
53 });
54
55 try {
56 orchestrator.run_pipeline(ctx);
57 } catch (const CommandNotFoundError& e) {
58 if (ctx.command_name != "help" && !ctx.options.has("help"))
59 FormatterManager::warn(ctx.command_name + " is not a " + Config::config().program_name + " command.");
60 std::make_unique<Help>(internal_commands)->do_run(ctx.command_name, ctx.options);
61 return 1;
62 } catch (const CLIError& e) {
63 std::cerr << e.what() << "\n";
64 return 1;
65 } catch (const std::exception& e) {
66 std::cerr << "Unexpected error: " << e.what() << "\n";
67 return 1;
68 }
69
70 return 0;
71}
Base class for CLI-related errors.
Definition: cli_error.hpp:10
An error is thrown when an unknown command is passed.
Definition: cli_error.hpp:32
static Config & config()
Gets the singleton configuration instance.
Definition: config.cpp:68
static void warn(const std::string &str)
void add_options(const CliOption *long_opts)
Step make_parse_step(int argc, char *argv[])
Main command orchestrator.
void run_pipeline(Context &ctx)
void add_step(Step step)
Represents a similarity graph between functions (paths).
int main(int argc, char *argv[])
Definition: main.cpp:10
CommandMap< Table > create_internal_commands(Table &table)
Step setup_command_step(std::unique_ptr< ICommand > &command, const std::vector< std::pair< std::vector< std::string >, CommandsRegistry::CommandFactory > > &commands)
Step similarity_step(Similarity_Table &table)
constexpr CliOption global_long_opts[]
bool formatter_step(Context &ctx)
Step command_run_step(std::shared_ptr< ICommand > command, const OptionsCollector &collector)
Main command orchestration interface.
char ** argv
ParsedOptions options
std::string command_name
bool has(const std::string &name) const
Checks whether an option exists.
std::optional< std::string_view > get(const std::string &name) const
Returns the value of an option.
std::string program_name
Name of the program.
Definition: schema.hpp:15
std::filesystem::path name_container
Name of the cache container.
Definition: schema.hpp:18