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.
27    Sync(SyncArgs),
28}
29
30/// Arguments for `rk self-depend status`.
31#[derive(Debug, Args)]
32pub struct StatusArgs {
33    /// The project to read.
34    #[arg(long, default_value = ".")]
35    pub target: Utf8PathBuf,
36
37    /// Report one manager's entry alone; every manager by default, absent ones included.
38    #[arg(long, value_enum)]
39    pub manager: Option<Manager>,
40
41    /// Emit one JSON object on stdout instead of the human report.
42    #[arg(long)]
43    pub json: bool,
44}
45
46/// Arguments for `rk self-depend add`.
47#[derive(Debug, Args)]
48pub struct AddArgs {
49    /// The project to wire.
50    #[arg(long, default_value = ".")]
51    pub target: Utf8PathBuf,
52
53    /// The release tag to pin: v0.2.16, 0.2.16, or the release URL; this binary's version by default.
54    #[arg(long)]
55    pub tag: Option<String>,
56
57    /// Record that every host installs rk itself, at this release or newer, instead of pinning it in a manager file.
58    #[arg(long, conflicts_with_all = ["tag", "manager", "venue"])]
59    pub host: bool,
60
61    /// The target's tool manager; required when the target carries several, the flake when it carries none.
62    #[arg(long, value_enum)]
63    pub manager: Option<Manager>,
64
65    /// Where rk is fetched from; the first venue the manager renders a fragment for by default.
66    #[arg(long, value_enum)]
67    pub venue: Option<Venue>,
68
69    /// Write the seed files; without it the fragments are printed and nothing is written.
70    #[arg(long)]
71    pub apply: bool,
72
73    /// Emit one JSON object on stdout instead of the human report.
74    #[arg(long)]
75    pub json: bool,
76}
77
78/// Arguments for `rk self-depend clean`.
79#[derive(Debug, Args)]
80pub struct CleanArgs {
81    /// The project to clean.
82    #[arg(long, default_value = ".")]
83    pub target: Utf8PathBuf,
84
85    /// One extra file to remove, for a predecessor the catalog does not know; repeatable.
86    #[arg(long, value_name = "PATH")]
87    pub also: Vec<Utf8PathBuf>,
88
89    /// Remove the files and rewrite .envrc; without it every leftover is listed.
90    #[arg(long)]
91    pub apply: bool,
92
93    /// Emit one JSON object on stdout instead of the human report.
94    #[arg(long)]
95    pub json: bool,
96}
97
98/// Arguments for `rk self-depend sync`.
99#[derive(Debug, Args)]
100pub struct SyncArgs {
101    /// The project to sync.
102    #[arg(long, default_value = ".")]
103    pub target: Utf8PathBuf,
104
105    /// The release tag to pin, in either direction, making no network request; the latest release by default, forward only.
106    #[arg(long)]
107    pub tag: Option<String>,
108
109    /// The manager whose pin moves; the one manager naming release-kit by default.
110    #[arg(long, value_enum)]
111    pub manager: Option<Manager>,
112
113    /// Who is calling: envrc stays silent and exits 0 on every outcome, operator reports and fails loudly.
114    #[arg(long, value_enum, default_value_t = Caller::Envrc)]
115    pub caller: Caller,
116
117    /// Rewrite the pin, refresh the lock, and build; without it the bump is reported and nothing runs.
118    #[arg(long)]
119    pub apply: bool,
120
121    /// Emit one JSON object on stdout instead of the human report.
122    #[arg(long)]
123    pub json: bool,
124}
125
126/// Who invoked the sync. One flag decides four behaviors as a bundle: the
127/// daily stamp, silence on nothing to do, the exit code of a reported
128/// failure, and silence under lock contention.
129#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
130#[value(rename_all = "kebab-case")]
131pub enum Caller {
132    /// The `.envrc` line on directory entry: gated by the stamp, silent, exit 0.
133    Envrc,
134    /// A person or an agent at a prompt: every outcome reported, the exit-code matrix.
135    Operator,
136}