Skip to main content

radicle_cli/commands/inspect/
args.rs

1use clap::Parser;
2
3const ABOUT: &str = "Inspect a Radicle repository";
4const LONG_ABOUT: &str = r#"Inspects the given path or RID. If neither is specified,
5the current repository is inspected.
6"#;
7
8#[derive(Debug, Parser)]
9#[group(multiple = false)]
10pub(super) struct TargetArgs {
11    /// Inspect the repository's delegates
12    #[arg(long)]
13    pub(super) delegates: bool,
14
15    /// Show the history of the repository identity document
16    #[arg(long)]
17    pub(super) history: bool,
18
19    /// Inspect the identity document
20    #[arg(long)]
21    pub(super) identity: bool,
22
23    /// Inspect the repository's identity payload
24    #[arg(long)]
25    pub(super) payload: bool,
26
27    /// Inspect the repository's seeding policy
28    #[arg(long)]
29    pub(super) policy: bool,
30
31    /// Inspect the repository's refs on the local device
32    #[arg(long)]
33    pub(super) refs: bool,
34
35    /// Return the repository identifier (RID)
36    #[arg(long)]
37    pub(super) rid: bool,
38
39    /// Inspect the values of `rad/sigrefs` for all remotes of this repository
40    #[arg(long)]
41    pub(super) sigrefs: bool,
42
43    /// Inspect the repository's visibility
44    #[arg(long)]
45    pub(super) visibility: bool,
46}
47
48pub(super) enum Target {
49    Delegates,
50    History,
51    Identity,
52    Payload,
53    Policy,
54    Refs,
55    RepoId,
56    Sigrefs,
57    Visibility,
58}
59
60impl From<TargetArgs> for Target {
61    fn from(args: TargetArgs) -> Self {
62        match (
63            args.delegates,
64            args.history,
65            args.identity,
66            args.payload,
67            args.policy,
68            args.refs,
69            args.rid,
70            args.sigrefs,
71            args.visibility,
72        ) {
73            (true, false, false, false, false, false, false, false, false) => Target::Delegates,
74            (false, true, false, false, false, false, false, false, false) => Target::History,
75            (false, false, true, false, false, false, false, false, false) => Target::Identity,
76            (false, false, false, true, false, false, false, false, false) => Target::Payload,
77            (false, false, false, false, true, false, false, false, false) => Target::Policy,
78            (false, false, false, false, false, true, false, false, false) => Target::Refs,
79            (false, false, false, false, false, false, true, false, false)
80            | (false, false, false, false, false, false, false, false, false) => Target::RepoId,
81            (false, false, false, false, false, false, false, true, false) => Target::Sigrefs,
82            (false, false, false, false, false, false, false, false, true) => Target::Visibility,
83            _ => unreachable!(),
84        }
85    }
86}
87
88#[derive(Debug, Parser)]
89#[command(about = ABOUT, long_about = LONG_ABOUT, disable_version_flag = true)]
90pub struct Args {
91    /// Repository, by RID or by path
92    #[arg(value_name = "RID|PATH")]
93    pub(super) repo: Option<String>,
94
95    #[clap(flatten)]
96    pub(super) target: TargetArgs,
97}