Skip to main content

spec_driven_docs/cli/
self_depend.rs

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