diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-17 05:49:19 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-17 05:49:19 +0800 |
| commit | 57c53affe3542cb6bd4e79ee4c18f20a1bd76b2d (patch) | |
| tree | 1cd4aef44cb7a45a8cd9d520b598f5f181e24c76 /mingling_cli/src/config | |
| parent | ef23cd944402939605c78a4a853ef6e33af02c21 (diff) | |
refactor!: replace pack! macros with derive-based pipeline types
Remove the `pack!`, `pack_err!`, `pack_structural!`, and
`pack_err_structural!` macros, replacing all pipeline type definitions
with `#[derive(Grouped)]` and `#[derive(Grouped, Wrap)]` attributes.
This changes the generated struct shape from named-field structs with an
`inner` field to tuple structs accessed via `.0`, and removes the
auto-generated `name` and `info` fields from error types.
Diffstat (limited to 'mingling_cli/src/config')
| -rw-r--r-- | mingling_cli/src/config/cmd_cfg.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/mingling_cli/src/config/cmd_cfg.rs b/mingling_cli/src/config/cmd_cfg.rs index c10195e..8baa4a1 100644 --- a/mingling_cli/src/config/cmd_cfg.rs +++ b/mingling_cli/src/config/cmd_cfg.rs @@ -1,8 +1,6 @@ use mingling::{ - LazyRes, Routable, ShellContext, Suggest, - macros::{ - arg, buffer, chain, command, completion, metadata, pack, r_println, renderer, suggest, - }, + Grouped, LazyRes, Routable, ShellContext, Suggest, Wrap, + macros::{arg, buffer, chain, command, completion, metadata, r_println, renderer, suggest}, metadata::Description, picker::{EntryPicker, PickerArg, value::Flag}, }; @@ -11,10 +9,17 @@ use crate::{Entry, Next, config::ResMlingConfig}; const FLAG_PAIR: PickerArg<Flag> = arg![pair: Flag]; -pack!(StateConfigEdit = (String, String)); -pack!(ResultConfigKeyValuePair = String); -pack!(ResultConfigValue = String); -pack!(ResultConfig = ()); +#[derive(Grouped, Wrap)] +pub struct StateConfigEdit((String, String)); + +#[derive(Grouped, Wrap)] +pub struct ResultConfigKeyValuePair(String); + +#[derive(Grouped, Wrap)] +pub struct ResultConfigValue(String); + +#[derive(Grouped)] +pub struct ResultConfig; #[command] pub fn cfg(args: Entry) -> Next { @@ -27,19 +32,19 @@ pub fn cfg(args: Entry) -> Next { match (key, value) { (Some(k), Some(v)) => { // Edit - StateConfigEdit::new((k, v)).into() + StateConfigEdit((k, v)).into() } (Some(k), None) => { // Display if *show_pair { - ResultConfigKeyValuePair::new(k).to_render() + ResultConfigKeyValuePair(k).to_render() } else { - ResultConfigValue::new(k).to_render() + ResultConfigValue(k).to_render() } } (None, None) => { // List - ResultConfig::new(()).to_render() + ResultConfig.to_render() } _ => { unreachable!("This path is unreachable given the positional parsing done by arg-picker") @@ -50,13 +55,13 @@ pub fn cfg(args: Entry) -> Next { #[chain] pub fn handle_state_config_edit(kv: StateConfigEdit, config: &mut LazyRes<ResMlingConfig>) { let config = config.get_mut(); - config.edit(&kv.0, &kv.1); + config.edit(&kv.0.0, &kv.0.1); } #[renderer(buffer)] pub fn render_config_kvp(r: ResultConfigKeyValuePair, config: &mut LazyRes<ResMlingConfig>) { let config = config.get_ref(); - let key = r.inner; + let key = r.0; let value = config.get(&key); r_println!( "\"{}\" = \"{}\"", @@ -68,7 +73,7 @@ pub fn render_config_kvp(r: ResultConfigKeyValuePair, config: &mut LazyRes<ResMl #[renderer(buffer)] pub fn render_config_value(r: ResultConfigValue, config: &mut LazyRes<ResMlingConfig>) { let config = config.get_ref(); - let key = r.inner; + let key = r.0; let value = config.get(&key); r_println!("{}", value) } |
