Skip to main content

tome/
cli.rs

1use clap::{Args, Parser, Subcommand};
2
3#[derive(Debug, Parser)]
4#[clap(author, version, about, long_about = None)]
5pub struct TomeArgs {
6    #[clap(subcommand)]
7    pub commands: TomeCommands,
8}
9
10#[derive(Debug, Subcommand)]
11pub enum TomeCommands {
12    // if we use "Help" directly, this
13    // subcommand is overshaddowed by clap's own help
14    // command. Therefore this is named CommandHelp
15    CommandHelp(HelpArgs),
16    CommandComplete(CompleteArgs),
17    CommandExecute(ExecuteArgs),
18    Init(InitArgs),
19    /// find a script and exec it.
20    /// run will not run the script in completion mode,
21    /// regardless of the script front matter. builtins such as
22    /// help are not accessible via this command
23    Run(RunArgs),
24}
25
26#[derive(Debug, Args)]
27pub struct CompleteArgs {
28    pub command_directory_path: String,
29    /// The type of the shell that is invoking completion
30    #[clap(short, long)]
31    pub shell: String,
32    #[clap(last = true)]
33    pub args: Vec<String>,
34}
35
36#[derive(Debug, Args)]
37pub struct ExecuteArgs {
38    pub command_directory_path: String,
39    #[clap(short, long)]
40    pub shell: String,
41    #[clap(last = true)]
42    pub args: Vec<String>,
43}
44
45#[derive(Debug, Args)]
46pub struct HelpArgs {
47    pub command_directory_path: String,
48    #[clap(last = true)]
49    pub args: Vec<String>,
50}
51
52#[derive(Debug, Args)]
53pub struct InitArgs {
54    /// The name for the generated command.
55    pub command_name: String,
56    /// The path to the directory that contains the commands to load.
57    pub command_directory_path: String,
58    /// The type of the shell to use, or the path to the shell executable being used.
59    pub shell_type_or_path: String,
60}
61
62#[derive(Debug, Args)]
63pub struct RunArgs {
64    pub command_directory_path: String,
65    #[clap(last = true)]
66    pub args: Vec<String>,
67}