Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
5
10
11int main(int argc, char* argv[]) {
12 auto& cfg = Config::config();
13 cfg.setDefaultConfig();
14
15 Orchestrator orchestrator;
16 Context ctx;
17
18 Similarity_Table similarity_table;
19
20 ctx.command_name = (argc > 1) ? argv[1] : OrchestratorHelper::DEFAULT_COMMAND;
21
22 ctx.argc = argc;
23 ctx.argv = argv;
24
25 std::unique_ptr<ICommand> command;
26 auto internal_commands = OrchestratorCommands::create_internal_commands(similarity_table);
27 orchestrator.add_step(OrchestratorHelper::setup_command_step(command, internal_commands));
28
29 OptionsCollector collector;
30 orchestrator.add_step([&command, &collector](Context&) {
31 if (!command)
32 return false;
33
35 collector.add_options(command->options());
36
37 return true;
38 });
39
40 orchestrator.add_step(collector.make_parse_step(argc, argv));
41
43
44 orchestrator.add_step([&similarity_table, &orchestrator, &command, &collector](Context& ctx) {
45 auto it_name = ctx.options.args.find("name");
46 if (it_name != ctx.options.args.end()) {
47 Config::config().name_container = it_name->second;
48 }
49
50 if (ctx.command_name != "help" && ctx.options.args.count("help") == 0) {
51 orchestrator.add_step([](Context& ctx) {
52 bool force_pre = ctx.options.args.count("preprocessor") > 0;
53 PreprocessorBuild pre(force_pre);
54 return true;
55 });
56 orchestrator.add_step(OrchestratorHelper::similarity_step(similarity_table));
57 }
58
59 orchestrator.add_step(OrchestratorHelper::command_run_step(std::move(command), collector));
60
61 return true;
62 });
63
64 try {
65 orchestrator.run_pipeline(ctx);
66 } catch (const CommandNotFoundError& e) {
67 if (ctx.command_name != "help" && ctx.options.args.count("help") == 0)
68 FormatterManager::warn(ctx.command_name + " is not a " + Config::config().program_name + " command.");
69 std::make_unique<Help>(internal_commands)->do_run(ctx.command_name, ctx.options);
70 return 1;
71 } catch (const CLIError& e) {
72 std::cerr << e.what() << "\n";
73 return 1;
74 } catch (const std::exception& e) {
75 std::cerr << "Unexpected error: " << e.what() << "\n";
76 return 1;
77 }
78
79 return 0;
80}
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:37
std::string program_name
Name of the program.
Definition config.hpp:41
fs::path name_container
Name of the cache container.
Definition config.hpp:44
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)
Codebase preprocessing orchestrator.
Represents a similarity graph between functions (paths).
int main(int argc, char *argv[])
Definition main.cpp:11
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.
Codebase preprocessing interface.
char ** argv
ParsedOptions options
std::string command_name
std::map< std::string, std::string > args
Map from option name to value.