radicle_cli/commands/
help.rs1use std::ffi::OsString;
2
3use crate::terminal as term;
4use crate::terminal::args::{Args, Error, Help};
5
6use super::*;
7
8pub const HELP: Help = Help {
9 name: "help",
10 description: "CLI help",
11 version: env!("RADICLE_VERSION"),
12 usage: "Usage: rad help [--help]",
13};
14
15const COMMANDS: &[Help] = &[
16 rad_auth::HELP,
17 rad_block::HELP,
18 rad_checkout::HELP,
19 rad_clone::HELP,
20 rad_config::HELP,
21 rad_fork::HELP,
22 rad_help::HELP,
23 rad_id::HELP,
24 rad_init::HELP,
25 rad_inbox::HELP,
26 rad_inspect::HELP,
27 rad_issue::HELP,
28 rad_ls::HELP,
29 rad_node::HELP,
30 rad_patch::HELP,
31 rad_path::HELP,
32 rad_clean::HELP,
33 rad_self::HELP,
34 rad_seed::HELP,
35 rad_follow::HELP,
36 rad_unblock::HELP,
37 rad_unfollow::HELP,
38 rad_unseed::HELP,
39 rad_remote::HELP,
40 rad_stats::HELP,
41 rad_sync::HELP,
42];
43
44#[derive(Default)]
45pub struct Options {}
46
47impl Args for Options {
48 fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
49 let mut parser = lexopt::Parser::from_args(args);
50
51 if let Some(arg) = parser.next()? {
52 return Err(anyhow::anyhow!(arg.unexpected()));
53 }
54 Err(Error::HelpManual { name: "rad" }.into())
55 }
56}
57
58pub fn run(_options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
59 term::print("Usage: rad <command> [--help]");
60
61 if let Err(e) = ctx.profile() {
62 term::blank();
63 match e.downcast_ref() {
64 Some(term::args::Error::WithHint { err, hint }) => {
65 term::print(term::format::yellow(err));
66 term::print(term::format::yellow(hint));
67 }
68 Some(e) => {
69 term::error(e);
70 }
71 None => {
72 term::error(e);
73 }
74 }
75 term::blank();
76 }
77
78 term::print("Common `rad` commands used in various situations:");
79 term::blank();
80
81 for help in COMMANDS {
82 term::info!(
83 "\t{} {}",
84 term::format::bold(format!("{:-12}", help.name)),
85 term::format::dim(help.description)
86 );
87 }
88 term::blank();
89 term::print("See `rad <command> --help` to learn about a specific command.");
90 term::blank();
91
92 term::print("Do you have feedback?");
93 term::print(
94 " - Chat <\x1b]8;;https://radicle.zulipchat.com\x1b\\radicle.zulipchat.com\x1b]8;;\x1b\\>",
95 );
96 term::print(
97 " - Mail <\x1b]8;;mailto:feedback@radicle.xyz\x1b\\feedback@radicle.xyz\x1b]8;;\x1b\\>",
98 );
99 term::print(" (Messages are automatically posted to the public #feedback channel on Zulip.)");
100
101 Ok(())
102}