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
use anyhow::Result;
use structopt::StructOpt;
use crate::command;
#[derive(StructOpt, Debug)]
#[structopt(name = "beam", about = "Easier connection to teleport hosts")]
pub struct Beam {
#[structopt(
short,
long,
help = "The user which will be used to connect to the host. (default is the current system user)"
)]
pub user: Option<String>,
#[structopt(short, long, help = "The proxy to use")]
pub proxy: Option<String>,
#[structopt(short, long, help = "The auth to use")]
pub auth: Option<String>,
#[structopt(short, long = "clear-cache", help = "Whether to clear the cache")]
pub clear_cache: bool,
#[structopt(subcommand)]
pub cmd: Option<Command>,
}
#[derive(StructOpt, Debug)]
pub enum Command {
Connect(command::connect::Connect),
Config(command::config::Config),
List(command::list::List),
}
#[derive(StructOpt, Debug, PartialEq, Default)]
pub struct LsOpts {
#[structopt(short, long, help = "The format to use for the output")]
format: Option<String>,
}
impl Beam {
pub fn run(&self) -> Result<()> {
self.execute_command()?;
Ok(())
}
pub fn execute_command(&self) -> Result<()> {
match &self.cmd {
Some(Command::Connect(command)) => command.run(self),
Some(Command::Config(command)) => command.run(),
Some(Command::List(command)) => command.run(self),
None => command::default::Default::run(self),
}
}
}