use std::env;
use std::str::FromStr;
use clap::{Args, Parser, Subcommand};
use url::Url;
mod completion;
mod schema;
mod subjects;
mod verbosity;
pub use self::completion::*;
pub use self::schema::*;
pub use self::subjects::*;
pub use self::verbosity::*;
#[derive(Debug, Clone, Parser)]
#[clap(version, author = env!("CARGO_PKG_HOMEPAGE"), about)]
pub struct Settings {
#[clap(flatten)]
pub verbosity: Verbosity,
#[clap(subcommand)]
pub command: Command,
}
#[derive(Debug, Clone, Subcommand)]
pub enum Command {
#[clap(subcommand)]
Subject(SubjectSubCommand),
#[clap(subcommand)]
Schema(SchemaSubCommand),
Completion(Completion),
}
const DEFAULT_SCHEMA_REGISTRY_URL: &str = "http://localhost:8081";
#[derive(Debug, Clone, PartialEq, Args)]
pub struct SchemaRegistrySettings {
#[clap(short, long, default_value_t = SchemaRegistrySettings::get_url_from_env())]
pub url: Url,
}
impl SchemaRegistrySettings {
fn get_url_from_env() -> Url {
let input = env::var("SCHEMA_REGISTRY_URL")
.unwrap_or_else(|_| DEFAULT_SCHEMA_REGISTRY_URL.to_string());
Url::from_str(&input).expect("Valid URL")
}
}
impl Default for SchemaRegistrySettings {
fn default() -> Self {
let url = Self::get_url_from_env();
Self { url }
}
}