Refactor config updates (#13802)

# Description
This PR standardizes updates to the config through a new
`UpdateFromValue` trait. For now, this trait is private in case we need
to make changes to it.

Note that this PR adds some additional `ShellError` cases to create
standard error messages for config errors. A follow-up PR will move
usages of the old error cases to these new ones. This PR also uses
`Type::custom` in lots of places (e.g., for string enums). Not sure if
this is something we want to encourage.

# User-Facing Changes
Should be none.
This commit is contained in:
Ian Manske
2024-10-11 09:40:32 -07:00
committed by GitHub
parent 02313e6819
commit fce6146576
32 changed files with 1343 additions and 1487 deletions

View File

@ -52,7 +52,7 @@ fn config_add_unsupported_key() {
assert!(actual
.err
.contains("$env.config.foo is an unknown config setting"));
.contains("Unknown config option: $env.config.foo"));
}
#[test]
@ -61,7 +61,7 @@ fn config_add_unsupported_type() {
r#"$env.config.ls = '' "#,
r#";"#]));
assert!(actual.err.contains("should be a record"));
assert!(actual.err.contains("Type mismatch"));
}
#[test]
@ -70,12 +70,8 @@ fn config_add_unsupported_value() {
r#"$env.config.history.file_format = ''"#,
r#";"#]));
assert!(actual
.err
.contains("unrecognized $env.config.history.file_format option ''"));
assert!(actual
.err
.contains("expected either 'sqlite' or 'plaintext'"));
assert!(actual.err.contains("Invalid value"));
assert!(actual.err.contains("expected 'sqlite' or 'plaintext'"));
}
#[test]