Add todo to zsh and add powershell base
This commit is contained in:
parent
b4d610e5fd
commit
a573f722af
|
@ -9,11 +9,23 @@ import (
|
||||||
|
|
||||||
func WritePowerShellCompletions(out io.Writer, rootCmd *Command) error {
|
func WritePowerShellCompletions(out io.Writer, rootCmd *Command) error {
|
||||||
return powerShellTpl.Execute(out, map[string]any{
|
return powerShellTpl.Execute(out, map[string]any{
|
||||||
"rootCmd": rootCmd,
|
"RootCmd": rootCmd,
|
||||||
"globalOpts": opt.Globals(),
|
"GlobalOpts": opt.Globals(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var powerShellTpl = template.Must(template.New("PowerShell").Parse(`
|
var powerShellTpl = template.Must(template.New("PowerShell").Funcs(tplFuncs).Parse(`
|
||||||
|
{{- $rootCmd := .RootCmd -}}
|
||||||
|
{{- $progName := $rootCmd.Name -}}
|
||||||
|
{{- $varName := $rootCmd.Name | camel -}}
|
||||||
|
|
||||||
|
[scriptblock]$__{{ $varName }}CompleterBlock = {
|
||||||
|
param(
|
||||||
|
$WordToComplete,
|
||||||
|
$CommandAst,
|
||||||
|
$CursorPosition
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Register-ArgumentCompleter -CommandName {{ $progName }} -ScriptBlock $__{{ $varName }}CompleterBlock
|
||||||
`))
|
`))
|
||||||
|
|
|
@ -15,6 +15,7 @@ func WriteZshCompletions(out io.Writer, rootCmd *Command) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fix indentation and other spacing
|
// TODO: Fix indentation and other spacing
|
||||||
|
// TODO: Implement global options
|
||||||
var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
||||||
{{- $rootCmd := .RootCmd -}}
|
{{- $rootCmd := .RootCmd -}}
|
||||||
{{- $progName := $rootCmd.Name -}}
|
{{- $progName := $rootCmd.Name -}}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
||||||
module go.fifitido.net/cmd
|
module go.fifitido.net/cmd
|
||||||
|
|
||||||
go 1.21.3
|
go 1.21.3
|
||||||
|
|
||||||
|
require github.com/iancoleman/strcase v0.3.0
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
|
||||||
|
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
14
tpl_funcs.go
14
tpl_funcs.go
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/iancoleman/strcase"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tplFuncs = template.FuncMap{
|
var tplFuncs = template.FuncMap{
|
||||||
|
@ -19,6 +21,8 @@ var tplFuncs = template.FuncMap{
|
||||||
"sub": tplSub,
|
"sub": tplSub,
|
||||||
"dec": tplDec,
|
"dec": tplDec,
|
||||||
"mult": tplMult,
|
"mult": tplMult,
|
||||||
|
"pascal": tplPascal,
|
||||||
|
"camel": tplCamel,
|
||||||
}
|
}
|
||||||
|
|
||||||
func tplMap(vals ...any) (map[string]any, error) {
|
func tplMap(vals ...any) (map[string]any, error) {
|
||||||
|
@ -42,7 +46,7 @@ func tplJoin(strs []string, sep string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func tplUnder(s string) string {
|
func tplUnder(s string) string {
|
||||||
return strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(s, " ", "_"), "-", "_"))
|
return strcase.ToSnake(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tplVarPrefix(s string) string {
|
func tplVarPrefix(s string) string {
|
||||||
|
@ -80,3 +84,11 @@ func tplDec(i int) int {
|
||||||
func tplMult(a, b int) int {
|
func tplMult(a, b int) int {
|
||||||
return a * b
|
return a * b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tplPascal(s string) string {
|
||||||
|
return strcase.ToCamel(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tplCamel(s string) string {
|
||||||
|
return strcase.ToLowerCamel(s)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue