|
1 |
| -//! This module provides helper methods to deal with common CLI options using the `clap` crate. |
2 |
| -//! |
3 |
| -//! In particular it currently supports handling two kinds of options: |
4 |
| -//! * CRD printing |
5 |
| -//! * Product config location |
6 |
| -//! |
7 |
| -//! # Example |
8 |
| -//! |
9 |
| -//! This example show the usage of the CRD functionality. |
10 |
| -//! |
11 |
| -//! ```no_run |
12 |
| -//! // Handle CLI arguments |
13 |
| -//! use clap::{crate_version, Parser}; |
14 |
| -//! use kube::CustomResource; |
15 |
| -//! use schemars::JsonSchema; |
16 |
| -//! use serde::{Deserialize, Serialize}; |
17 |
| -//! use stackable_operator::{CustomResourceExt, cli, shared::crd}; |
18 |
| -//! |
19 |
| -//! const OPERATOR_VERSION: &str = "23.1.1"; |
20 |
| -//! |
21 |
| -//! #[derive(Clone, CustomResource, Debug, JsonSchema, Serialize, Deserialize)] |
22 |
| -//! #[kube( |
23 |
| -//! group = "foo.stackable.tech", |
24 |
| -//! version = "v1", |
25 |
| -//! kind = "FooCluster", |
26 |
| -//! namespaced |
27 |
| -//! )] |
28 |
| -//! pub struct FooClusterSpec { |
29 |
| -//! pub name: String, |
30 |
| -//! } |
31 |
| -//! |
32 |
| -//! #[derive(Clone, CustomResource, Debug, JsonSchema, Serialize, Deserialize)] |
33 |
| -//! #[kube( |
34 |
| -//! group = "bar.stackable.tech", |
35 |
| -//! version = "v1", |
36 |
| -//! kind = "BarCluster", |
37 |
| -//! namespaced |
38 |
| -//! )] |
39 |
| -//! pub struct BarClusterSpec { |
40 |
| -//! pub name: String, |
41 |
| -//! } |
42 |
| -//! |
43 |
| -//! #[derive(clap::Parser)] |
44 |
| -//! #[command( |
45 |
| -//! name = "Foobar Operator", |
46 |
| -//! author, |
47 |
| -//! version, |
48 |
| -//! about = "Stackable Operator for Foobar" |
49 |
| -//! )] |
50 |
| -//! struct Opts { |
51 |
| -//! #[clap(subcommand)] |
52 |
| -//! command: cli::Command, |
53 |
| -//! } |
54 |
| -//! |
55 |
| -//! # fn main() -> Result<(), crd::Error> { |
56 |
| -//! let opts = Opts::parse(); |
57 |
| -//! |
58 |
| -//! match opts.command { |
59 |
| -//! cli::Command::Crd => { |
60 |
| -//! FooCluster::print_yaml_schema(OPERATOR_VERSION)?; |
61 |
| -//! BarCluster::print_yaml_schema(OPERATOR_VERSION)?; |
62 |
| -//! }, |
63 |
| -//! cli::Command::Run { .. } => { |
64 |
| -//! // Run the operator |
65 |
| -//! } |
66 |
| -//! } |
67 |
| -//! # Ok(()) |
68 |
| -//! # } |
69 |
| -//! ``` |
70 |
| -//! |
71 |
| -//! Product config handling works similarly: |
72 |
| -//! |
73 |
| -//! ```no_run |
74 |
| -//! use clap::{crate_version, Parser}; |
75 |
| -//! use stackable_operator::cli; |
76 |
| -//! |
77 |
| -//! #[derive(clap::Parser)] |
78 |
| -//! #[command( |
79 |
| -//! name = "Foobar Operator", |
80 |
| -//! author, |
81 |
| -//! version, |
82 |
| -//! about = "Stackable Operator for Foobar" |
83 |
| -//! )] |
84 |
| -//! struct Opts { |
85 |
| -//! #[clap(subcommand)] |
86 |
| -//! command: cli::Command, |
87 |
| -//! } |
88 |
| -//! |
89 |
| -//! # fn main() -> Result<(), cli::Error> { |
90 |
| -//! let opts = Opts::parse(); |
91 |
| -//! |
92 |
| -//! match opts.command { |
93 |
| -//! cli::Command::Crd => { |
94 |
| -//! // Print CRD objects |
95 |
| -//! } |
96 |
| -//! cli::Command::Run(cli::ProductOperatorRun { product_config, watch_namespace, .. }) => { |
97 |
| -//! let product_config = product_config.load(&[ |
98 |
| -//! "deploy/config-spec/properties.yaml", |
99 |
| -//! "/etc/stackable/spark-operator/config-spec/properties.yaml", |
100 |
| -//! ])?; |
101 |
| -//! } |
102 |
| -//! } |
103 |
| -//! # Ok(()) |
104 |
| -//! # } |
105 |
| -//! |
106 |
| -//! ``` |
107 |
| -//! |
108 |
| -//! |
| 1 | +//! Contains various types for composing the CLI interface for operators and other applications |
| 2 | +//! running in a Kubernetes cluster. |
| 3 | +
|
109 | 4 | use clap::{Args, Parser};
|
110 | 5 | use stackable_telemetry::tracing::TelemetryOptions;
|
111 | 6 |
|
|
0 commit comments