schema_registry_cli/settings/
mod.rs1use std::env;
2use std::str::FromStr;
3
4use clap::{Args, Parser, Subcommand};
5use url::Url;
6
7mod completion;
8mod schema;
9mod subjects;
10mod verbosity;
11
12pub use self::completion::*;
13pub use self::schema::*;
14pub use self::subjects::*;
15pub use self::verbosity::*;
16
17#[derive(Debug, Clone, Parser)]
19#[clap(version, author = env!("CARGO_PKG_HOMEPAGE"), about)]
20pub struct Settings {
21 #[clap(flatten)]
23 pub verbosity: Verbosity,
24
25 #[clap(subcommand)]
27 pub command: Command,
28}
29
30#[derive(Debug, Clone, Subcommand)]
32pub enum Command {
33 #[clap(subcommand)]
35 Subject(SubjectSubCommand),
36
37 #[clap(subcommand)]
39 Schema(SchemaSubCommand),
40
41 Completion(Completion),
43}
44
45const DEFAULT_SCHEMA_REGISTRY_URL: &str = "http://localhost:8081";
46
47#[derive(Debug, Clone, PartialEq, Args)]
49pub struct SchemaRegistrySettings {
50 #[clap(short, long, default_value_t = SchemaRegistrySettings::get_url_from_env())]
52 pub url: Url,
53}
54
55impl SchemaRegistrySettings {
56 fn get_url_from_env() -> Url {
57 let input = env::var("SCHEMA_REGISTRY_URL")
58 .unwrap_or_else(|_| DEFAULT_SCHEMA_REGISTRY_URL.to_string());
59 Url::from_str(&input).expect("Valid URL")
60 }
61}
62
63impl Default for SchemaRegistrySettings {
64 fn default() -> Self {
65 let url = Self::get_url_from_env();
66 Self { url }
67 }
68}