Skip to content

Commit 6df892b

Browse files
committed
cli: move global options to opts module
1 parent 871da9e commit 6df892b

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

nix/cli/packages/cli/src/cli/opts.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::subs::SubCommands;
2-
use clap::Parser;
2+
use crate::types::BitteProvider;
3+
use clap::{ArgSettings, Parser};
4+
use uuid::Uuid;
35

46
#[derive(Parser)]
57
#[clap(author, version, about)]
@@ -10,3 +12,47 @@ pub struct Bitte {
1012
#[clap(subcommand)]
1113
commands: SubCommands,
1214
}
15+
16+
#[derive(Parser, Default)]
17+
pub struct Globals {
18+
#[clap(arg_enum, long, env = "BITTE_PROVIDER", ignore_case = true, value_parser = clap::value_parser!(BitteProvider))]
19+
/// The cluster infrastructure provider
20+
provider: BitteProvider,
21+
#[clap(long, env = "BITTE_DOMAIN", value_name = "NAME")]
22+
/// The public domain of the cluster
23+
domain: String,
24+
#[clap(long = "cluster", env = "BITTE_CLUSTER", value_name = "TITLE")]
25+
/// The unique name of the cluster
26+
name: String,
27+
#[clap(
28+
long,
29+
env = "AWS_DEFAULT_REGION",
30+
value_name = "REGION",
31+
required_if_eq("provider", "AWS")
32+
)]
33+
/// The default AWS region
34+
aws_region: Option<String>,
35+
#[clap(
36+
long,
37+
env = "AWS_ASG_REGIONS",
38+
value_name = "REGIONS",
39+
required_if_eq("provider", "AWS"),
40+
value_delimiter(':'),
41+
require_delimiter = true
42+
)]
43+
/// Regions containing Nomad clients
44+
aws_asg_regions: Option<Vec<String>>,
45+
}
46+
47+
#[derive(Parser, Default)]
48+
pub struct Nomad {
49+
#[clap(
50+
long,
51+
value_name = "TOKEN",
52+
env = "NOMAD_TOKEN",
53+
value_parser = clap::value_parser!(Uuid),
54+
setting = ArgSettings::HideEnvValues
55+
)]
56+
/// The Nomad token used to query node information
57+
nomad: Option<Uuid>,
58+
}

nix/cli/packages/cli/src/cli/subs.rs

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use crate::types::BitteProvider;
2-
use clap::{ArgSettings, Parser};
1+
use crate::cli::opts::{Globals, Nomad};
2+
use clap::Parser;
33
use clap_complete::Shell;
44
use deploy::data as deployData;
55
use deploy::settings as deploySettings;
6-
use uuid::Uuid;
76

87
#[derive(Parser)]
98
pub enum SubCommands {
@@ -57,50 +56,6 @@ pub struct Completions {
5756
shell: Shell,
5857
}
5958

60-
#[derive(Parser, Default)]
61-
struct Globals {
62-
#[clap(arg_enum, long, env = "BITTE_PROVIDER", ignore_case = true, value_parser = clap::value_parser!(BitteProvider))]
63-
/// The cluster infrastructure provider
64-
provider: BitteProvider,
65-
#[clap(long, env = "BITTE_DOMAIN", value_name = "NAME")]
66-
/// The public domain of the cluster
67-
domain: String,
68-
#[clap(long = "cluster", env = "BITTE_CLUSTER", value_name = "TITLE")]
69-
/// The unique name of the cluster
70-
name: String,
71-
#[clap(
72-
long,
73-
env = "AWS_DEFAULT_REGION",
74-
value_name = "REGION",
75-
required_if_eq("provider", "AWS")
76-
)]
77-
/// The default AWS region
78-
aws_region: Option<String>,
79-
#[clap(
80-
long,
81-
env = "AWS_ASG_REGIONS",
82-
value_name = "REGIONS",
83-
required_if_eq("provider", "AWS"),
84-
value_delimiter(':'),
85-
require_delimiter = true
86-
)]
87-
/// Regions containing Nomad clients
88-
aws_asg_regions: Option<Vec<String>>,
89-
}
90-
91-
#[derive(Parser, Default)]
92-
struct Nomad {
93-
#[clap(
94-
long,
95-
value_name = "TOKEN",
96-
env = "NOMAD_TOKEN",
97-
value_parser = clap::value_parser!(Uuid),
98-
setting = ArgSettings::HideEnvValues
99-
)]
100-
/// The Nomad token used to query node information
101-
nomad: Option<Uuid>,
102-
}
103-
10459
#[derive(Parser)]
10560
/// SSH to instances
10661
pub struct Ssh {

0 commit comments

Comments
 (0)