Skip to content

Commit 78f08ea

Browse files
authored
Merge pull request #69 from gookit/dev
2 parents 3d6cf1f + 31f80dd commit 78f08ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2851
-2370
lines changed

.github/workflows/go.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
21-
go_version: [1.18, 1.19]
21+
go_version: [1.17, 1.18, 1.19]
2222

2323
steps:
2424
- name: Check out codes
@@ -31,7 +31,7 @@ jobs:
3131
go-version: ${{ matrix.go_version }}
3232

3333
- name: Revive check
34-
uses: morphy2k/[email protected].0
34+
uses: morphy2k/[email protected].1
3535
if: ${{ matrix.os == 'ubuntu-latest' }}
3636
with:
3737
# Exclude patterns, separated by semicolons (optional)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Actions Status](https://github.com/gookit/gcli/workflows/action-tests/badge.svg)](https://github.com/gookit/gcli/actions)
55
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/gcli)](https://github.com/gookit/gcli)
66
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/4f071e6858fb4117b6c1376c9316d8ef)](https://www.codacy.com/gh/gookit/gcli/dashboard?utm_source=github.com&utm_medium=referral&utm_content=gookit/gcli&utm_campaign=Badge_Grade)
7-
[![GoDoc](https://godoc.org/github.com/gookit/gcli?status.svg)](https://pkg.go.dev/github.com/gookit/gcli/v3)
7+
[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/goutil.svg)](https://pkg.go.dev/github.com/gookit/goutil)
88
[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/gcli)](https://goreportcard.com/report/github.com/gookit/gcli)
99
[![Coverage Status](https://coveralls.io/repos/github/gookit/gcli/badge.svg?branch=master)](https://coveralls.io/github/gookit/gcli?branch=master)
1010

README.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Actions Status](https://github.com/gookit/gcli/workflows/action-tests/badge.svg)](https://github.com/gookit/gcli/actions)
55
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/gcli)](https://github.com/gookit/gcli)
66
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/4f071e6858fb4117b6c1376c9316d8ef)](https://www.codacy.com/gh/gookit/gcli/dashboard?utm_source=github.com&utm_medium=referral&utm_content=gookit/gcli&utm_campaign=Badge_Grade)
7-
[![GoDoc](https://godoc.org/github.com/gookit/gcli?status.svg)](https://pkg.go.dev/github.com/gookit/gcli/v3)
7+
[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/goutil.svg)](https://pkg.go.dev/github.com/gookit/goutil)
88
[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/gcli)](https://goreportcard.com/report/github.com/gookit/gcli)
99
[![Coverage Status](https://coveralls.io/repos/github/gookit/gcli/badge.svg?branch=master)](https://coveralls.io/github/gookit/gcli?branch=master)
1010

_examples/cliapp/main.go

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
package main
22

33
import (
4+
"fmt"
5+
46
"github.com/gookit/color"
57
"github.com/gookit/gcli/v3"
68
"github.com/gookit/gcli/v3/_examples/cmd"
79
"github.com/gookit/gcli/v3/builtin"
10+
"github.com/gookit/gcli/v3/events"
811
// "github.com/gookit/gcli/v3/builtin/filewatcher"
912
// "github.com/gookit/gcli/v3/builtin/reverseproxy"
1013
)
1114

15+
var customGOpt string
16+
1217
// local run:
1318
//
1419
// go run ./_examples/cliapp
1520
// go build ./_examples/cliapp && ./cliapp
1621
//
1722
// run on windows(cmd, powerShell):
1823
//
24+
// go run ./_examples/cliapp
1925
// go build ./_examples/cliapp && ./cliapp
2026
func main() {
2127
app := gcli.NewApp(func(app *gcli.App) {
2228
app.Version = "3.0.0"
2329
app.Desc = "this is my cli application"
24-
app.On(gcli.EvtAppInit, func(data ...any) bool {
30+
app.On(gcli.EvtAppInit, func(ctx *gcli.HookCtx) bool {
2531
// do something...
26-
// fmt.Println("init app")
32+
fmt.Println("init app event", ctx.Name())
2733
return false
2834
})
2935

@@ -40,11 +46,17 @@ func main() {
4046
// disable global options
4147
// gcli.GOpts().SetDisable()
4248

43-
var customGOpt string
44-
app.GOptsBinder = func(gf *gcli.Flags) {
45-
// gcli.Logf(gcli.VerbInfo, "custom add and global option flag")
46-
gf.StrVar(&customGOpt, &gcli.FlagMeta{Name: "custom", Desc: "desc message for the option"})
47-
}
49+
// app.BeforeAddOpts = func(opts *gcli.Flags) {
50+
// opts.StrVar(&customGOpt, &gcli.FlagMeta{Name: "custom", Desc: "desc message for the option"})
51+
// }
52+
53+
app.On(events.OnAppBindOptsAfter, func(ctx *gcli.HookCtx) (stop bool) {
54+
ctx.App.Flags().StrVar(&customGOpt, &gcli.FlagMeta{
55+
Name: "custom",
56+
Desc: "desc message for the option",
57+
})
58+
return false
59+
})
4860

4961
// app.Strict = true
5062
app.Add(cmd.GitCmd)

_examples/cmd/example.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/gookit/goutil/dump"
99
)
1010

11-
// The string flag list, implemented flag.Value interface
11+
// Names The string flag list, implemented flag.Value interface
1212
type Names []string
1313

1414
func (ns *Names) String() string {
@@ -64,7 +64,8 @@ var Example = &gcli.Command{
6464

6565
// command running
6666
// example run:
67-
// go run ./_examples/cliapp.go ex -c some.txt -d ./dir --id 34 -n tom -n john val0 val1 val2 arrVal0 arrVal1 arrVal2
67+
//
68+
// go run ./_examples/cliapp.go ex -c some.txt -d ./dir --id 34 -n tom -n john val0 val1 val2 arrVal0 arrVal1 arrVal2
6869
func exampleExecute(c *gcli.Command, args []string) error {
6970
color.Infoln("hello, in example command")
7071

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

any.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !go1.18
2+
// +build !go1.18
3+
4+
package gcli
5+
6+
// alias of interface{}, use for go < 1.18
7+
type any = interface{}

0 commit comments

Comments
 (0)