Skip to content

Commit

Permalink
up: update some tests and pkg readme docs
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 16, 2022
1 parent 1b510b3 commit 31f80dd
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 20 deletions.
8 changes: 1 addition & 7 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ import (
* CLI application
*************************************************************/

// Commander interface
type Commander interface {
Value(string) (any, bool)
SetValue(string, any)
}

// Handler interface definition
type Handler interface {
// Creator for create new command
Expand Down Expand Up @@ -95,7 +89,7 @@ func New(fns ...func(app *App)) *App {
// // Or with a config func
// NewApp(func(a *App) {
// // do something before init ....
// a.Hooks[events.OnAppInit] = func () {}
// a.Hooks[events.OnAppInitAfter] = func () {}
// })
func NewApp(fns ...func(app *App)) *App {
app := &App{
Expand Down
3 changes: 1 addition & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,8 @@ func TestApp_showCommandTips(t *testing.T) {
// assert.False(t, app.IsCommand("cmd1"))
// }

func TestApp_AddCommander(t *testing.T) {
func TestApp_AddHandler(t *testing.T) {
app := gcli.NewApp()

app.AddHandler(&UserCommand{})

assert.True(t, app.HasCommand("test"))
Expand Down
6 changes: 3 additions & 3 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func TestApp_Hooks_EvtAppInit(t *testing.T) {
buf.Reset()

cli := newNotExitApp()
cli.On(events.OnAppInit, func(ctx *gcli.HookCtx) bool {
buf.WriteString("trigger " + events.OnAppInit)
cli.On(events.OnAppInitAfter, func(ctx *gcli.HookCtx) bool {
buf.WriteString("trigger " + ctx.Name())
return false
})
cli.Add(simpleCmd)
assert.Eq(t, "trigger "+events.OnAppInit, buf.String())
assert.Eq(t, "trigger "+events.OnAppInitAfter, buf.String())

buf.Reset()
cli.On(events.OnGlobalOptsParsed, func(ctx *gcli.HookCtx) bool {
Expand Down
9 changes: 3 additions & 6 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const (
OnAppInitBefore = "app.init.before"
// OnAppInitAfter On app init after
OnAppInitAfter = "app.init.after"
// OnAppInit event
// Deprecated: please use OnAppInitAfter
OnAppInit = OnAppInitAfter
// OnAppStop = "app.stopped"

// OnAppBindOptsBefore bind app options
Expand Down Expand Up @@ -37,14 +34,14 @@ const (
OnCmdInitBefore = "cmd.init.before"
OnCmdInitAfter = "cmd.init.after"

// OnCmdNotFound app or sub command not found.
// OnCmdNotFound on app-command or subcommand not found.
//
// Data:
// {name: command-name}
OnCmdNotFound = "cmd.not.found"
// OnAppCmdNotFound app command not found
// OnAppCmdNotFound on app command not found
OnAppCmdNotFound = "app.cmd.not.found"
// OnCmdSubNotFound sub command not found
// OnCmdSubNotFound on subcommand not found
OnCmdSubNotFound = "cmd.sub.not.found"

// OnCmdOptParsed event
Expand Down
35 changes: 35 additions & 0 deletions gflag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Gflag

`gflag` provide command line options and arguments binding, parse, management.

## GoDoc

Please see https://pkg.go.dev/github.com/gookit/gcli/v2/gflag

## Install

```shell
go get github.com/gookit/gcli/v2/gflag
```

## Usage

```go
package main

import (
"fmt"

"github.com/gookit/gcli/v2/gflag"
)

func main() {
gf := gflag.New("testFlags")
gf.SetHandle(func(p *gflag.Parser) error {
fmt.Println(p.Name())
return nil
})

gf.Parse()
}
```
1 change: 1 addition & 0 deletions gflag/gflag.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package gflag provide command line options and arguments binding, parse, management.
package gflag

import (
Expand Down
10 changes: 10 additions & 0 deletions interact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ command-line interactive util methods
- `MultiSelect/Checkbox`
- `ReadPassword`

## GoDoc

Please see https://pkg.go.dev/github.com/gookit/gcli/v2/interact

## Install

```shell
go get github.com/gookit/gcli/v2/interact
```

## Select & Choice

Usage:
Expand Down
4 changes: 2 additions & 2 deletions progress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Package progress provide terminal progress bar display. Such as: `Txt`, `Bar`, `

## GoDoc

please see https://godoc.org/github.com/gookit/gcli/progress
Please see https://pkg.go.dev/github.com/gookit/gcli/v2/progress

## Install

```bash
go get -u github.com/gookit/gcli/v3
go get github.com/gookit/gcli/v3/progress
```

## Usage
Expand Down
10 changes: 10 additions & 0 deletions show/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ contains `section, panel, padding, helpPanel, table, tree, title, list, multiLis
- markdown
- json

## GoDoc

Please see https://pkg.go.dev/github.com/gookit/gcli/v2/show

## Install

```shell
go get github.com/gookit/gcli/v2/show
```

## Related

- https://github.com/InVisionApp/tabular
Expand Down

0 comments on commit 31f80dd

Please sign in to comment.