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 and keep its pin fresh.
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    /// Move the pin to the latest release through the wired manager; the flake pair moves both files or neither.
27    Sync(SyncArgs),
28    /// Remove what a predecessor bump mechanism left, and name what a line scan must not touch.
29    Clean(CleanArgs),
30}
31
32/// Report what a target carries.
33#[derive(Debug, clap::Args)]
34pub struct StatusArgs {
35    /// The project to read; absolute, or the working directory.
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    /// Print one JSON object instead of text.
44    #[arg(long)]
45    pub json: bool,
46}
47
48/// Serve the fragments for one pair.
49#[derive(Debug, clap::Args)]
50pub struct AddArgs {
51    /// The project to wire; absolute, or the working directory.
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    /// The target's tool manager; required when the target carries several, the flake when it carries none.
60    #[arg(long, value_enum)]
61    pub manager: Option<Manager>,
62
63    /// Where this tool is fetched from; the first venue the manager renders a fragment for by default.
64    #[arg(long, value_enum)]
65    pub venue: Option<Venue>,
66
67    /// Write the seed files; without it the fragments are printed and nothing is written.
68    #[arg(long)]
69    pub apply: bool,
70
71    /// Print one JSON object instead of text.
72    #[arg(long)]
73    pub json: bool,
74}
75
76/// Who is calling the sync.
77#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
78pub enum Caller {
79    /// The shell-entry line on directory entry: gated by the stamp, silent, exit 0.
80    Envrc,
81    /// A person or an agent at a prompt: every outcome reported, the exit-code matrix.
82    Operator,
83}
84
85/// Move the pin.
86#[derive(Debug, clap::Args)]
87pub struct SyncArgs {
88    /// The project to sync; absolute, or the working directory.
89    #[arg(long, default_value = ".")]
90    pub target: Utf8PathBuf,
91
92    /// The release tag to pin, in either direction, making no network request; the latest release by default.
93    #[arg(long)]
94    pub tag: Option<String>,
95
96    /// The manager whose pin moves; the one manager naming this tool by default.
97    #[arg(long, value_enum)]
98    pub manager: Option<Manager>,
99
100    /// Who is calling: envrc stays silent and exits 0 on every outcome, operator reports and fails loudly.
101    #[arg(long, value_enum, default_value_t = Caller::Envrc)]
102    pub caller: Caller,
103
104    /// Rewrite the pin and refresh the lock; without it the bump is reported and nothing runs.
105    #[arg(long)]
106    pub apply: bool,
107
108    /// Print one JSON object instead of text.
109    #[arg(long)]
110    pub json: bool,
111}
112
113/// Remove what a predecessor left.
114#[derive(Debug, clap::Args)]
115pub struct CleanArgs {
116    /// The project to clean; absolute, or the working directory.
117    #[arg(long, default_value = ".")]
118    pub target: Utf8PathBuf,
119
120    /// One extra file to remove, relative to the target, for a predecessor the catalog does not know; repeatable.
121    #[arg(long)]
122    pub also: Vec<Utf8PathBuf>,
123
124    /// Remove the files; without it every leftover is listed.
125    #[arg(long)]
126    pub apply: bool,
127
128    /// Print one JSON object instead of text.
129    #[arg(long)]
130    pub json: bool,
131}