Skip to main content

check_updates_cli/
cli.rs

1use clap::{Parser, ValueEnum, builder::styling};
2
3const STYLES: clap::builder::Styles = styling::Styles::styled()
4    .header(styling::AnsiColor::Yellow.on_default().bold())
5    .usage(styling::AnsiColor::Green.on_default().bold())
6    .literal(styling::AnsiColor::Blue.on_default().bold())
7    .placeholder(styling::AnsiColor::Green.on_default());
8
9#[derive(Parser, Debug)]
10#[command(
11    name = "check-updates",
12    about = "Check for updates in your dependencies",
13    version,
14    styles(STYLES)
15)]
16pub struct Args {
17    #[arg(short, long, help = "Interactive mode")]
18    pub interactive: bool,
19
20    #[arg(long, help = "Root directory to search from", value_name = "DIR")]
21    pub root: Option<std::path::PathBuf>,
22
23    #[arg(long, help = "Enable verbose output")]
24    pub verbose: bool,
25
26    #[arg(long, help = "Exit with a non-zero status when updates are available")]
27    pub fail_on_updates: bool,
28
29    #[arg(
30        long = "cache",
31        value_enum,
32        default_value_t = RegistryCacheMode::Refresh,
33        help = "Cache mode"
34    )]
35    pub cache: RegistryCacheMode,
36
37    #[arg(short = 'u', long, help = "Update version requirements in Cargo.toml")]
38    pub update: bool,
39
40    #[arg(
41        short = 'U',
42        long,
43        help = "Update version requirements in Cargo.toml and run cargo update"
44    )]
45    pub upgrade: bool,
46
47    #[arg(short = 'c', long, help = "Only upgrade to semver-compatible versions")]
48    pub compatible: bool,
49
50    #[arg(long, help = "Compact interactive mode (fewer spacing lines)")]
51    pub compact: bool,
52
53    #[arg(long, help = "Include pre-release/alpha/beta versions")]
54    pub pre: bool,
55
56    #[arg(
57        short,
58        long,
59        help = "Only check specific workspace package(s) (can be specified multiple times)"
60    )]
61    pub package: Vec<String>,
62
63    #[command(subcommand)]
64    pub cmd: Option<Command>,
65}
66
67#[derive(Debug, Clone, Copy, ValueEnum)]
68pub enum RegistryCacheMode {
69    PreferLocal,
70    Refresh,
71    NoCache,
72}
73
74#[derive(Parser, Debug)]
75pub enum Command {
76    #[command(
77        about = "Generate shell completion scripts",
78        long_about = "Generate shell completion scripts for check-updates.\nCan be used like `check-updates generate-completion bash > check-updates.bash`"
79    )]
80    GenerateShellCompletion {
81        #[clap(value_name = "SHELL")]
82        shell: clap_complete::Shell,
83    },
84}