Skip to main content

didbot/
verbs.rs

1//! The verbs `didbot` knows by name.
2
3use didbot_cli::FirstPartyVerb;
4
5/// Every first-party verb, and the binary that answers it.
6///
7/// `didbot-operator` takes the verb as its own subcommand; `didbot-oauth`
8/// and `didbot-register` are one verb each, so the verb is dropped and the
9/// rest is passed as typed.
10pub const FIRST_PARTY: &[FirstPartyVerb] = &[
11    FirstPartyVerb {
12        verb: "operate",
13        binary: "didbot-operator",
14        package: "didbot-operator",
15        argv: &["operate"],
16        about: "claim a server, admit an account beneath you, or check either",
17    },
18    FirstPartyVerb {
19        verb: "login",
20        binary: "didbot-operator",
21        package: "didbot-operator",
22        argv: &["login"],
23        about: "sign in as a deployment's operator",
24    },
25    FirstPartyVerb {
26        verb: "estop",
27        binary: "didbot-operator",
28        package: "didbot-operator",
29        argv: &["estop"],
30        about: "read or set a deployment's emergency stop",
31    },
32    FirstPartyVerb {
33        verb: "account",
34        binary: "didbot-operator",
35        package: "didbot-operator",
36        argv: &["account"],
37        about: "read or act on the accounts a deployment hosts",
38    },
39    FirstPartyVerb {
40        verb: "app",
41        binary: "didbot-operator",
42        package: "didbot-operator",
43        argv: &["app"],
44        about: "read what OAuth applications hold and did, or end their logins",
45    },
46    FirstPartyVerb {
47        verb: "announce",
48        binary: "didbot-operator",
49        package: "didbot-operator",
50        argv: &["announce"],
51        about: "ask the relay to crawl a deployment",
52    },
53    FirstPartyVerb {
54        verb: "oauth",
55        binary: "didbot-oauth",
56        package: "didbot-agentd",
57        argv: &[],
58        about: "answer sign-ins as an agent: pending, show, approve, decline",
59    },
60    FirstPartyVerb {
61        verb: "register",
62        binary: "didbot-register",
63        package: "didbot-agentd",
64        argv: &[],
65        about: "make this machine an account, with a key that never leaves it",
66    },
67];
68
69/// The verb table as `--help` shows it.
70pub fn help_table() -> String {
71    let width = FIRST_PARTY
72        .iter()
73        .map(|row| row.verb.len())
74        .max()
75        .unwrap_or(0);
76    let mut out = String::from("Verbs:\n");
77    for row in FIRST_PARTY {
78        out.push_str(&format!(
79            "  {:<width$}  {} [{}]\n",
80            row.verb, row.about, row.binary
81        ));
82    }
83    out.push_str(
84        "  <other>   didbot-<other> from PATH, with the rest of the command line\n\
85         \n\
86         `didbot help <verb>` is `didbot <verb> --help`.",
87    );
88    out
89}