forked from suptejas/volt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.rs
More file actions
73 lines (66 loc) · 2.06 KB
/
cli.rs
File metadata and controls
73 lines (66 loc) · 2.06 KB
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 crate::commands::{
add, clean, clone, discord, info, init, list, login, node, outdated, run, search,
}; // remove outdated later
use async_trait::async_trait;
use clap::{crate_authors, crate_description, crate_name, crate_version, Parser, Subcommand};
use super::VoltConfig;
/// A trait to be implemented by subcommands
#[async_trait]
pub trait VoltCommand {
async fn exec(self, config: VoltConfig) -> miette::Result<()>;
}
/// Volt CLI subcommands
#[derive(Debug, Subcommand)]
pub enum VoltSubCmd {
Add(add::Add),
Clone(clone::Clone),
Init(init::Init),
Clean(clean::Clean),
Discord(discord::Discord),
Search(search::Search),
Login(login::Login),
Run(run::Run),
Info(info::Info),
Node(node::Node),
Outdated(outdated::Outdated), // remove later???
List(list::List), // remove later???
}
#[async_trait]
impl VoltCommand for VoltSubCmd {
async fn exec(self, config: VoltConfig) -> miette::Result<()> {
match self {
Self::Add(x) => x.exec(config).await,
Self::Clone(x) => x.exec(config).await,
Self::Init(x) => x.exec(config).await,
Self::Clean(x) => x.exec(config).await,
Self::Discord(x) => x.exec(config).await,
Self::Search(x) => x.exec(config).await,
Self::Login(x) => x.exec(config).await,
Self::Run(x) => x.exec(config).await,
Self::Info(x) => x.exec(config).await,
Self::Node(x) => x.exec(config).await,
Self::Outdated(x) => x.exec(config).await, // remove later
Self::List(x) => x.exec(config).await, // remove later
}
}
}
#[derive(Debug, Parser)]
#[clap(
name = crate_name!(),
version = crate_version!(),
about = crate_description!(),
author = crate_authors!(),
disable_colored_help = true,
)]
#[allow(clippy::module_name_repetitions)]
pub struct VoltCli {
#[clap(flatten)]
pub config: VoltConfig,
#[clap(subcommand)]
pub cmd: VoltSubCmd,
}
impl VoltCli {
pub fn new() -> Self {
Self::parse()
}
}