From cb94d3d880794caf99a7724da63412867230754b Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:38:49 -0600 Subject: [PATCH] fix: added completes to string output (#186) --- ...e__complete__bash__tests__complete_bash-3.snap | 1 + ...e__complete__fish__tests__complete_fish-3.snap | 1 + ...age__complete__zsh__tests__complete_zsh-3.snap | 1 + lib/src/spec/complete.rs | 15 +++++++++++++++ lib/src/spec/mod.rs | 6 ++++++ 5 files changed, 24 insertions(+) diff --git a/lib/src/complete/snapshots/usage__complete__bash__tests__complete_bash-3.snap b/lib/src/complete/snapshots/usage__complete__bash__tests__complete_bash-3.snap index fc9fbe6..e3eb69e 100644 --- a/lib/src/complete/snapshots/usage__complete__bash__tests__complete_bash-3.snap +++ b/lib/src/complete/snapshots/usage__complete__bash__tests__complete_bash-3.snap @@ -33,6 +33,7 @@ arg "[arg2]" help="arg2 description" default="default value" { arg "" help="arg3 description" help_long="arg3 long description" arg "..." var=true arg "[with-default]" default="default value" +complete "plugin" run="echo \"plugin-1\nplugin-2\nplugin-3\"" cmd "plugin" { cmd "install" { flag "-g --global" diff --git a/lib/src/complete/snapshots/usage__complete__fish__tests__complete_fish-3.snap b/lib/src/complete/snapshots/usage__complete__fish__tests__complete_fish-3.snap index 47e84e1..53c937a 100644 --- a/lib/src/complete/snapshots/usage__complete__fish__tests__complete_fish-3.snap +++ b/lib/src/complete/snapshots/usage__complete__fish__tests__complete_fish-3.snap @@ -32,6 +32,7 @@ arg "[arg2]" help="arg2 description" default="default value" { arg "" help="arg3 description" help_long="arg3 long description" arg "..." var=true arg "[with-default]" default="default value" +complete "plugin" run="echo \"plugin-1\nplugin-2\nplugin-3\"" cmd "plugin" { cmd "install" { flag "-g --global" diff --git a/lib/src/complete/snapshots/usage__complete__zsh__tests__complete_zsh-3.snap b/lib/src/complete/snapshots/usage__complete__zsh__tests__complete_zsh-3.snap index f6953c7..a82a4f2 100644 --- a/lib/src/complete/snapshots/usage__complete__zsh__tests__complete_zsh-3.snap +++ b/lib/src/complete/snapshots/usage__complete__zsh__tests__complete_zsh-3.snap @@ -38,6 +38,7 @@ arg "[arg2]" help="arg2 description" default="default value" { arg "" help="arg3 description" help_long="arg3 long description" arg "..." var=true arg "[with-default]" default="default value" +complete "plugin" run="echo \"plugin-1\nplugin-2\nplugin-3\"" cmd "plugin" { cmd "install" { flag "-g --global" diff --git a/lib/src/spec/complete.rs b/lib/src/spec/complete.rs index 618ab5d..d0cd657 100644 --- a/lib/src/spec/complete.rs +++ b/lib/src/spec/complete.rs @@ -1,3 +1,4 @@ +use kdl::{KdlEntry, KdlNode}; use serde::{Deserialize, Serialize}; use crate::error::UsageErr; @@ -38,3 +39,17 @@ impl SpecComplete { Ok(config) } } + +impl From<&SpecComplete> for KdlNode { + fn from(complete: &SpecComplete) -> Self { + let mut node = KdlNode::new("complete"); + node.push(KdlEntry::new(complete.name.clone())); + if let Some(run) = &complete.run { + node.push(KdlEntry::new_prop("run", run.clone())); + } + if let Some(type_) = &complete.type_ { + node.push(KdlEntry::new_prop("type", type_.clone())); + } + node + } +} diff --git a/lib/src/spec/mod.rs b/lib/src/spec/mod.rs index a1dbe9a..7db8335 100644 --- a/lib/src/spec/mod.rs +++ b/lib/src/spec/mod.rs @@ -90,6 +90,7 @@ impl Spec { && self.usage.is_empty() && self.cmd.is_empty() && self.config.is_empty() + && self.complete.is_empty() } pub(crate) fn parse(ctx: &ParsingContext, input: &str) -> Result { @@ -342,6 +343,9 @@ impl Display for Spec { for arg in self.cmd.args.iter() { nodes.push(arg.into()); } + for complete in self.complete.values() { + nodes.push(complete.into()); + } for cmd in self.cmd.subcommands.values() { nodes.push(cmd.into()) } @@ -406,6 +410,7 @@ cmd "config" { arg "value" } } +complete "file" run="ls" "#, ) .unwrap(); @@ -414,6 +419,7 @@ cmd "config" { bin "usage" flag "-f --force" global=true arg "" + complete "file" run="ls" cmd "config" { cmd "set" { arg "" help="Key to set"