From 7c82fa3f9aae1d80b1d20b4aeac3f37eb9eb952c Mon Sep 17 00:00:00 2001 From: rsteube Date: Sat, 14 Sep 2024 14:56:43 +0200 Subject: [PATCH] ActionMacro: support format --- action.go | 5 ++++- macro.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/action.go b/action.go index a9e3ffb..4d9765f 100644 --- a/action.go +++ b/action.go @@ -58,8 +58,11 @@ func executable() string { } // ActionMacro completes given macro -func ActionMacro(s string) carapace.Action { +func ActionMacro(s string, a ...any) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if len(a) > 0 { + s = fmt.Sprintf(s, a...) + } r := regexp.MustCompile(`^\$(?P[^(]*)(\((?P.*)\))?$`) matches := r.FindStringSubmatch(s) if matches == nil { diff --git a/macro.go b/macro.go index a6f9e0f..41e20f3 100644 --- a/macro.go +++ b/macro.go @@ -34,7 +34,7 @@ func AddMacro(s string, m Macro) { func MacroN(f func() carapace.Action) Macro { return Macro{ - macro: macro.MacroN[carapace.Action](func() (*carapace.Action, error) { + macro: macro.MacroN(func() (*carapace.Action, error) { a := f() return &a, nil }), @@ -43,7 +43,7 @@ func MacroN(f func() carapace.Action) Macro { func MacroI[T any](f func(t T) carapace.Action) Macro { return Macro{ - macro: macro.MacroI[T, carapace.Action](func(t T) (*carapace.Action, error) { + macro: macro.MacroI(func(t T) (*carapace.Action, error) { a := f(t) return &a, nil }), @@ -52,7 +52,7 @@ func MacroI[T any](f func(t T) carapace.Action) Macro { func MacroV[T any](f func(t ...T) carapace.Action) Macro { return Macro{ - macro: macro.MacroV[T, carapace.Action](func(t ...T) (*carapace.Action, error) { + macro: macro.MacroV(func(t ...T) (*carapace.Action, error) { a := f(t...) return &a, nil }),