1use clap::Parser;
2
3#[macro_use]
4extern crate lazy_static;
5
6pub mod cli;
7pub mod commands;
8pub mod constants;
9pub mod directory;
10pub mod finder;
11pub mod script;
12pub mod shell_type;
13pub mod types;
14
15#[cfg(test)]
16mod shell_type_tests;
17
18#[cfg(test)]
19mod lib_tests;
20
21pub fn execute(raw_args: Vec<String>) -> Result<String, String> {
22 let mut arguments = raw_args.iter().peekable();
23 let tome_executable = match arguments.peek() {
25 Some(arg) => (*arg).clone(),
26 None => return Err(String::from("0th argument should be the tome binary")),
27 };
28 match cli::TomeArgs::try_parse_from(arguments) {
29 Ok(tome_args) => match &tome_args.commands {
30 cli::TomeCommands::CommandComplete(complete_args) => commands::complete::complete(
31 &complete_args.command_directory_path,
32 &complete_args.shell,
33 &complete_args.args,
34 ),
35 cli::TomeCommands::CommandExecute(execute_args) => commands::execute::execute(
36 &execute_args.command_directory_path,
37 &execute_args.shell,
38 &execute_args.args,
39 ),
40 cli::TomeCommands::CommandHelp(help_args) => {
41 commands::help::help(&help_args.command_directory_path, &help_args.args)
42 }
43 cli::TomeCommands::Init(init_args) => commands::init::init(&tome_executable, init_args),
44 cli::TomeCommands::Run(run_args) => {
45 commands::run::run(&run_args.command_directory_path, &run_args.args)
46 }
47 },
48 Err(msg) => Err(msg.to_string()),
49 }
50}