Skip to content

Commit

Permalink
fix: added completes to string output (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Dec 9, 2024
1 parent d29ec77 commit cb94d3d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ arg "[arg2]" help="arg2 description" default="default value" {
arg "<arg3>" help="arg3 description" help_long="arg3 long description"
arg "<argrest>..." 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ arg "[arg2]" help="arg2 description" default="default value" {
arg "<arg3>" help="arg3 description" help_long="arg3 long description"
arg "<argrest>..." 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ arg "[arg2]" help="arg2 description" default="default value" {
arg "<arg3>" help="arg3 description" help_long="arg3 long description"
arg "<argrest>..." 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"
Expand Down
15 changes: 15 additions & 0 deletions lib/src/spec/complete.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use kdl::{KdlEntry, KdlNode};
use serde::{Deserialize, Serialize};

use crate::error::UsageErr;
Expand Down Expand Up @@ -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
}
}
6 changes: 6 additions & 0 deletions lib/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Spec, UsageErr> {
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -406,6 +410,7 @@ cmd "config" {
arg "value"
}
}
complete "file" run="ls"
"#,
)
.unwrap();
Expand All @@ -414,6 +419,7 @@ cmd "config" {
bin "usage"
flag "-f --force" global=true
arg "<arg1>"
complete "file" run="ls"
cmd "config" {
cmd "set" {
arg "<key>" help="Key to set"
Expand Down

0 comments on commit cb94d3d

Please sign in to comment.