Skip to content

Commit

Permalink
chore: prog,example - replace the interface{} to go1.18 any
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Sep 4, 2022
1 parent ff70ef3 commit 4e9980d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion _examples/cliapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
app := gcli.NewApp(func(app *gcli.App) {
app.Version = "3.0.0"
app.Desc = "this is my cli application"
app.On(gcli.EvtAppInit, func(data ...interface{}) bool {
app.On(gcli.EvtAppInit, func(data ...any) bool {
// do something...
// fmt.Println("init app")
return false
Expand Down
2 changes: 1 addition & 1 deletion _examples/cmd/env_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var EnvInfo = &gcli.Command{
Func: func(c *gcli.Command, _ []string) error {
eAble, _ := os.Executable()

data := map[string]interface{}{
data := map[string]any{
"os": runtime.GOOS,
"binName": c.BinName(),
"workDir": c.WorkDir(),
Expand Down
2 changes: 1 addition & 1 deletion _examples/cmd/git_pull_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var GitPullMulti = &gcli.Command{
true,
).
WithValue("./").
WithValidator(func(v interface{}) (i interface{}, e error) {
WithValidator(func(v any) (i any, e error) {
if !fsutil.IsDir(v.(string)) {
return nil, fmt.Errorf("the base path must be an exist dir")
}
Expand Down
4 changes: 2 additions & 2 deletions _examples/cmd/progress_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var pdOpts = struct {
maxSteps int
maxSteps int
overwrite, random bool

handlers map[string]func(int)
Expand All @@ -31,7 +31,7 @@ var ProgressDemo = &gcli.Command{
Desc: "progress bar type name. allow: bar,txt,dtxt,loading,roundTrip",

Required: true,
// Validator: func(val interface{}) (interface{}, error) {
// Validator: func(val any) (any, error) {
// name := val.(string)
// },
})
Expand Down
6 changes: 3 additions & 3 deletions builtin/gen_auto_complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func doGen(c *gcli.Command, _ []string) (err error) {
}

// color.Info.Tips("\n %+v\n", genOpts)
data := map[string]interface{}{
data := map[string]any{
"Shell": genOpts.shell,
"BinName": genOpts.binName,
"FileName": genOpts.output,
Expand Down Expand Up @@ -172,7 +172,7 @@ _complete_for_{{.BinName}} () {
complete -F _complete_for_{{.BinName}} {{.BinName}} {{.BinName}}.exe
`

func buildForBashShell(app *gcli.App, data map[string]interface{}) map[string]interface{} {
func buildForBashShell(app *gcli.App, data map[string]any) map[string]any {
var cNames []string

// {cmd name: opts}
Expand Down Expand Up @@ -264,7 +264,7 @@ compdef _complete_for_{{.BinName}} {{.BinName}}
compdef _complete_for_{{.BinName}} {{.BinName}}.exe
`

func buildForZshShell(app *gcli.App, data map[string]interface{}) map[string]interface{} {
func buildForZshShell(app *gcli.App, data map[string]any) map[string]any {
type opInfos []string

// {cmd name: cmd des}. in zsh eg: 'build[compile packages and dependencies]'
Expand Down
27 changes: 14 additions & 13 deletions builtin/sflag/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type ArgsParser struct {
// raw args length
length int
// parsed longs options. value allow: bool, string, array
longOpts map[string]interface{}
longOpts map[string]any
// parsed shorts options. value allow: bool, string, array
shortOpts map[string]interface{}
shortOpts map[string]any
// parsed arguments
args []string
}
Expand All @@ -58,8 +58,8 @@ func ParseArgs(args []string, boolOpts []string, arrayOpts []string) *ArgsParser
}

// Opts get parsed opts
func (p *ArgsParser) Opts() map[string]interface{} {
return map[string]interface{}{
func (p *ArgsParser) Opts() map[string]any {
return map[string]any{
"longs": p.longOpts,
"shorts": p.shortOpts,
}
Expand All @@ -84,8 +84,8 @@ func (p *ArgsParser) prepare() {
p.arrayOpts = p.flipSlice(p.ArrayOpts)
}

p.longOpts = make(map[string]interface{})
p.shortOpts = make(map[string]interface{})
p.longOpts = make(map[string]any)
p.shortOpts = make(map[string]any)
}

/*************************************************************
Expand All @@ -95,13 +95,14 @@ func (p *ArgsParser) prepare() {
// Parse args list to options
//
// Supports options format:
// -e // bool, short option
// -e <value> // short option
// -e=<value>
// -aux // multi short bool options
// --bool-opt // bool, lang option
// --long-opt <value> // lang option
// --long-opt=<value>
//
// -e // bool, short option
// -e <value> // short option
// -e=<value>
// -aux // multi short bool options
// --bool-opt // bool, lang option
// --long-opt <value> // lang option
// --long-opt=<value>
func (p *ArgsParser) Parse(args []string) {
p.rawArgs = args
p.prepare()
Expand Down
2 changes: 1 addition & 1 deletion builtin/sflag/value_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// ValueGetter struct
type ValueGetter struct {
// value store parsed argument data. (type: string, []string)
Value interface{}
Value any
// is array
Arrayed bool
}
Expand Down
2 changes: 1 addition & 1 deletion helper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
)

// RenderText render text template with data
func RenderText(input string, data interface{}, fns template.FuncMap, isFile ...bool) string {
func RenderText(input string, data any, fns template.FuncMap, isFile ...bool) string {
t := template.New("cli")
t.Funcs(template.FuncMap{
// don't escape content
Expand Down
11 changes: 6 additions & 5 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ type Progresser interface {
Advance(steps ...uint)
AdvanceTo(step uint)
Finish(msg ...string)
Bound() interface{}
Bound() any
}

// Progress definition
// Refer:
// https://github.com/inhere/php-console/blob/master/src/utils/ProgressBar.php
//
// https://github.com/inhere/php-console/blob/master/src/utils/ProgressBar.php
type Progress struct {
// Format string the bar format
Format string
Expand All @@ -52,7 +53,7 @@ type Progress struct {
// current step value
step uint
// bound user custom data.
bound interface{}
bound any
// mark start status
started bool
// completed percent. eg: "83.8"
Expand Down Expand Up @@ -139,13 +140,13 @@ func (p *Progress) WithMaxSteps(maxSteps ...int) *Progress {
}

// Binding user custom data to instance
func (p *Progress) Binding(data interface{}) *Progress {
func (p *Progress) Binding(data any) *Progress {
p.bound = data
return p
}

// Bound get bound sub struct instance
func (p *Progress) Bound() interface{} {
func (p *Progress) Bound() any {
return p.bound
}

Expand Down

0 comments on commit 4e9980d

Please sign in to comment.