-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopts.rs
More file actions
112 lines (92 loc) · 3.16 KB
/
opts.rs
File metadata and controls
112 lines (92 loc) · 3.16 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use crate::data::renku_url::RenkuUrl;
use super::cmd::*;
use clap::{Parser, ValueEnum, ValueHint};
use clap_verbosity_flag::{Verbosity, WarnLevel};
use serde::{Deserialize, Serialize};
use std::str::FromStr;
/// Main options are available to all commands. They must appear
/// before a sub-command.
#[derive(Parser, Debug, Clone)]
#[command()]
pub struct CommonOpts {
/// Be more verbose when logging. Verbosity increases with each
/// occurence of that option.
#[command(flatten)]
pub verbosity: Verbosity<WarnLevel>,
/// How to format the output. The default is human readable which
/// may choose to not show every detail for better readability.
/// The json output format can be used to always show all details
/// in a structured form.
#[arg(short, long, value_enum, default_value_t = Format::Default)]
pub format: Format,
/// The (base) URL to Renku. It can be given as environment
/// variable RENKU_CLI_RENKU_URL.
#[arg(long, value_hint = ValueHint::Url)]
pub renku_url: Option<RenkuUrl>,
/// Set a proxy to use for doing http requests. By default, the
/// system proxy will be used. Can be either `none` or <url>. If
/// `none`, the system proxy will be ignored; otherwise specify
/// the proxy url, like `http://myproxy.com`.
#[arg(long)]
pub proxy: Option<ProxySetting>,
/// The user to authenticate at the proxy.
#[arg(long)]
pub proxy_user: Option<String>,
/// The password to authenticate at the proxy.
#[arg(long)]
pub proxy_password: Option<String>,
}
#[derive(Parser, Debug)]
pub enum SubCommand {
#[command()]
Version(version::Input),
#[command()]
ShellCompletion(shell_completion::Input),
#[command()]
Project(project::Input),
/// Clone a project. (Shortcut for 'project clone')
#[command()]
Clone(project::clone::Input),
#[command()]
Login(login::Input),
#[cfg(feature = "user-doc")]
UserDoc(userdoc::Input),
}
/// This is the command line interface to the Renku platform. Main
/// options are available to all sub-commands and must appear before
/// them. Each sub command has its own set of flags/options and
/// arguments.
///
/// Repository: <https://github.com/SwissDataScienceCenter/renku-cli>
/// Issue tracker: <https://github.com/SwissDataScienceCenter/renku-cli/issues>
#[derive(Parser, Debug)]
#[command(name = "rnk", version)]
pub struct MainOpts {
#[clap(flatten)]
pub common_opts: CommonOpts,
#[clap(subcommand)]
pub subcmd: SubCommand,
}
/// The format for presenting the results.
#[derive(ValueEnum, Debug, Copy, Clone, Serialize, Deserialize, PartialEq)]
pub enum Format {
Json,
Default,
}
#[derive(Parser, Debug, Clone, Serialize, Deserialize)]
pub enum ProxySetting {
/// Don't use any proxy; this will also discard the system proxy.
None,
/// Use a custom defined proxy.
Custom { url: String },
}
impl FromStr for ProxySetting {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.eq_ignore_ascii_case("none") {
Ok(ProxySetting::None)
} else {
Ok(ProxySetting::Custom { url: s.to_string() })
}
}
}