release_kit/cli/depend.rs
1//! Arguments for `rk depend`.
2
3use camino::Utf8PathBuf;
4use clap::{Args, Subcommand, ValueEnum};
5use serde::Serialize;
6
7/// The target's tool manager: one enum, owned by the self-depend axis,
8/// so `rk depend` and `rk self-depend` read the same list.
9pub use crate::self_depend::manager::Manager;
10
11/// Add another project as a dependency of a target, from how the source distributes itself.
12#[derive(Debug, Args)]
13pub struct DependArgs {
14 /// What to do with the dependency.
15 #[command(subcommand)]
16 pub action: DependAction,
17}
18
19/// The depend operations.
20#[derive(Debug, Subcommand)]
21pub enum DependAction {
22 /// Read the source and the target, offline, and report every way the dependency can land.
23 Assess(AssessArgs),
24 /// Serve the fragment or the native command for one way; seed a manager file only where the target has none.
25 Add(AddArgs),
26}
27
28/// Arguments for `rk depend assess`.
29#[derive(Debug, Args)]
30pub struct AssessArgs {
31 /// The dependency's checkout: a local directory, never a URL.
32 #[arg(long)]
33 pub source: Utf8PathBuf,
34
35 /// The project that takes the dependency.
36 #[arg(long, default_value = ".")]
37 pub target: Utf8PathBuf,
38
39 /// Emit one JSON object on stdout instead of the human report.
40 #[arg(long)]
41 pub json: bool,
42}
43
44/// Arguments for `rk depend add`.
45#[derive(Debug, Args)]
46pub struct AddArgs {
47 /// The dependency's checkout: a local directory, never a URL.
48 #[arg(long)]
49 pub source: Utf8PathBuf,
50
51 /// The project that takes the dependency.
52 #[arg(long, default_value = ".")]
53 pub target: Utf8PathBuf,
54
55 /// dev: a tool on PATH in the development environment; prod: a library the code imports.
56 #[arg(long, value_enum)]
57 pub kind: Kind,
58
59 /// The target's tool manager; required when the target carries several, or none.
60 #[arg(long, value_enum)]
61 pub manager: Option<Manager>,
62
63 /// How the source is fetched; the first viable channel for the manager by default.
64 #[arg(long, value_enum)]
65 pub channel: Option<Channel>,
66
67 /// The version to pin: 1.2.3, v1.2.3, or the release URL; the source tree's declared version by default.
68 #[arg(long)]
69 pub pin: Option<String>,
70
71 /// Write the seed file; without it the fragment or command is 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/// What kind of dependency the target takes.
81#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, ValueEnum)]
82#[serde(rename_all = "kebab-case")]
83#[value(rename_all = "kebab-case")]
84pub enum Kind {
85 /// A tool on PATH in the development environment.
86 Dev,
87 /// A library the code imports, through the technology's own manifest.
88 Prod,
89}
90
91impl Kind {
92 /// The wire form.
93 #[must_use]
94 pub const fn as_str(self) -> &'static str {
95 match self {
96 Self::Dev => "dev",
97 Self::Prod => "prod",
98 }
99 }
100}
101
102/// Where the source is fetched from.
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, ValueEnum)]
104#[serde(rename_all = "kebab-case")]
105#[value(rename_all = "kebab-case")]
106pub enum Channel {
107 /// The crate on crates.io.
108 Crates,
109 /// The flake the source repository serves, at a tag.
110 Flake,
111 /// The project on the Python package index.
112 Pypi,
113 /// The package on the npm registry.
114 Npm,
115 /// The prebuilt archives attached to a GitHub release.
116 GithubRelease,
117}
118
119impl Channel {
120 /// The wire form.
121 #[must_use]
122 pub const fn as_str(self) -> &'static str {
123 match self {
124 Self::Crates => "crates",
125 Self::Flake => "flake",
126 Self::Pypi => "pypi",
127 Self::Npm => "npm",
128 Self::GithubRelease => "github-release",
129 }
130 }
131
132 /// Every channel, in the order the reports list them.
133 pub const ALL: [Self; 5] = [
134 Self::Crates,
135 Self::Flake,
136 Self::Pypi,
137 Self::Npm,
138 Self::GithubRelease,
139 ];
140}