1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-05-29 06:30:52 +00:00
starship/src/configs/mod.rs
David Knaack 2d4b183fce
refactor: replace module_config_derive with serde (#3786)
* refactor: replace module_config_derive with serde

Changes include:
* Removing `starship_module_config_derive` and replacing it with `serde::Deserialize`
* Removing `RootModuleConfig::load_config`. While potentially useful, it was only used in tests. And it would require something like `serde::DeserializeSeed` which is not derived by serde.
* Merging `RootModuleConfig` into `ModuleConfig`
* Implementing a `ValueDeserializer` that holds a reference to a `toml::Value` in `serde_utils.rs`
* Deserialization errors (invalid type) are now logged and include the current key and the struct names
* Unknown keys are now considered an error. "Did you mean?"-messages are still possible

* fix typo

Co-authored-by: Matan Kushner <hello@matchai.dev>

Co-authored-by: Matan Kushner <hello@matchai.dev>
2022-03-26 10:42:19 +01:00

247 lines
6.0 KiB
Rust

use indexmap::IndexMap;
use serde::{self, Deserialize, Serialize};
pub mod aws;
pub mod azure;
pub mod battery;
pub mod buf;
pub mod c;
pub mod character;
pub mod cmake;
pub mod cmd_duration;
pub mod cobol;
pub mod conda;
pub mod container;
pub mod crystal;
pub mod custom;
pub mod dart;
pub mod deno;
pub mod directory;
pub mod docker_context;
pub mod dotnet;
pub mod elixir;
pub mod elm;
pub mod env_var;
pub mod erlang;
pub mod fill;
pub mod gcloud;
pub mod git_branch;
pub mod git_commit;
pub mod git_metrics;
pub mod git_state;
pub mod git_status;
pub mod go;
pub mod haskell;
pub mod helm;
pub mod hg_branch;
pub mod hostname;
pub mod java;
pub mod jobs;
pub mod julia;
pub mod kotlin;
pub mod kubernetes;
pub mod line_break;
pub mod localip;
pub mod lua;
pub mod memory_usage;
pub mod nim;
pub mod nix_shell;
pub mod nodejs;
pub mod ocaml;
pub mod openstack;
pub mod package;
pub mod perl;
pub mod php;
pub mod pulumi;
pub mod purescript;
pub mod python;
pub mod red;
pub mod rlang;
pub mod ruby;
pub mod rust;
pub mod scala;
pub mod shell;
pub mod shlvl;
pub mod singularity;
mod starship_root;
pub mod status;
pub mod sudo;
pub mod swift;
pub mod terraform;
pub mod time;
pub mod username;
pub mod v;
pub mod vagrant;
pub mod vcsh;
pub mod zig;
pub use starship_root::*;
#[derive(Serialize, Deserialize, Clone, Default)]
#[serde(default)]
pub struct FullConfig<'a> {
// Root config
#[serde(flatten)]
root: StarshipRootConfig,
// modules
#[serde(borrow)]
aws: aws::AwsConfig<'a>,
#[serde(borrow)]
azure: azure::AzureConfig<'a>,
#[serde(borrow)]
battery: battery::BatteryConfig<'a>,
#[serde(borrow)]
buf: buf::BufConfig<'a>,
#[serde(borrow)]
c: c::CConfig<'a>,
#[serde(borrow)]
character: character::CharacterConfig<'a>,
#[serde(borrow)]
cmake: cmake::CMakeConfig<'a>,
#[serde(borrow)]
cmd_duration: cmd_duration::CmdDurationConfig<'a>,
#[serde(borrow)]
cobol: cobol::CobolConfig<'a>,
#[serde(borrow)]
conda: conda::CondaConfig<'a>,
#[serde(borrow)]
container: container::ContainerConfig<'a>,
#[serde(borrow)]
crystal: crystal::CrystalConfig<'a>,
#[serde(borrow)]
dart: dart::DartConfig<'a>,
#[serde(borrow)]
deno: deno::DenoConfig<'a>,
#[serde(borrow)]
directory: directory::DirectoryConfig<'a>,
#[serde(borrow)]
docker_context: docker_context::DockerContextConfig<'a>,
#[serde(borrow)]
dotnet: dotnet::DotnetConfig<'a>,
#[serde(borrow)]
elixir: elixir::ElixirConfig<'a>,
#[serde(borrow)]
elm: elm::ElmConfig<'a>,
#[serde(borrow)]
env_var: IndexMap<String, env_var::EnvVarConfig<'a>>,
#[serde(borrow)]
erlang: erlang::ErlangConfig<'a>,
#[serde(borrow)]
fill: fill::FillConfig<'a>,
#[serde(borrow)]
gcloud: gcloud::GcloudConfig<'a>,
#[serde(borrow)]
git_branch: git_branch::GitBranchConfig<'a>,
#[serde(borrow)]
git_commit: git_commit::GitCommitConfig<'a>,
#[serde(borrow)]
git_metrics: git_metrics::GitMetricsConfig<'a>,
#[serde(borrow)]
git_state: git_state::GitStateConfig<'a>,
#[serde(borrow)]
git_status: git_status::GitStatusConfig<'a>,
#[serde(borrow)]
golang: go::GoConfig<'a>,
#[serde(borrow)]
haskell: haskell::HaskellConfig<'a>,
#[serde(borrow)]
helm: helm::HelmConfig<'a>,
#[serde(borrow)]
hg_branch: hg_branch::HgBranchConfig<'a>,
#[serde(borrow)]
hostname: hostname::HostnameConfig<'a>,
#[serde(borrow)]
java: java::JavaConfig<'a>,
#[serde(borrow)]
jobs: jobs::JobsConfig<'a>,
#[serde(borrow)]
julia: julia::JuliaConfig<'a>,
#[serde(borrow)]
kotlin: kotlin::KotlinConfig<'a>,
#[serde(borrow)]
kubernetes: kubernetes::KubernetesConfig<'a>,
line_break: line_break::LineBreakConfig,
#[serde(borrow)]
localip: localip::LocalipConfig<'a>,
#[serde(borrow)]
lua: lua::LuaConfig<'a>,
#[serde(borrow)]
memory_usage: memory_usage::MemoryConfig<'a>,
#[serde(borrow)]
nim: nim::NimConfig<'a>,
#[serde(borrow)]
nix_shell: nix_shell::NixShellConfig<'a>,
#[serde(borrow)]
nodejs: nodejs::NodejsConfig<'a>,
#[serde(borrow)]
ocaml: ocaml::OCamlConfig<'a>,
#[serde(borrow)]
openstack: openstack::OspConfig<'a>,
#[serde(borrow)]
package: package::PackageConfig<'a>,
#[serde(borrow)]
perl: perl::PerlConfig<'a>,
#[serde(borrow)]
php: php::PhpConfig<'a>,
#[serde(borrow)]
pulumi: pulumi::PulumiConfig<'a>,
#[serde(borrow)]
purescript: purescript::PureScriptConfig<'a>,
#[serde(borrow)]
python: python::PythonConfig<'a>,
#[serde(borrow)]
red: red::RedConfig<'a>,
#[serde(borrow)]
rlang: rlang::RLangConfig<'a>,
#[serde(borrow)]
ruby: ruby::RubyConfig<'a>,
#[serde(borrow)]
rust: rust::RustConfig<'a>,
#[serde(borrow)]
scala: scala::ScalaConfig<'a>,
#[serde(borrow)]
shell: shell::ShellConfig<'a>,
#[serde(borrow)]
shlvl: shlvl::ShLvlConfig<'a>,
#[serde(borrow)]
singularity: singularity::SingularityConfig<'a>,
#[serde(borrow)]
status: status::StatusConfig<'a>,
#[serde(borrow)]
sudo: sudo::SudoConfig<'a>,
#[serde(borrow)]
swift: swift::SwiftConfig<'a>,
#[serde(borrow)]
terraform: terraform::TerraformConfig<'a>,
#[serde(borrow)]
time: time::TimeConfig<'a>,
#[serde(borrow)]
username: username::UsernameConfig<'a>,
#[serde(borrow)]
vagrant: vagrant::VagrantConfig<'a>,
#[serde(borrow)]
vcsh: vcsh::VcshConfig<'a>,
#[serde(borrow)]
vlang: v::VConfig<'a>,
#[serde(borrow)]
zig: zig::ZigConfig<'a>,
#[serde(borrow)]
custom: IndexMap<String, custom::CustomConfig<'a>>,
}
#[cfg(test)]
mod test {
use super::*;
use crate::module::ALL_MODULES;
use toml::value::Value;
#[test]
fn test_all_modules_in_full_config() {
let full_cfg = Value::try_from(FullConfig::default()).unwrap();
let cfg_table = full_cfg.as_table().unwrap();
for module in ALL_MODULES {
assert!(cfg_table.contains_key(*module));
}
}
}