Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.1.0: refactor app and cmd run and event logic #69

Merged
merged 25 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7206e9c
refactor: refact the app and cmd event handle logic
inhere Sep 4, 2022
55c2a8b
test: fix some event fire tests error
inhere Sep 4, 2022
78e8fdf
refactor: move the HelpVars to sub pkg helper
inhere Sep 4, 2022
41a4d39
wip: refactoring app and global options logic
inhere Sep 7, 2022
54b41a7
wip: refactoring app and cmd core context init logic
inhere Sep 7, 2022
f335cf8
wip: refactoring the app and cmd context logic
inhere Sep 8, 2022
fff4d8c
up: update some app run logic
inhere Sep 20, 2022
e5748f2
dep: update the gookit/goutil to v0.5.12
inhere Sep 20, 2022
963b35e
up: update some cmd add and init logic
inhere Sep 21, 2022
931b003
refactor: refactor the gflag parse to sub-pkg /gflag
inhere Sep 21, 2022
0b253e2
up: update some gflag and app run logic
inhere Sep 23, 2022
7322987
refactor: move all flag arguments manage logic to pkg /gflag
inhere Sep 23, 2022
7a3fd89
refactor: gflag - rename struct FlagMeta to Option
inhere Sep 26, 2022
01d0e0c
up: update the gOpts reset func logic, update some tests
inhere Sep 29, 2022
7fe4634
up: gflag - refactor and update some flag parse logic
inhere Sep 29, 2022
7a02863
up: update some docs and update some helper funcs
inhere Sep 29, 2022
4243004
chore: fix example run error and cmd help message error
inhere Sep 29, 2022
9feede0
refactor: gflag - refactor the gflag.Flags to Parser and CliOpts
inhere Sep 30, 2022
3479377
up: update some app and cmd method name, update some type name.
inhere Sep 30, 2022
3482598
up: update some for gflag parse and app init logic
inhere Sep 30, 2022
4c7ed4b
up: fix cmd init error, missing init cli parser
inhere Oct 3, 2022
08e163b
up: update some for flag parse and cmd init
inhere Oct 4, 2022
96aa894
up: update some app and cmd event fire logic
inhere Oct 4, 2022
1b510b3
test: fix cmd init event fire error and some test error
inhere Oct 4, 2022
31f80dd
up: update some tests and pkg readme docs
inhere Oct 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go_version: [1.18, 1.19]
go_version: [1.17, 1.18, 1.19]

steps:
- name: Check out codes
Expand All @@ -31,7 +31,7 @@ jobs:
go-version: ${{ matrix.go_version }}

- name: Revive check
uses: morphy2k/revive-action@v2.4.0
uses: morphy2k/revive-action@v2.4.1
if: ${{ matrix.os == 'ubuntu-latest' }}
with:
# Exclude patterns, separated by semicolons (optional)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Actions Status](https://github.com/gookit/gcli/workflows/action-tests/badge.svg)](https://github.com/gookit/gcli/actions)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/gcli)](https://github.com/gookit/gcli)
[![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)
[![GoDoc](https://godoc.org/github.com/gookit/gcli?status.svg)](https://pkg.go.dev/github.com/gookit/gcli/v3)
[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/goutil.svg)](https://pkg.go.dev/github.com/gookit/goutil)
[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/gcli)](https://goreportcard.com/report/github.com/gookit/gcli)
[![Coverage Status](https://coveralls.io/repos/github/gookit/gcli/badge.svg?branch=master)](https://coveralls.io/github/gookit/gcli?branch=master)

Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Actions Status](https://github.com/gookit/gcli/workflows/action-tests/badge.svg)](https://github.com/gookit/gcli/actions)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/gookit/gcli)](https://github.com/gookit/gcli)
[![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)
[![GoDoc](https://godoc.org/github.com/gookit/gcli?status.svg)](https://pkg.go.dev/github.com/gookit/gcli/v3)
[![Go Reference](https://pkg.go.dev/badge/github.com/gookit/goutil.svg)](https://pkg.go.dev/github.com/gookit/goutil)
[![Go Report Card](https://goreportcard.com/badge/github.com/gookit/gcli)](https://goreportcard.com/report/github.com/gookit/gcli)
[![Coverage Status](https://coveralls.io/repos/github/gookit/gcli/badge.svg?branch=master)](https://coveralls.io/github/gookit/gcli?branch=master)

Expand Down
26 changes: 19 additions & 7 deletions _examples/cliapp/main.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
package main

import (
"fmt"

"github.com/gookit/color"
"github.com/gookit/gcli/v3"
"github.com/gookit/gcli/v3/_examples/cmd"
"github.com/gookit/gcli/v3/builtin"
"github.com/gookit/gcli/v3/events"
// "github.com/gookit/gcli/v3/builtin/filewatcher"
// "github.com/gookit/gcli/v3/builtin/reverseproxy"
)

var customGOpt string

// local run:
//
// go run ./_examples/cliapp
// go build ./_examples/cliapp && ./cliapp
//
// run on windows(cmd, powerShell):
//
// go run ./_examples/cliapp
// go build ./_examples/cliapp && ./cliapp
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 ...any) bool {
app.On(gcli.EvtAppInit, func(ctx *gcli.HookCtx) bool {
// do something...
// fmt.Println("init app")
fmt.Println("init app event", ctx.Name())
return false
})

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

var customGOpt string
app.GOptsBinder = func(gf *gcli.Flags) {
// gcli.Logf(gcli.VerbInfo, "custom add and global option flag")
gf.StrVar(&customGOpt, &gcli.FlagMeta{Name: "custom", Desc: "desc message for the option"})
}
// app.BeforeAddOpts = func(opts *gcli.Flags) {
// opts.StrVar(&customGOpt, &gcli.FlagMeta{Name: "custom", Desc: "desc message for the option"})
// }

app.On(events.OnAppBindOptsAfter, func(ctx *gcli.HookCtx) (stop bool) {
ctx.App.Flags().StrVar(&customGOpt, &gcli.FlagMeta{
Name: "custom",
Desc: "desc message for the option",
})
return false
})

// app.Strict = true
app.Add(cmd.GitCmd)
Expand Down
5 changes: 3 additions & 2 deletions _examples/cmd/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/gookit/goutil/dump"
)

// The string flag list, implemented flag.Value interface
// Names The string flag list, implemented flag.Value interface
type Names []string

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

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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions any.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !go1.18
// +build !go1.18

package gcli

// alias of interface{}, use for go < 1.18
type any = interface{}
Loading