1use std::path::PathBuf;
4
5use clap::{Args, Parser, Subcommand, ValueEnum};
6use url::Url;
7use vgi_forge::DEFAULT_REQUIRED_CHECK;
8
9#[derive(Debug, Parser)]
11#[command(name = "vgi", version, about, long_about = None)]
12pub struct Cli {
13 #[command(subcommand)]
15 pub command: Command,
16}
17
18#[derive(Debug, Subcommand)]
20pub enum Command {
21 #[command(subcommand)]
23 Repo(RepoCommand),
24}
25
26#[derive(Debug, Subcommand)]
28pub enum RepoCommand {
29 Init(InitArgs),
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
36pub enum TransportChoice {
37 Auto,
39 Tsp,
41 Didcomm,
43 Https,
45}
46
47impl From<TransportChoice> for vgi_forge::VerifyTransport {
48 fn from(c: TransportChoice) -> Self {
49 match c {
50 TransportChoice::Auto => vgi_forge::VerifyTransport::Auto,
51 TransportChoice::Tsp => vgi_forge::VerifyTransport::Tsp,
52 TransportChoice::Didcomm => vgi_forge::VerifyTransport::Didcomm,
53 TransportChoice::Https => vgi_forge::VerifyTransport::Https,
54 }
55 }
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
59pub enum ForgeChoice {
60 Auto,
63 Github,
65 Forgejo,
67}
68
69const INIT_ABOUT: &str = "\
70Turn VGI commit trust on for a repository in a manual or personal-account git \
71namespace: the same bootstrap the community's bridge runs, done as you.
72
73On GitHub it acts through your own `gh` login (`gh auth login`; you need admin \
74on the repository). It commits `.github/workflows/verify-trust.yml` with the \
75registry and VTC DIDs written in as literals, and the exempt web-flow keyring; \
76removes stale TRUST_REGISTRY_DID / VTC_DID repository variables; and converges \
77the \"VGI commit trust\" ruleset on the default branch: pull request required, \
78\"Verify commit trust\" required and pinned to GitHub Actions, no force-push, no \
79deletion, no bypass actors. The owners are the person running this (on a \
80personal repository, the account holder) plus each --code-owner, counted once \
81each. With two or more owners it also writes a managed `.github/CODEOWNERS` \
82block and the ruleset requires a code owner's review, so no pull request can \
83change the check it is judged by without another owner's approval. With one \
84owner, only the check is required. On an organisation repository that is \
85refused unless you pass --solo: anyone else in the organisation with write \
86access could edit the workflow in the very pull request it judges.
87
88These are per-repository guards. They are not the organisation's required \
89workflow, which only the community's bridge sets.
90
91On Forgejo it acts with FORGEJO_TOKEN (a token of yours with write:repository \
92and read:user), sent only to the repository's own host and only after \
93GET /api/v1/version, asked without it, answers as Forgejo or Gitea. It \
94allows fast-forward-only merges, commits \
95`.forgejo/workflows/verify-trust.yml` with the DIDs written in, and \
96converges the default branch's protection: no pushes, the check's status \
97context required, the workflow directories protected, applying to admins.
98
99Every step is check-then-apply: a re-run changes nothing, and --dry-run \
100prints each change (with the file or request body) without making it.
101
102It does not tell the VTC the repository exists. That is `git-ns/repo/adopt`, \
103a Trust Task signed with a VTA session, which this tool does not hold; it \
104prints the `cnm git adopt` command to run instead.";
105
106#[derive(Debug, Args)]
108#[command(long_about = INIT_ABOUT)]
109pub struct InitArgs {
110 #[arg(long, value_name = "DID")]
112 pub vtc: String,
113
114 #[arg(long, value_name = "HOST/OWNER/REPO")]
117 pub resource: Option<String>,
118
119 #[arg(long, value_name = "DID")]
122 pub registry: Option<String>,
123
124 #[arg(long = "owner", value_name = "DID")]
127 pub owners: Vec<String>,
128
129 #[arg(long, value_enum, default_value_t = ForgeChoice::Auto)]
131 pub forge: ForgeChoice,
132
133 #[arg(long = "code-owner", value_name = "LOGIN")]
138 pub code_owners: Vec<String>,
139
140 #[arg(long, conflicts_with = "code_owners")]
146 pub solo: bool,
147
148 #[arg(long, value_name = "FILE")]
151 pub platform_keyring: Option<PathBuf>,
152
153 #[arg(long, value_name = "REF")]
157 pub verify_trust_action: Option<String>,
158
159 #[arg(long, value_name = "TAG", default_value = concat!("v", env!("CARGO_PKG_VERSION")))]
161 pub verify_trust_version: String,
162
163 #[arg(long, value_name = "HEX")]
167 pub verify_trust_sha256: Option<String>,
168
169 #[arg(long, value_enum, value_name = "BINDING", default_value_t = TransportChoice::Auto)]
174 pub verify_trust_transport: TransportChoice,
175
176 #[arg(long, value_name = "NAME", default_value = DEFAULT_REQUIRED_CHECK)]
178 pub required_check: String,
179
180 #[arg(long, value_name = "URL")]
182 pub forgejo_url: Option<Url>,
183
184 #[arg(long, value_name = "LABEL", default_value = vgi_forge_forgejo::DEFAULT_RUNS_ON)]
186 pub runs_on: String,
187
188 #[arg(long)]
190 pub dry_run: bool,
191}