Compare commits

..

6 Commits
dev ... main

Author SHA1 Message Date
Evan Fiordeliso 160b3321ef Release v0.3.0 2023-11-16 23:02:14 -05:00
Evan Fiordeliso 1fbc94aa49 Release v0.2.4
- Implement the completion script for PowerShell
- Add global options to zsh completion script
2023-11-13 19:09:51 -05:00
Evan Fiordeliso c5bd7662f2 Release v0.2.3
- Implemented zsh autocomplete script generation
2023-11-13 17:17:29 -05:00
Evan Fiordeliso 81a1f6d97c Release v0.2.2 2023-11-13 13:43:33 -05:00
Evan Fiordeliso 349cdf01d6 Merge branch 'dev' 2023-11-13 00:50:24 -05:00
Evan Fiordeliso 9e5d7e2519 Update go.fifitido.net/cmd in hello world example 2023-11-12 17:27:39 -05:00
3 changed files with 14 additions and 34 deletions

2
go.mod
View File

@ -1,3 +1,5 @@
module go.fifitido.net/cmd
go 1.21.3
require github.com/iancoleman/strcase v0.3.0

2
go.sum
View File

@ -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=

View File

@ -2,9 +2,10 @@ package cmd
import (
"fmt"
"regexp"
"strings"
"text/template"
"github.com/iancoleman/strcase"
)
var tplFuncs = template.FuncMap{
@ -21,6 +22,7 @@ var tplFuncs = template.FuncMap{
"sub": tplSub,
"dec": tplDec,
"mult": tplMult,
"pascal": tplPascal,
"camel": tplCamel,
}
@ -49,19 +51,7 @@ func tplJoin(strs []string, sep string) string {
}
func tplUnder(s string) string {
// Remove all characters that are not alphanumeric or spaces or underscores
s = regexp.MustCompile("[^a-zA-Z0-9_ -]+").ReplaceAllString(s, "")
// Replace all spaces with underscores
s = strings.ReplaceAll(s, " ", "_")
// Replace all dashes with underscores
s = strings.ReplaceAll(s, "-", "_")
// Convert to lowercase
s = strings.ToLower(s)
return s
return strcase.ToSnake(s)
}
func tplVarPrefix(s string) string {
@ -100,24 +90,10 @@ func tplMult(a, b int) int {
return a * b
}
func tplCamel(s string) string {
// Remove all characters that are not alphanumeric or spaces or underscores
s = regexp.MustCompile("[^a-zA-Z0-9_ -]+").ReplaceAllString(s, "")
// Replace all underscores with spaces
s = strings.ReplaceAll(s, "_", " ")
// Replace all dashes with spaces
s = strings.ReplaceAll(s, "-", " ")
// Title case s
words := strings.Split(s, " ")
for i, word := range words {
words[i] = strings.ToTitle(word)
}
// Join words
s = strings.Join(words, "")
return s
func tplPascal(s string) string {
return strcase.ToCamel(s)
}
func tplCamel(s string) string {
return strcase.ToLowerCamel(s)
}