Skip to content

Commit 56d9ad7

Browse files
committed
fix: show cli options sorted
Sort the cli options when the `--help` command is used Signed-off-by: Flavio Castelli <fcastelli@suse.com>
1 parent a5d53ca commit 56d9ad7

File tree

1 file changed

+9
-52
lines changed

1 file changed

+9
-52
lines changed

src/cli.rs

+9-52
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ lazy_static! {
2121
}
2222

2323
pub(crate) fn build_cli() -> Command {
24-
Command::new(crate_name!())
25-
.author(crate_authors!())
26-
.version(crate_version!())
27-
.about(crate_description!())
28-
.arg(
24+
let mut args = vec![
2925
Arg::new("log-level")
3026
.long("log-level")
3127
.value_name("LOG_LEVEL")
@@ -39,8 +35,6 @@ pub(crate) fn build_cli() -> Command {
3935
PossibleValue::new("error"),
4036
])
4137
.help("Log level"),
42-
)
43-
.arg(
4438
Arg::new("log-fmt")
4539
.long("log-fmt")
4640
.value_name("LOG_FMT")
@@ -52,169 +46,132 @@ pub(crate) fn build_cli() -> Command {
5246
PossibleValue::new("otlp"),
5347
])
5448
.help("Log output format"),
55-
)
56-
.arg(
5749
Arg::new("log-no-color")
5850
.long("log-no-color")
5951
.env("NO_COLOR")
6052
.required(false)
6153
.help("Disable colored output for logs"),
62-
)
63-
.arg(
6454
Arg::new("address")
6555
.long("addr")
6656
.value_name("BIND_ADDRESS")
6757
.default_value("0.0.0.0")
6858
.env("KUBEWARDEN_BIND_ADDRESS")
6959
.help("Bind against ADDRESS"),
70-
)
71-
.arg(
7260
Arg::new("port")
7361
.long("port")
7462
.value_name("PORT")
7563
.default_value("3000")
7664
.env("KUBEWARDEN_PORT")
7765
.help("Listen on PORT"),
78-
)
79-
.arg(
8066
Arg::new("workers")
8167
.long("workers")
8268
.value_name("WORKERS_NUMBER")
8369
.env("KUBEWARDEN_WORKERS")
8470
.help("Number of workers thread to create"),
85-
)
86-
.arg(
8771
Arg::new("cert-file")
8872
.long("cert-file")
8973
.value_name("CERT_FILE")
9074
.default_value("")
9175
.env("KUBEWARDEN_CERT_FILE")
9276
.help("Path to an X.509 certificate file for HTTPS"),
93-
)
94-
.arg(
9577
Arg::new("key-file")
9678
.long("key-file")
9779
.value_name("KEY_FILE")
9880
.default_value("")
9981
.env("KUBEWARDEN_KEY_FILE")
10082
.help("Path to an X.509 private key file for HTTPS"),
101-
)
102-
.arg(
10383
Arg::new("policies")
10484
.long("policies")
10585
.value_name("POLICIES_FILE")
10686
.env("KUBEWARDEN_POLICIES")
10787
.default_value("policies.yml")
10888
.help("YAML file holding the policies to be loaded and their settings"),
109-
)
110-
.arg(
11189
Arg::new("policies-download-dir")
11290
.long("policies-download-dir")
11391
.value_name("POLICIES_DOWNLOAD_DIR")
11492
.default_value(".")
11593
.env("KUBEWARDEN_POLICIES_DOWNLOAD_DIR")
11694
.help("Download path for the policies"),
117-
)
118-
.arg(
11995
Arg::new("sigstore-cache-dir")
12096
.long("sigstore-cache-dir")
12197
.value_name("SIGSTORE_CACHE_DIR")
12298
.default_value("sigstore-data")
12399
.env("KUBEWARDEN_SIGSTORE_CACHE_DIR")
124100
.help("Directory used to cache sigstore data"),
125-
)
126-
.arg(
127101
Arg::new("sources-path")
128102
.long("sources-path")
129103
.value_name("SOURCES_PATH")
130104
.env("KUBEWARDEN_SOURCES_PATH")
131105
.help("YAML file holding source information (https, registry insecure hosts, custom CA's...)"),
132-
)
133-
.arg(
134106
Arg::new("verification-path")
135107
.long("verification-path")
136108
.value_name("VERIFICATION_CONFIG_PATH")
137109
.env("KUBEWARDEN_VERIFICATION_CONFIG_PATH")
138110
.help("YAML file holding verification information (URIs, keys, annotations...)"),
139-
)
140-
.arg(
141111
Arg::new("docker-config-json-path")
142112
.long("docker-config-json-path")
143113
.value_name("DOCKER_CONFIG")
144114
.env("KUBEWARDEN_DOCKER_CONFIG_JSON_PATH")
145115
.help("Path to a Docker config.json-like path. Can be used to indicate registry authentication details"),
146-
)
147-
.arg(
148116
Arg::new("enable-metrics")
149117
.long("enable-metrics")
150118
.env("KUBEWARDEN_ENABLE_METRICS")
151119
.required(false)
152120
.help("Enable metrics"),
153-
)
154-
.arg(
155121
Arg::new("enable-verification")
156122
.long("enable-verification")
157123
.env("KUBEWARDEN_ENABLE_VERIFICATION")
158124
.required(false)
159125
.help("Enable Sigstore verification"),
160-
)
161-
.arg(
162126
Arg::new("always-accept-admission-reviews-on-namespace")
163127
.long("always-accept-admission-reviews-on-namespace")
164128
.value_name("NAMESPACE")
165129
.env("KUBEWARDEN_ALWAYS_ACCEPT_ADMISSION_REVIEWS_ON_NAMESPACE")
166130
.required(false)
167131
.help("Always accept AdmissionReviews that target the given namespace"),
168-
)
169-
.arg(
170132
Arg::new("disable-timeout-protection")
171133
.long("disable-timeout-protection")
172134
.env("KUBEWARDEN_DISABLE_TIMEOUT_PROTECTION")
173135
.required(false)
174136
.help("Disable policy timeout protection"),
175-
)
176-
.arg(
177137
Arg::new("policy-timeout")
178138
.long("policy-timeout")
179139
.env("KUBEWARDEN_POLICY_TIMEOUT")
180140
.value_name("MAXIMUM_EXECUTION_TIME_SECONDS")
181141
.default_value("2")
182142
.help("Interrupt policy evaluation after the given time"),
183-
)
184-
.arg(
185143
Arg::new("daemon")
186144
.long("daemon")
187145
.env("KUBEWARDEN_DAEMON")
188146
.required(false)
189147
.help("If set, runs policy-server in detached mode as a daemon"),
190-
)
191-
.arg(
192148
Arg::new("daemon-pid-file")
193149
.long("daemon-pid-file")
194150
.env("KUBEWARDEN_DAEMON_PID_FILE")
195151
.default_value("policy-server.pid")
196152
.help("Path to pid file, used only when running in daemon mode"),
197-
)
198-
.arg(
199153
Arg::new("daemon-stdout-file")
200154
.long("daemon-stdout-file")
201155
.env("KUBEWARDEN_DAEMON_STDOUT_FILE")
202156
.required(false)
203157
.help("Path to file holding stdout, used only when running in daemon mode"),
204-
)
205-
.arg(
206158
Arg::new("daemon-stderr-file")
207159
.long("daemon-stderr-file")
208160
.env("KUBEWARDEN_DAEMON_STDERR_FILE")
209161
.required(false)
210162
.help("Path to file holding stderr, used only when running in daemon mode"),
211-
)
212-
.arg(
213163
Arg::new("ignore-kubernetes-connection-failure")
214164
.long("ignore-kubernetes-connection-failure")
215165
.env("KUBEWARDEN_IGNORE_KUBERNETES_CONNECTION_FAILURE")
216166
.required(false)
217167
.help("Do not exit with an error if the Kubernetes connection fails. This will cause context aware policies to break when there's no connection with Kubernetes."),
218-
)
168+
];
169+
args.sort_by(|a, b| a.get_id().cmp(b.get_id()));
170+
171+
Command::new(crate_name!())
172+
.author(crate_authors!())
173+
.version(crate_version!())
174+
.about(crate_description!())
219175
.long_version(VERSION_AND_BUILTINS.as_str())
176+
.args(args)
220177
}

0 commit comments

Comments
 (0)