Skip to main content

git_atomic/cli/
mod.rs

1pub mod commands;
2pub mod output;
3
4use clap::{Parser, Subcommand};
5use std::path::PathBuf;
6
7/// Create atomic commits & branches from a single changeset.
8///
9/// Splits a multi-component commit into isolated per-component branches,
10/// each containing only the files that belong to that component.
11/// Run without a subcommand to split HEAD with default settings.
12#[derive(Debug, Parser)]
13#[command(
14    name = "git-atomic",
15    version,
16    about,
17    disable_help_subcommand = true,
18    subcommand_negates_reqs = true
19)]
20pub struct Cli {
21    /// Path to the .atomic.toml configuration file.
22    #[arg(long, default_value = ".atomic.toml", global = true)]
23    pub config: PathBuf,
24
25    /// Increase log verbosity (-v for files, -vv for debug details).
26    #[arg(short, long, action = clap::ArgAction::Count, global = true)]
27    pub verbose: u8,
28
29    /// Suppress all non-error output.
30    #[arg(short, long, global = true)]
31    pub quiet: bool,
32
33    /// Emit machine-readable JSON instead of human-friendly text.
34    #[arg(long, global = true)]
35    pub json: bool,
36
37    /// Show what would happen without performing any mutations.
38    #[arg(long, global = true)]
39    pub dry_run: bool,
40
41    #[command(subcommand)]
42    pub command: Option<Command>,
43}
44
45#[derive(Debug, Subcommand)]
46pub enum Command {
47    /// Split a commit into per-component branches [default when omitted].
48    Commit(CommitArgs),
49
50    /// Show each component's branch state relative to the base branch.
51    Status(StatusArgs),
52
53    /// Check the configuration file for errors (bad globs, missing fields).
54    Validate,
55
56    /// Generate a starter .atomic.toml in the current directory.
57    Init,
58}
59
60#[derive(Debug, Parser)]
61pub struct CommitArgs {
62    /// Git ref or range to split (e.g. HEAD, main..feature).
63    #[arg(default_value = "HEAD")]
64    pub source_ref: String,
65
66    /// Overwrite branches that have diverged from the base branch.
67    #[arg(long)]
68    pub force: bool,
69
70    /// Split and push in one step; exit non-zero on any failure.
71    #[arg(long)]
72    pub ci_mode: bool,
73
74    /// Push component branches to the remote after splitting.
75    #[arg(long)]
76    pub push: bool,
77
78    /// Git remote to push to when --push or --ci-mode is used.
79    #[arg(long, default_value = "origin")]
80    pub remote: String,
81}
82
83#[derive(Debug, Parser)]
84pub struct StatusArgs {
85    /// Git ref whose changed files to inspect.
86    #[arg(long = "ref", default_value = "HEAD")]
87    pub source_ref: String,
88
89    /// Suppress configuration display (show only branch state).
90    #[arg(long)]
91    pub no_config: bool,
92}