Allow options to be set from environment variables

This commit is contained in:
Erwin Boskma 2022-11-05 10:43:29 +01:00
parent 22b6ecdd4a
commit 151ebbe8a6
Signed by: erwin
SSH key fingerprint: SHA256:CyeNoWXd3kjX2Nwu6pDxxdS7OqmPVOy0NavA/KU/ntU

View file

@ -18,30 +18,36 @@ mod output;
#[clap(version, author, about)] #[clap(version, author, about)]
struct Opts { struct Opts {
/// Home Assistant host /// Home Assistant host
#[clap(short, long)] #[clap(short, long, env = "HNP_HOST")]
host: String, host: String,
/// Media player entity ID /// Media player entity ID
#[clap(short, long)] #[clap(short, long, env = "HNP_ENTITY")]
entity: String, entity: String,
/// API token /// API token
#[clap(short, long, env)] #[clap(short, long, env = "HNP_TOKEN")]
token: Option<String>, token: Option<String>,
/// File with the API token /// File with the API token
#[clap(long, env)] #[clap(long, env, env = "HNP_TOKEN_FILE")]
token_file: Option<PathBuf>, token_file: Option<PathBuf>,
/// Use HTTP instead of HTTPS /// Use HTTP instead of HTTPS
#[clap(short, long)] #[clap(short, long, env = "HNP_INSECURE")]
insecure: bool, insecure: bool,
/// Output format /// Output format
#[clap(arg_enum, short, long, default_value = "waybar")] #[clap(
arg_enum,
short,
long,
env = "HNP_OUTPUT_FORMAT",
default_value = "waybar"
)]
format: output::OutputFormat, format: output::OutputFormat,
#[clap(short, long)] #[clap(short, long, env = "HNP_DEBUG")]
debug: bool, debug: bool,
#[clap(subcommand)] #[clap(subcommand)]