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 (defaults to 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}
52
53#[derive(Debug, Args)]
54pub struct MigrationListArgs {
55    /// Path to the crate directory to list migrations for  [default: current
56    /// directory]
57    pub path: Option<PathBuf>,
58}
59
60#[derive(Debug, Args)]
61pub struct MigrationMakeArgs {
62    /// Path to the crate directory to generate migrations for [default: current
63    /// directory]
64    pub path: Option<PathBuf>,
65    /// Name of the app to use in the migration (default: crate name)
66    #[arg(long)]
67    pub app_name: Option<String>,
68    /// Directory to write the migrations to (default: migrations/ directory
69    /// in the crate's src/ directory)
70    #[arg(long)]
71    pub output_dir: Option<PathBuf>,
72}
73
74#[derive(Debug, Args)]
75#[group(multiple = false)]
76pub struct CotSourceArgs {
77    /// Use the latest `cot` version from git instead of a published crate
78    #[arg(long, group = "cot_source")]
79    pub use_git: bool,
80    /// Use `cot` from the specified path instead of a published crate
81    #[arg(long, group = "cot_source")]
82    pub cot_path: Option<PathBuf>,
83}
84
85#[derive(Debug, Subcommand)]
86pub enum CliCommands {
87    /// Generate manpages for the Cot CLI
88    Manpages(ManpagesArgs),
89    /// Generate completions for the Cot CLI
90    Completions(CompletionsArgs),
91}
92
93#[derive(Debug, Args)]
94pub struct ManpagesArgs {
95    /// Directory to write the manpages to [default: current directory]
96    #[arg(short, long)]
97    pub output_dir: Option<PathBuf>,
98    /// Create the directory if it doesn't exist
99    #[arg(short, long)]
100    pub create: bool,
101}
102
103#[derive(Debug, Clone, Copy, Args)]
104pub struct CompletionsArgs {
105    /// Shell to generate completions for
106    pub shell: clap_complete::Shell,
107}