diff options
author | David Knaack <davidkna@users.noreply.github.com> | 2022-04-01 17:14:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 17:14:05 +0200 |
commit | 18ad26f98dd1bfcc01e2b092a5b6165a7b093631 (patch) | |
tree | 10f55ccdfb49f12aae9fd8b03217579683b5a62d /src | |
parent | 418bac919087c692c8188744d951b50643c45f49 (diff) |
feat: allow printing config file schema (#3737)
Diffstat (limited to 'src')
77 files changed, 150 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 982fe688c..ba323dd94 100644 --- a/src/config.rs +++ b/src/config.rs @@ -50,6 +50,7 @@ impl<'a, T: Deserialize<'a> + Default> ModuleConfig<'a, ValueError> for T { } #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(untagged)] pub enum Either<A, B> { First(A), @@ -77,6 +78,24 @@ where } } +#[cfg(feature = "config-schema")] +impl<T> schemars::JsonSchema for VecOr<T> +where + T: schemars::JsonSchema + Sized, +{ + fn schema_name() -> String { + Either::<T, Vec<T>>::schema_name() + } + + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + Either::<T, Vec<T>>::json_schema(gen) + } + + fn is_referenceable() -> bool { + Either::<T, Vec<T>>::is_referenceable() + } +} + /// Root config of starship. pub struct StarshipConfig { pub config: Option<Value>, diff --git a/src/configs/aws.rs b/src/configs/aws.rs index 5e492d394..c6810477d 100644 --- a/src/configs/aws.rs +++ b/src/configs/aws.rs @@ -2,15 +2,48 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] +/// ## AWS +/// +/// The `aws` module shows the current AWS region and profile when +/// credentials or a `credential_process` have been setup. This is based on +/// `AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env var with +/// `~/.aws/config` file. This module also shows an expiration timer when using temporary +/// credentials. +/// +/// The module will display a profile only if its credentials are present in +/// `~/.aws/credentials` or a `credential_process` is defined in +/// `~/.aws/config`. Alternatively, having any of the `AWS_ACCESS_KEY_ID`, +/// `AWS_SECRET_ACCESS_KEY`, or `AWS_SESSION_TOKEN` env vars defined will +/// also suffice. +/// +/// When using [aws-vault](https://github.com/99designs/aws-vault) the profile +/// is read from the `AWS_VAULT` env var and the credentials expiration date +/// is read from the `AWS_SESSION_EXPIRATION` env var. +/// +/// When using [awsu](https://github.com/kreuzwerker/awsu) the profile +/// is read from the `AWSU_PROFILE` env var. +/// +/// When using [AWSume](https://awsu.me) the profile +/// is read from the `AWSUME_PROFILE` env var and the credentials expiration +/// date is read from the `AWSUME_EXPIRATION` env var. pub struct AwsConfig<'a> { + /// The format for the module. pub format: &'a str, + /// The symbol used before displaying the current AWS profile. pub symbol: &'a str, + /// The style for the module. pub style: &'a str, + /// Disables the AWS module. pub disabled: bool, + /// Table of region aliases to display in addition to the AWS name. pub region_aliases: HashMap<String, &'a str>, + /// Table of profile aliases to display in addition to the AWS name. pub profile_aliases: HashMap<String, &'a str>, + /// The symbol displayed when the temporary credentials have expired. pub expiration_symbol: &'a str, + /// If true displays info even if `credentials`, `credential_process` or `sso_start_url` have not been setup. pub force_display: bool, } diff --git a/src/configs/azure.rs b/src/configs/azure.rs index bc4fadde2..259e02c40 100644 --- a/src/configs/azure.rs +++ b/src/configs/azure.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct AzureConfig<'a> { pub format: &'a str, diff --git a/src/configs/battery.rs b/src/configs/battery.rs index 9058aadb9..baa973555 100644 --- a/src/configs/battery.rs +++ b/src/configs/battery.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct BatteryConfig<'a> { pub full_symbol: &'a str, @@ -30,6 +31,7 @@ impl<'a> Default for BatteryConfig<'a> { } #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct BatteryDisplayConfig<'a> { pub threshold: i64, diff --git a/src/configs/buf.rs b/src/configs/buf.rs index 531ce4dfc..32dd5071a 100644 --- a/src/configs/buf.rs +++ b/src/configs/buf.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct BufConfig<'a> { pub format: &'a str, diff --git a/src/configs/c.rs b/src/configs/c.rs index fda0a17ab..b9d15f6e4 100644 --- a/src/configs/c.rs +++ b/src/configs/c.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct CConfig<'a> { pub format: &'a str, diff --git a/src/configs/character.rs b/src/configs/character.rs index 91bba8c23..91cef60c4 100644 --- a/src/configs/character.rs +++ b/src/configs/character.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct CharacterConfig<'a> { pub format: &'a str, diff --git a/src/configs/cmake.rs b/src/configs/cmake.rs index 51140c8f3..679d403e0 100644 --- a/src/configs/cmake.rs +++ b/src/configs/cmake.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct CMakeConfig<'a> { pub format: &'a str, diff --git a/src/configs/cmd_duration.rs b/src/configs/cmd_duration.rs index ace907305..9e1e6725a 100644 --- a/src/configs/cmd_duration.rs +++ b/src/configs/cmd_duration.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct CmdDurationConfig<'a> { pub min_time: i64, diff --git a/src/configs/cobol.rs b/src/configs/cobol.rs index da41b96f3..7858de922 100644 --- a/src/configs/cobol.rs +++ b/src/configs/cobol.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct CobolConfig<'a> { pub format: &'a str, diff --git a/src/configs/conda.rs b/src/configs/conda.rs index df88312d1..e2e391546 100644 --- a/src/configs/conda.rs +++ b/src/configs/conda.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct CondaConfig<'a> { pub truncation_length: usize, diff --git a/src/configs/container.rs b/src/configs/container.rs index dd777b48a..b0173797c 100644 --- a/src/configs/container.rs +++ b/src/configs/container.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct ContainerConfig<'a> { pub format: &'a str, diff --git a/src/configs/crystal.rs b/src/configs/crystal.rs index 7c7ece703..015d64994 100644 --- a/src/configs/crystal.rs +++ b/src/configs/crystal.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct CrystalConfig<'a> { pub format: &'a str, diff --git a/src/configs/custom.rs b/src/configs/custom.rs index a38d60a75..979fe1bd9 100644 --- a/src/configs/custom.rs +++ b/src/configs/custom.rs @@ -3,6 +3,7 @@ use crate::config::VecOr; use serde::{self, Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct CustomConfig<'a> { pub format: &'a str, diff --git a/src/configs/dart.rs b/src/configs/dart.rs index cc235d488..5046d0464 100644 --- a/src/configs/dart.rs +++ b/src/configs/dart.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct DartConfig<'a> { pub format: &'a str, diff --git a/src/configs/deno.rs b/src/configs/deno.rs index f3f955ec3..1308c9c11 100644 --- a/src/configs/deno.rs +++ b/src/configs/deno.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct DenoConfig<'a> { pub format: &'a str, diff --git a/src/configs/directory.rs b/src/configs/directory.rs index 89c98518a..32c72fb6b 100644 --- a/src/configs/directory.rs +++ b/src/configs/directory.rs @@ -3,6 +3,7 @@ use indexmap::IndexMap; use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct DirectoryConfig<'a> { pub truncation_length: i64, diff --git a/src/configs/docker_context.rs b/src/configs/docker_context.rs index 73603ac34..2f7474216 100644 --- a/src/configs/docker_context.rs +++ b/src/configs/docker_context.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct DockerContextConfig<'a> { pub symbol: &'a str, diff --git a/src/configs/dotnet.rs b/src/configs/dotnet.rs index da2137655..4498d6382 100644 --- a/src/configs/dotnet.rs +++ b/src/configs/dotnet.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct DotnetConfig<'a> { pub format: &'a str, diff --git a/src/configs/elixir.rs b/src/configs/elixir.rs index fac7983c2..b0ad3cb81 100644 --- a/src/configs/elixir.rs +++ b/src/configs/elixir.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct ElixirConfig<'a> { pub format: &'a str, diff --git a/src/configs/elm.rs b/src/configs/elm.rs index 1b5357d43..31bb1fb73 100644 --- a/src/configs/elm.rs +++ b/src/configs/elm.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct ElmConfig<'a> { pub format: &'a str, diff --git a/src/configs/env_var.rs b/src/configs/env_var.rs index 0b5c663b7..8f6b995bd 100644 --- a/src/configs/env_var.rs +++ b/src/configs/env_var.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct EnvVarConfig<'a> { pub symbol: &'a str, diff --git a/src/configs/erlang.rs b/src/configs/erlang.rs index 06888b88a..a1cca11fe 100644 --- a/src/configs/erlang.rs +++ b/src/configs/erlang.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct ErlangConfig<'a> { pub format: &'a str, diff --git a/src/configs/fill.rs b/src/configs/fill.rs index 63cd4424c..eaf72a1b0 100644 --- a/src/configs/fill.rs +++ b/src/configs/fill.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct FillConfig<'a> { pub style: &'a str, diff --git a/src/configs/gcloud.rs b/src/configs/gcloud.rs index e298a0446..1f2aec552 100644 --- a/src/configs/gcloud.rs +++ b/src/configs/gcloud.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))] #[serde(default)] pub struct GcloudConfig<'a> { pub format: &'a str, |