Skip to main content

cot_cli/
args.rs

1use std::path::PathBuf;
2
3use clap::{Args, Parser, Subcommand};
4use clap_verbosity_flag::Verbosity;
5
6#[derive(Debug, Parser)]
7#[command(
8    name = "cot",
9    version,
10    about,
11    long_about = None
12)]
13pub struct Cli {
14    #[command(flatten)]
15    pub verbose: Verbosity,
16    #[command(subcommand)]
17    pub command: Commands,
18}
19
20#[derive(Debug, Subcommand)]
21pub enum Commands {
22    /// Create a new Cot project
23    New(ProjectNewArgs),
24
25    /// Manage migrations for a Cot project
26    #[command(subcommand)]
27    Migration(MigrationCommands),
28
29    /// Manage Cot CLI
30    #[command(subcommand)]
31    Cli(CliCommands),
32}
33
34#[derive(Debug, Args)]
35pub struct ProjectNewArgs {
36    /// Path to the directory to create the new project in
37    pub path: PathBuf,
38    /// Set the resulting crate name [default: the directory name]
39    #[arg(long)]
40    pub name: Option<String>,
41    #[command(flatten)]
42    pub source: CotSourceArgs,
43}
44
45#[derive(Debug, Subcommand)]
46pub enum MigrationCommands {
47    /// List all migrations for a Cot project
48    List(MigrationListArgs),
49    /// Generate migrations for a Cot project
50    Make(MigrationMakeArgs),
51    /// Create a new empty migration
52    New(MigrationNewArgs),
53}
54
55#[derive(Debug, Args)]
56pub struct MigrationNewArgs {
57    /// Name of the migration
58    pub name: String,
59    /// Path to the crate directory to create the migration in [default: current
60    /// directory]
61    pub path: Option<PathBuf>,
62    /// Name of the app to use in the migration (default: crate name)
63    #[arg(long)]
64    pub app_name: Option<String>,
65}
66
67#[derive(Debug, Args)]
68pub struct MigrationListArgs {
69    /// Path to the crate directory to list migrations for [default: current
70    /// directory]
71    pub path: Option<PathBuf>,
72}
73
74#[derive(Debug, Args)]
75pub struct MigrationMakeArgs {
76    /// Path to the crate directory to generate migrations for [default: current
77    /// directory]
78    pub path: Option<PathBuf>,
79    /// Name of the app to use in the migration [default: crate name]
80    #[arg(long)]
81    pub app_name: Option<String>,
82    /// Directory to write the migrations to [default: the migrations/ directory
83    /// in the crate's src/ directory]
84    #[arg(long)]
85    pub output_dir: Option<PathBuf>,
86}
87
88#[derive(Debug, Args)]
89#[group(multiple = false)]
90pub struct CotSourceArgs {
91    /// Use the latest `cot` version from git instead of a published crate
92    #[arg(long, group = "cot_source")]
93    pub use_git: bool,
94    /// Use `cot` from the specified path instead of a published crate
95    #[arg(long, group = "cot_source")]
96    pub cot_path: Option<PathBuf>,
97}
98
99#[derive(Debug, Subcommand)]
100pub enum CliCommands {
101    /// Generate manpages for the Cot CLI
102    Manpages(ManpagesArgs),
103    /// Generate completions for the Cot CLI
104    Completions(CompletionsArgs),
105}
106
107#[derive(Debug, Args)]
108pub struct ManpagesArgs {
109    /// Directory to write the manpages to [default: current directory]
110    #[arg(short, long)]
111    pub output_dir: Option<PathBuf>,
112    /// Create the directory if it doesn't exist
113    #[arg(short, long)]
114    pub create: bool,
115}
116
117#[derive(Debug, Clone, Copy, Args)]
118pub struct CompletionsArgs {
119    /// Shell to generate completions for
120    pub shell: clap_complete::Shell,
121}