Skip to main content

release_kit/cli/
self_depend.rs

1//! Arguments for `rk self-depend`.
2
3use camino::Utf8PathBuf;
4use clap::{Args, Subcommand, ValueEnum};
5
6use crate::self_depend::manager::Manager;
7use crate::self_depend::venue::Venue;
8
9/// Wire release-kit as a consumer's dependency and keep its pin fresh.
10#[derive(Debug, Args)]
11pub struct SelfDependArgs {
12    /// What to do with the pin wiring.
13    #[command(subcommand)]
14    pub action: SelfDependAction,
15}
16
17/// The self-depend operations.
18#[derive(Debug, Subcommand)]
19pub enum SelfDependAction {
20    /// Report what a target carries, offline: each manager's pin, the .envrc line, and any leftover.
21    Status(StatusArgs),
22    /// Serve the fragments for one manager and venue pair and the .envrc line; seed the manager file where the target has none.
23    Add(AddArgs),
24    /// Remove what a predecessor bump mechanism left, and name what a line scan must not touch.
25    Clean(CleanArgs),
26    /// Move the pin to the latest release through the wired manager; the flake pair locks and builds, both files or neither. The operator's act, refused inside an .envrc evaluation.
27    Sync(SyncArgs),
28    /// Warn where a newer release is out, from a cache read weekly; the .envrc line runs it on every directory entry. Writes nothing but its cache, and exits 0.
29    Check(CheckArgs),
30}
31
32/// Arguments for `rk self-depend status`.
33#[derive(Debug, Args)]
34pub struct StatusArgs {
35    /// The project to read.
36    #[arg(long, default_value = ".")]
37    pub target: Utf8PathBuf,
38
39    /// Report one manager's entry alone; every manager by default, absent ones included.
40    #[arg(long, value_enum)]
41    pub manager: Option<Manager>,
42
43    /// Emit one JSON object on stdout instead of the human report.
44    #[arg(long)]
45    pub json: bool,
46}
47
48/// Arguments for `rk self-depend add`.
49#[derive(Debug, Args)]
50pub struct AddArgs {
51    /// The project to wire.
52    #[arg(long, default_value = ".")]
53    pub target: Utf8PathBuf,
54
55    /// The release tag to pin: v0.2.16, 0.2.16, or the release URL; this binary's version by default.
56    #[arg(long)]
57    pub tag: Option<String>,
58
59    /// Record that every host installs rk itself, at this release or newer, instead of pinning it in a manager file.
60    #[arg(long, conflicts_with_all = ["tag", "manager", "venue"])]
61    pub host: bool,
62
63    /// The target's tool manager; required when the target carries several, the flake when it carries none.
64    #[arg(long, value_enum)]
65    pub manager: Option<Manager>,
66
67    /// Where rk is fetched from; the first venue the manager renders a fragment for by default.
68    #[arg(long, value_enum)]
69    pub venue: Option<Venue>,
70
71    /// Write the seed files; without it the fragments are printed and nothing is written.
72    #[arg(long)]
73    pub apply: bool,
74
75    /// Emit one JSON object on stdout instead of the human report.
76    #[arg(long)]
77    pub json: bool,
78}
79
80/// Arguments for `rk self-depend clean`.
81#[derive(Debug, Args)]
82pub struct CleanArgs {
83    /// The project to clean.
84    #[arg(long, default_value = ".")]
85    pub target: Utf8PathBuf,
86
87    /// One extra file to remove, for a predecessor the catalog does not know; repeatable.
88    #[arg(long, value_name = "PATH")]
89    pub also: Vec<Utf8PathBuf>,
90
91    /// Remove the files and rewrite .envrc; without it every leftover is listed.
92    #[arg(long)]
93    pub apply: bool,
94
95    /// Emit one JSON object on stdout instead of the human report.
96    #[arg(long)]
97    pub json: bool,
98}
99
100/// Arguments for `rk self-depend sync`.
101#[derive(Debug, Args)]
102pub struct SyncArgs {
103    /// The project to sync.
104    #[arg(long, default_value = ".")]
105    pub target: Utf8PathBuf,
106
107    /// The release tag to pin, in either direction, making no network request; the latest release by default, forward only.
108    #[arg(long)]
109    pub tag: Option<String>,
110
111    /// The manager whose pin moves; the one manager naming release-kit by default.
112    #[arg(long, value_enum)]
113    pub manager: Option<Manager>,
114
115    /// Who is calling: the operator, the only caller a sync serves; envrc is retired, and `rk self-depend check` serves directory entry.
116    #[arg(long, value_enum, default_value_t = Caller::Operator)]
117    pub caller: Caller,
118
119    /// Rewrite the pin, refresh the lock, and build; without it the bump is reported and nothing runs.
120    #[arg(long)]
121    pub apply: bool,
122
123    /// Emit one JSON object on stdout instead of the human report.
124    #[arg(long)]
125    pub json: bool,
126}
127
128/// Who invoked the sync. A sync moves the pin only as the operator's act,
129/// so `envrc` stays a value only to be refused by name.
130#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
131#[value(rename_all = "kebab-case")]
132pub enum Caller {
133    /// Retired: the `.envrc` line runs `rk self-depend check`, which never moves a pin.
134    Envrc,
135    /// A person or an agent at a prompt: every outcome reported, the exit-code matrix.
136    Operator,
137}
138
139/// Arguments for `rk self-depend check`.
140#[derive(Debug, Args)]
141pub struct CheckArgs {
142    /// The project whose pin is checked.
143    #[arg(long, default_value = ".")]
144    pub target: Utf8PathBuf,
145
146    /// Emit one JSON object on stdout instead of the human report.
147    #[arg(long)]
148    pub json: bool,
149}