Skip to content

Commit

Permalink
feat: impl sort keys in setting files. (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peefy committed May 17, 2023
1 parent 51e56a7 commit 086302b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ message CliConfig {
bool disable_none = 6;
int64 verbose = 7;
bool debug = 8;
bool sort_keys = 9;
}

message KeyValuePair {
Expand Down
1 change: 1 addition & 0 deletions kclvm/api/src/service/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl IntoLoadSettingsFiles for SettingsFile {
disable_none: config.disable_none.unwrap_or_default(),
verbose: config.verbose.unwrap_or_default() as i64,
debug: config.debug.unwrap_or_default(),
sort_keys: config.sort_keys.unwrap_or_default(),
}),
kcl_options: match self.kcl_options {
Some(opts) => opts
Expand Down
2 changes: 1 addition & 1 deletion kclvm/cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn app() -> clap::App<'static> {
(@arg disable_none: -n --disable_none "Disable dumping None values")
(@arg strict_range_check: -r --strict_range_check "Do perform strict numeric range checks")
(@arg debug: -d --debug "Run in debug mode (for developers only)")
(@arg sort_key: -k --sort "Sort result keys")
(@arg sort_keys: -k --sort_keys "Sort result keys")
(@arg arguments: ... -D --argument +takes_value "Specify the top-level argument")
(@arg path_selector: ... -S --path_selector "Specify the path selector")
(@arg overrides: ... -O --overrides +takes_value "Specify the configuration override path and value")
Expand Down
1 change: 1 addition & 0 deletions kclvm/cmd/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub(crate) fn build_settings(matches: &ArgMatches) -> Result<SettingsPathBuf> {
disable_none: bool_from_matches(matches, "disable_none"),
verbose: u32_from_matches(matches, "verbose"),
debug: bool_from_matches(matches, "debug"),
sort_keys: bool_from_matches(matches, "sort_keys"),
package_maps,
..Default::default()
}),
Expand Down
4 changes: 4 additions & 0 deletions kclvm/config/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct Config {
pub disable_none: Option<bool>,
pub verbose: Option<u32>,
pub debug: Option<bool>,
pub sort_keys: Option<bool>,
// kclvm needs a mapping between the package name and the package path
// to determine the source code path corresponding to different version package.
pub package_maps: Option<HashMap<String, String>>,
Expand All @@ -77,6 +78,7 @@ impl SettingsFile {
disable_none: Some(false),
verbose: Some(0),
debug: Some(false),
sort_keys: Some(false),
package_maps: Some(HashMap::default()),
}),
kcl_options: Some(vec![]),
Expand Down Expand Up @@ -373,6 +375,7 @@ pub fn merge_settings(settings: &[SettingsFile]) -> SettingsFile {
set_if!(result_kcl_cli_configs, disable_none, kcl_cli_configs);
set_if!(result_kcl_cli_configs, verbose, kcl_cli_configs);
set_if!(result_kcl_cli_configs, debug, kcl_cli_configs);
set_if!(result_kcl_cli_configs, sort_keys, kcl_cli_configs);
set_if!(result_kcl_cli_configs, package_maps, kcl_cli_configs);
}
}
Expand Down Expand Up @@ -414,6 +417,7 @@ mod settings_test {
assert!(kcl_cli_configs.debug.is_some());
assert!(kcl_cli_configs.path_selector.is_none());
assert!(kcl_cli_configs.overrides.is_none());
assert_eq!(kcl_cli_configs.sort_keys, Some(true));
if let Some(config_files) = kcl_cli_configs.files {
assert!(config_files == files);
}
Expand Down
1 change: 1 addition & 0 deletions kclvm/config/src/testdata/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ kcl_cli_configs:
disable_none: false
strict_range_check: false
debug: false
sort_keys: true
kcl_options:
- key: app-name
value: kclvm
Expand Down
1 change: 1 addition & 0 deletions kclvm/runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl TryFrom<SettingsFile> for ExecProgramArgs {
args.disable_none = cli_configs.disable_none.unwrap_or_default();
args.verbose = cli_configs.verbose.unwrap_or_default() as i32;
args.debug = cli_configs.debug.unwrap_or_default() as i32;
args.sort_keys = cli_configs.sort_keys.unwrap_or_default();
for override_str in &cli_configs.overrides.unwrap_or_default() {
args.overrides.push(parse_override_spec(override_str)?);
}
Expand Down
2 changes: 1 addition & 1 deletion test/grammar/sort_keys/hello/settings.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
kcl_options: -d --sort
kcl_options: -d --sort_keys

0 comments on commit 086302b

Please sign in to comment.