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
use std::path::PathBuf;
use anyhow::Result;
use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::Shell;
use crate::config::ConfigFileFormat;
use crate::status::OutputFormat;
#[derive(Parser)]
#[command(name = "ferrflow")]
#[command(about = "Universal semantic versioning for monorepos and classic repos")]
#[command(version)]
pub struct Cli {
/// Dry run — show what would happen without making changes
#[arg(long, global = true)]
pub dry_run: bool,
/// Verbose output
#[arg(short, long, global = true)]
pub verbose: bool,
/// Path to config file (overrides auto-detection, env: FERRFLOW_CONFIG)
#[arg(long, global = true, env = "FERRFLOW_CONFIG")]
pub config: Option<PathBuf>,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// Show what versions would be bumped (dry run)
Check {
/// Output as JSON
#[arg(long)]
json: bool,
},
/// Bump versions, update changelogs, create tags and push
Release {
/// Allow floating tags to move backward to a lower version
#[arg(long)]
force: bool,
},
/// Generate/update CHANGELOG.md only
Changelog,
/// Scaffold a ferrflow configuration file
Init {
/// Config file format (json, json5, toml)
#[arg(long)]
format: Option<ConfigFileFormat>,
},
/// Print each package name, current version, and last release tag
Status {
/// Output format
#[arg(long, value_enum, default_value = "text")]
output: OutputFormat,
},
/// Print the current version of a package
Version {
/// Package name (required in monorepos, optional in single repos)
package: Option<String>,
/// Output as JSON
#[arg(long)]
json: bool,
},
/// Print the last release tag of a package
Tag {
/// Package name (required in monorepos, optional in single repos)
package: Option<String>,
/// Output as JSON
#[arg(long)]
json: bool,
},
/// Generate shell completion scripts
Completions {
/// Shell to generate completions for
shell: Shell,
},
}
impl Cli {
pub fn run(self) -> Result<()> {
match self.command {
Commands::Check { json } => {
crate::monorepo::check(self.config.as_deref(), self.verbose, json)
}
Commands::Release { force } => {
crate::monorepo::release(self.config.as_deref(), self.dry_run, self.verbose, force)
}
Commands::Changelog => {
crate::changelog::generate_only(self.config.as_deref(), self.dry_run)
}
Commands::Init { format } => crate::config::init(format),
Commands::Status { output } => crate::status::run(self.config.as_deref(), &output),
Commands::Version { package, json } => {
crate::query::version(self.config.as_deref(), package.as_deref(), json)
}
Commands::Tag { package, json } => {
crate::query::tag(self.config.as_deref(), package.as_deref(), json)
}
Commands::Completions { shell } => {
clap_complete::generate(
shell,
&mut Cli::command(),
"ferrflow",
&mut std::io::stdout(),
);
Ok(())
}
}
}
}