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