semver-sync 0.2.1

Keep one version across every crate in a cargo workspace; bumps are checked as docker tags before any manifest is written.
//! Argument surface.

use std::path::PathBuf;

use clap::{Args, Parser, Subcommand};

/// Move every crate in a cargo workspace to one version, path pins included.
///
/// These versions become docker tags, so they are checked as tags. Every
/// command that writes takes --dry-run. Run `semver-sync alias` once to get the
/// shorter `ss` spelling, and bare `ss` prints what every crate is at.
#[derive(Parser, Debug)]
#[command(name = "semver-sync", version, about, propagate_version = true)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Option<Verb>,
}

#[derive(Subcommand, Debug)]
pub enum Verb {
    /// Bump the patch number of every crate, dropping any tag first.
    Patch(Bump),
    /// Bump the minor number of every crate, dropping any tag first.
    Minor(Bump),
    /// Bump the major number of every crate, dropping any tag first.
    Major(Bump),
    /// Tag every crate: `1.2.3-rc.0`, then `.1`, `.2` on the same tag.
    Tag(Tag),
    /// Set one exact version on every crate.
    Set(Set),
    /// Update this tool itself, reinstalling it from crates.io with cargo.
    Update,
    /// Print the semver-sync version.
    Version,
    /// Install the `ss` shell alias.
    Alias(Alias),
    /// Print a shell completion script.
    Completions(Completions),
    /// Write a configuration file to fill in.
    Config(Config),
}

/// The one flag every writer shares.
#[derive(Args, Debug)]
pub struct Bump {
    /// Report the result without touching any manifest.
    #[arg(long)]
    pub dry_run: bool,
}

#[derive(Args, Debug)]
pub struct Tag {
    /// Tag name, for example `rc` or `hotfix`.
    #[arg(value_name = "TAG")]
    pub tag: String,

    /// Report the result without touching any manifest.
    #[arg(long)]
    pub dry_run: bool,
}

#[derive(Args, Debug)]
pub struct Set {
    /// Exact version, for example `1.4.0-rc.0`.
    #[arg(id = "set-version", value_name = "VERSION")]
    pub version: String,

    /// Report the result without touching any manifest.
    #[arg(long)]
    pub dry_run: bool,
}

#[derive(Args, Debug)]
pub struct Alias {
    /// Alias to install.
    #[arg(long, default_value = "ss", value_name = "NAME")]
    pub name: String,

    /// Shell rc file to write. Defaults to the one for $SHELL.
    #[arg(long, value_name = "FILE")]
    pub file: Option<PathBuf>,
}

#[derive(Args, Debug)]
pub struct Completions {
    /// Shell to print a completion script for.
    #[arg(value_enum)]
    pub shell: clap_complete::Shell,
}

#[derive(Args, Debug)]
pub struct Config {
    /// Write in the user config dir (`$XDG_CONFIG_HOME`, else `$HOME/.config`)
    /// instead of next to the workspace root.
    #[arg(long)]
    pub global: bool,
}