mkideal / cli

CLI - A package for building command line app with go
MIT License
730 stars 43 forks source link

Verbose option #26

Closed suntong closed 8 years ago

suntong commented 8 years ago

Can cli provide the accumulative option like what ssh does for verbose?

I.e., the more -v are specified on the command line, the more verbose it will be. This will be good for other purpose like debug as well. So far my code look like this:

       Verbose      int          `cli:"v,verbose"usage:"Be verbose (with level 1 & 2)"`

To use it, I have to specify -v 1 or -v 2, a little bit inconvenient than specifying -v or -v -v.

Thanks

mkideal commented 8 years ago

Ok, but it will take a little bit of time.

suntong commented 8 years ago

NP. Just a wish that I might have it some day. No rush.

mkideal commented 8 years ago

See commit c86f2c0 and example 030

package main

import (
    "github.com/mkideal/cli"
)

type argT struct {
    cli.Helper
    V cli.Counter `cli:"v" usage:"count verbose"`
}

func main() {
    cli.Run(new(argT), func(ctx *cli.Context) error {
        argv := ctx.Argv().(*argT)
        ctx.String("v=%d\n", argv.V.Value())
        return nil
    })
}
$ go run main.go -v
v=1
$ go run main.go -vv
v=2
$ go run main.go -v -v
v=2
suntong commented 8 years ago

:+1: