-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcmd_open.rs
73 lines (68 loc) · 2.43 KB
/
cmd_open.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use anyhow::Result;
use clap::Parser;
use parse_display::{Display, FromStr};
/// Shortcut to open the Zoo documentation or Account in your browser.
///
/// If no arguments are given, the default is to open the Zoo documentation.
///
/// # open the Zoo docs in your browser
/// $ zoo open docs
///
/// # open your Zoo account in your browser
/// $ zoo open account
#[derive(Parser, Debug, Clone)]
#[clap(verbatim_doc_comment)]
pub struct CmdOpen {
#[clap(name = "shortcut", default_value_t, value_enum)]
shortcut: OpenShortcut,
}
/// The type of shortcut to open.
#[derive(PartialEq, Debug, Clone, FromStr, Display, clap::ValueEnum)]
#[display(style = "kebab-case")]
#[derive(Default)]
pub enum OpenShortcut {
/// Open the Zoo documentation in your browser.
#[default]
Docs,
/// Open the Zoo API reference in your browser.
ApiRef,
/// Open the Zoo CLI reference in your browser.
CliRef,
/// Open your Zoo account in your browser.
Account,
/// Open the Zoo Discord in your browser.
Discord,
/// Open the Zoo store in your browser.
Store,
/// Open the Zoo blog in your browser.
Blog,
/// Open the repository for the `zoo` CLI in your browser.
Repo,
/// Open the changelog for the `zoo` CLI in your browser.
Changelog,
}
impl OpenShortcut {
fn get_url(&self) -> String {
match self {
OpenShortcut::Docs => "https://zoo.dev/docs".to_string(),
OpenShortcut::ApiRef => "https://zoo.dev/docs/api".to_string(),
OpenShortcut::CliRef => "https://zoo.dev/docs/cli".to_string(),
OpenShortcut::Account => "https://zoo.dev/account".to_string(),
OpenShortcut::Discord => "https://discord.com/invite/Bee65eqawJ".to_string(),
OpenShortcut::Store => "https://store.zoo.dev".to_string(),
OpenShortcut::Blog => "https://zoo.dev/blog".to_string(),
OpenShortcut::Repo => "https://github.com/KittyCAD/cli".to_string(),
OpenShortcut::Changelog => changelog_url(clap::crate_version!()),
}
}
}
#[async_trait::async_trait(?Send)]
impl crate::cmd::Command for CmdOpen {
async fn run(&self, ctx: &mut crate::context::Context) -> Result<()> {
ctx.browser("", &self.shortcut.get_url())
}
}
/// Returns the URL to the changelog for the given version.
pub fn changelog_url(version: &str) -> String {
format!("https://github.com/KittyCAD/cli/releases/tag/v{version}")
}