callisto_cli/cli.rs
1use std::path::PathBuf;
2
3use clap::{Args, Parser, Subcommand, ValueEnum};
4
5/// Changesets-style version and release manager for Rust workspaces.
6#[derive(Parser)]
7#[command(name = "callisto", version)]
8pub struct Cli {
9 #[command(flatten)]
10 pub global: GlobalArgs,
11 #[command(subcommand)]
12 pub command: Command,
13}
14
15/// Flags shared by every subcommand.
16#[derive(Args, Clone, Debug)]
17pub struct GlobalArgs {
18 /// Output format for command results.
19 #[arg(long, global = true, value_enum, default_value = "text")]
20 pub format: OutputFormat,
21
22 /// Workspace directory to operate in (defaults to the current directory).
23 #[arg(long, global = true, default_value = ".")]
24 pub cwd: PathBuf,
25
26 #[arg(
27 long,
28 global = true,
29 help = "Preview manifest and file changes without writing to disk"
30 )]
31 pub dry_run: bool,
32}
33
34/// Output rendering mode: human-readable text or machine-readable JSON.
35#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
36pub enum OutputFormat {
37 Text,
38 Json,
39}
40
41/// A callisto subcommand.
42#[derive(Subcommand, Clone, Debug)]
43pub enum Command {
44 /// Create a new changeset describing pending package changes.
45 Add(AddArgs),
46 /// Show the workspace's pending changesets and diagnostics.
47 Status(StatusArgs),
48 /// Consume pending changesets and bump package versions accordingly.
49 Version(VersionArgs),
50 /// Manage prerelease mode for the workspace.
51 #[command(subcommand)]
52 Pre(PreArgs),
53 /// Check that changesets and the dependency graph are well-formed.
54 Validate(ValidateArgs),
55 /// Apply a temporary, non-persistent version bump for a snapshot release.
56 Snapshot(SnapshotArgs),
57 /// Scaffold Callisto configuration in the current workspace.
58 Init(InitArgs),
59 /// Compute which packages are ready to publish and print the publish plan.
60 PlanPublish(PlanPublishArgs),
61 /// Publish ready packages to their ecosystem registries via native CLI tools.
62 Publish(PublishArgs),
63 /// Generate a pull request body summarizing pending release changes.
64 ComposePrBody(ComposePrBodyArgs),
65 /// Create git tags for packages in a publish plan.
66 Tag(TagArgs),
67 /// Generate shell completion scripts.
68 Completions(CompletionsArgs),
69 /// Print the JSON schema for a report type.
70 Schema(SchemaArgs),
71}
72
73/// Arguments for the `schema` command.
74#[derive(Args, Clone, Debug, Default)]
75pub struct SchemaArgs {
76 /// Report type to print the schema for (status, version, snapshot, validate, tag, init, plan-publish, changeset, pre); defaults to status.
77 #[arg(long = "type", value_name = "TYPE")]
78 pub target_type: Option<String>,
79}
80
81/// Arguments for the `add` command.
82#[derive(Args, Clone, Debug)]
83pub struct AddArgs {
84 /// Package and severity to include, as `name:severity` (patch, minor, or major); repeatable. Omit to enter the interactive wizard.
85 #[arg(long = "package", value_name = "NAME:SEVERITY")]
86 pub packages: Vec<String>,
87 /// Human-readable summary of the change to record in the changeset.
88 #[arg(long)]
89 pub summary: Option<String>,
90}
91
92/// Arguments for the `status` command.
93#[derive(Args, Clone, Debug)]
94pub struct StatusArgs {
95 /// Treat warning-level diagnostics as errors.
96 #[arg(long)]
97 pub strict: bool,
98 /// Treat dependency-graph warnings as errors.
99 #[arg(long)]
100 pub strict_graph: bool,
101 /// Exit with a distinct status code indicating whether any changesets are pending.
102 #[arg(long)]
103 pub check: bool,
104}
105
106/// Arguments for the `version` command.
107#[derive(Args, Clone, Debug)]
108pub struct VersionArgs {
109 /// Regenerate lockfiles after applying the version bumps.
110 #[arg(long)]
111 pub refresh_lockfiles: bool,
112 /// Treat warning-level diagnostics as errors.
113 #[arg(long)]
114 pub strict: bool,
115 /// Treat dependency-graph warnings as errors.
116 #[arg(long)]
117 pub strict_graph: bool,
118 /// Allow versioning to proceed even if no changesets are pending.
119 #[arg(long)]
120 pub allow_empty_changesets: bool,
121}
122
123/// Subcommands for managing prerelease mode.
124#[derive(Subcommand, Clone, Debug)]
125pub enum PreArgs {
126 /// Enter prerelease mode, tagging subsequent version bumps with the given prerelease tag.
127 Enter { tag: String },
128 /// Exit prerelease mode, returning to normal versioning.
129 Exit,
130}
131
132/// Arguments for the `validate` command.
133#[derive(Args, Clone, Debug)]
134pub struct ValidateArgs {
135 /// Validate only changesets staged in git.
136 #[arg(long)]
137 pub staged: bool,
138 /// Validate only changesets added since the given git ref.
139 #[arg(long, value_name = "REF", conflicts_with = "staged")]
140 pub since: Option<String>,
141 /// Treat warning-level diagnostics as errors.
142 #[arg(long)]
143 pub strict: bool,
144 /// Treat dependency-graph warnings as errors.
145 #[arg(long)]
146 pub strict_graph: bool,
147}
148
149/// Arguments for the `snapshot` command.
150#[derive(Args, Clone, Debug)]
151pub struct SnapshotArgs {
152 /// Tag to append to the snapshot version (e.g. a commit SHA or branch name).
153 #[arg(long)]
154 pub tag: String,
155 /// Abort if the workspace graph contains crosscheck failures or other
156 /// error-severity diagnostics.
157 #[arg(long)]
158 pub strict: bool,
159}
160
161/// Arguments for the `init` command.
162#[derive(Args, Clone, Debug)]
163pub struct InitArgs {
164 /// Skip the interactive confirmation prompt.
165 #[arg(long)]
166 pub yes: bool,
167}
168
169/// Arguments for the `plan-publish` command (currently none).
170#[derive(Args, Clone, Debug, Default)]
171pub struct PlanPublishArgs {}
172
173/// Arguments for the `publish` command (currently none — use the global
174/// `--dry-run` flag to preview the plan without publishing anything).
175#[derive(Args, Clone, Debug, Default)]
176pub struct PublishArgs {}
177
178/// Arguments for the `compose-pr-body` command.
179#[derive(Args, Clone, Debug)]
180pub struct ComposePrBodyArgs {
181 /// Existing PR body text to merge with, or `-` to read it from stdin.
182 #[arg(long, value_name = "TEXT|-")]
183 pub existing_body: Option<String>,
184 /// Label to attach to the PR body; repeatable.
185 #[arg(long = "label")]
186 pub labels: Vec<String>,
187 /// Branch name to reference in the generated PR body.
188 #[arg(long)]
189 pub branch: Option<String>,
190}
191
192/// Arguments for the `tag` command.
193#[derive(Args, Clone, Debug)]
194pub struct TagArgs {
195 /// Path to a publish plan JSON file, inline JSON, or `-` to read it from stdin.
196 #[arg(long, value_name = "FILE|-")]
197 pub plan: String,
198 /// Also move a floating major-version tag (e.g. `v1`) to point at the new tag.
199 #[arg(long)]
200 pub floating_major: bool,
201 /// Abort if the workspace graph contains crosscheck failures or other
202 /// error-severity diagnostics.
203 #[arg(long)]
204 pub strict: bool,
205}
206
207/// Arguments for the `completions` command.
208#[derive(Args, Clone, Debug)]
209pub struct CompletionsArgs {
210 /// Shell to generate a completion script for.
211 #[arg(value_enum)]
212 pub shell: clap_complete::Shell,
213}