1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-24 13:47:38 +00:00

feat: allow printing config file schema (#3737)

This commit is contained in:
David Knaack 2022-04-01 17:14:05 +02:00 committed by GitHub
parent 418bac9190
commit 18ad26f98d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
85 changed files with 4944 additions and 0 deletions

1
.gitattributes vendored
View File

@ -1,2 +1,3 @@
/src/init/* text eol=lf
*.sh text eol=lf
/.github/config-schema.json text eol=lf

4711
.github/config-schema.json vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -129,6 +129,31 @@ jobs:
- name: Build | Check
run: cargo check --workspace --locked --all-features
# Check if config schema needs to be updated to reflect updated configuration options
check_if_config_schema_up_to_date:
name: Check if config schema is up to date
needs: cargo_check
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/checkout@v3
- name: Setup | Cache
uses: Swatinem/rust-cache@v1
- name: Setup | Rust
uses: actions-rs/toolchain@v1.0.7
with:
toolchain: stable
profile: minimal
override: true
- name: Run | Generate Schema
run: cargo run --locked --features config-schema -- config-schema > .github/config-schema.json
- name: Check | Detect Changes
run: git diff --exit-code .github/config-schema.json
# Run tests on Linux, macOS, and Windows
# On both Rust stable and Rust nightly
test:

View File

@ -154,6 +154,8 @@ dprint fmt
Editor plugins/functionality may help you run these automatically so that you don't accidentally create a PR that fails.
If your changes cause changes to the configuration, you will need to update the configuration schema in `.github/config-schema.json` with `cargo run --features config-schema -- config-schema > .github/config-schema.json`.
## Testing
Testing is critical to making sure starship works as intended on systems big and small. Starship interfaces with many applications and system APIs when generating the prompt, so there's a lot of room for bugs to slip in.
@ -291,6 +293,7 @@ everyone remember what they are. Don't worry: most of them are quite simple!
- [ ] Add the variable to the appropriate location in the "Default Prompt
Format" section of the documentation
- [ ] Add an appropriate choice of options to each preset in `docs/presets/README.md`
- [ ] Update the config file schema by running `cargo run --features config-schema -- config-schema > .github/config-schema.json`
- [ ] Create configs structs/traits in `src/configs/<module>.rs` and add the
following:
- [ ] An entry in `PROMPT_ORDER` (`src/configs/starship_root.rs`)

43
Cargo.lock generated
View File

@ -476,6 +476,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
[[package]]
name = "dyn-clone"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee2626afccd7561a06cf1367e2950c4718ea04565e20fb5029b6c7d8ad09abcf"
[[package]]
name = "easy-parallel"
version = "3.2.0"
@ -1410,6 +1416,31 @@ version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "schemars"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6b5a3c80cea1ab61f4260238409510e814e38b4b563c06044edf91e7dc070e3"
dependencies = [
"dyn-clone",
"indexmap",
"schemars_derive",
"serde",
"serde_json",
]
[[package]]
name = "schemars_derive"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ae4dce13e8614c46ac3c38ef1c0d668b101df6ac39817aebdaa26642ddae9b"
dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
"syn",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -1442,6 +1473,17 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_derive_internals"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.79"
@ -1567,6 +1609,7 @@ dependencies = [
"rayon",
"regex",
"rust-ini",
"schemars",
"semver",
"serde",
"serde_json",

View File

@ -16,6 +16,7 @@ include = [
"LICENSE",
"/README.md",
"docs/.vuepress/public/presets/toml/",
".github/config-schema.json",
]
keywords = ["prompt", "shell", "bash", "fish", "zsh"]
license = "ISC"
@ -31,6 +32,7 @@ The minimal, blazing-fast, and infinitely customizable prompt for any shell! ☄
[features]
default = ["battery"]
battery = ["starship-battery"]
config-schema = ["schemars"]
[dependencies]
ansi_term = "0.12.1"
@ -81,6 +83,11 @@ process_control = { version = "3.3.0", features = ["crossbeam-channel"] }
shell-words = "1.1.0"
[dependencies.schemars]
version = "0.8.8"
optional = true
features = ["preserve_order", "indexmap"]
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["winuser", "securitybaseapi", "processthreadsapi", "handleapi", "impl-default"] }

View File

@ -0,0 +1 @@
../../../.github/config-schema.json

View File

@ -9,6 +9,9 @@ mkdir -p ~/.config && touch ~/.config/starship.toml
All configuration for starship is done in this [TOML](https://github.com/toml-lang/toml) file:
```toml
# Get editor completions based on the config schema
"$schema" = 'https://starship.rs/config-schema.json'
# Inserts a blank line between shell prompts
add_newline = true

View File

@ -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>,

View File

@ -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,
}

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct GitBranchConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct GitCommitConfig<'a> {
pub commit_hash_length: usize,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct GitMetricsConfig<'a> {
pub added_style: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct GitStateConfig<'a> {
pub rebase: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct GitStatusConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct GoConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct HaskellConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct HelmConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct HgBranchConfig<'a> {
pub symbol: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct HostnameConfig<'a> {
pub ssh_only: bool,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct JavaConfig<'a> {
pub disabled: bool,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct JobsConfig<'a> {
pub threshold: i64,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct JuliaConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct KotlinConfig<'a> {
pub format: &'a str,

View File

@ -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 KubernetesConfig<'a> {
pub symbol: &'a str,

View File

@ -1,6 +1,8 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize, Default)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct LineBreakConfig {
pub disabled: bool,
}

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct LocalipConfig<'a> {
pub ssh_only: bool,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct LuaConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct MemoryConfig<'a> {
pub threshold: i64,

View File

@ -78,8 +78,12 @@ pub mod zig;
pub use starship_root::*;
#[derive(Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct FullConfig<'a> {
// Meta
#[serde(rename = "$schema")]
schema: String,
// Root config
#[serde(flatten)]
root: StarshipRootConfig,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct NimConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct NixShellConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct NodejsConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct OCamlConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct OspConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct PackageConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct PerlConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct PhpConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct PulumiConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct PureScriptConfig<'a> {
pub format: &'a str,

View File

@ -3,6 +3,7 @@ use crate::config::VecOr;
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct PythonConfig<'a> {
pub pyenv_version_name: bool,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct RedConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct RLangConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct RubyConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct RustConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct ScalaConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct ShellConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct ShLvlConfig<'a> {
pub threshold: i64,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct SingularityConfig<'a> {
pub symbol: &'a str,

View File

@ -1,8 +1,11 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct StarshipRootConfig {
#[serde(rename = "$schema")]
schema: String,
pub format: String,
pub right_format: String,
pub continuation_prompt: String,
@ -96,6 +99,7 @@ pub const PROMPT_ORDER: &[&str] = &[
impl<'a> Default for StarshipRootConfig {
fn default() -> Self {
StarshipRootConfig {
schema: "https://starship.rs/config-schema.json".to_string(),
format: "$all".to_string(),
right_format: "".to_string(),
continuation_prompt: "[∙](bright-black) ".to_string(),

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct StatusConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct SudoConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct SwiftConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct TerraformConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct TimeConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct UsernameConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct VConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct VagrantConfig<'a> {
pub format: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct VcshConfig<'a> {
pub symbol: &'a str,

View File

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
#[serde(default)]
pub struct ZigConfig<'a> {
pub format: &'a str,

View File

@ -97,6 +97,9 @@ enum Commands {
#[clap(default_value = "disabled")]
value: String,
},
#[cfg(feature = "config-schema")]
/// Generate a schema for the starship configuration as JSON-schema
ConfigSchema,
}
fn main() {
@ -216,6 +219,8 @@ fn main() {
.map(char::from)
.collect::<String>()
),
#[cfg(feature = "config-schema")]
Commands::ConfigSchema => print::print_schema(),
}
}

View File

@ -444,6 +444,12 @@ fn load_formatter_and_modules<'a>(context: &'a Context) -> (StringFormatter<'a>,
}
}
#[cfg(feature = "config-schema")]
pub fn print_schema() {
let schema = schemars::schema_for!(crate::configs::FullConfig);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
#[cfg(test)]
mod test {
use super::*;
@ -483,4 +489,10 @@ mod test {
let actual = get_prompt(context);
assert_eq!(expected, actual);
}
#[test]
#[cfg(feature = "config-schema")]
fn print_schema_does_not_panic() {
print_schema();
}
}