Giter Club home page Giter Club logo

Comments (18)

mkideal avatar mkideal commented on June 2, 2024

How about if I add a NumOption like NumArg?

from cli.

suntong avatar suntong commented on June 2, 2024

Hmm... will it work even when all parameters should be provided as cli options? Oh, yeah, gotya, Yep, me too think it should work.

from cli.

mkideal avatar mkideal commented on June 2, 2024

NumOption is added.

from cli.

suntong avatar suntong commented on June 2, 2024

Thanks, send you some PM, to the one you listed on github.com.

from cli.

suntong avatar suntong commented on June 2, 2024

Documenting our conversation in PM, please take a look at

https://github.com/suntong/lang/blob/master/lang/Go/src/sys/CLI/027-global-redo/redoCmds.go#L119-L126

I.e.,

var publishCmd = &cli.Command{
    Name: "publish",
    Desc: "Publish the network application",
    Argv: func() interface{} { return new(publishT) },
    Fn:   publish,

    NumOption: cli.AtLeast(1),
}

The NumOption: cli.AtLeast(1) should work exactly as NumArg: cli.AtLeast(1). E.g.,
https://github.com/suntong/lang/blob/master/lang/Go/src/sys/CLI/027-global-redo/redoCmds.go#L98

However, their behavior are different:

$ redo install
Install the network application
...

$ redo publish 
ERR! required argument --dir missing

from cli.

mkideal avatar mkideal commented on June 2, 2024

Now, everything is OK, See commit 1ed3d0d

from cli.

suntong avatar suntong commented on June 2, 2024

Hmm.... redo publish still complains about required argument missing, but it does show usage first now:

$ redo publish 
Publish the network application

Options:

  -h, --help
      display help information
...
  -l, --list
      list all sub commands
ERR! required argument --dir missing

Can we get rid of that complaining, :-)?

from cli.

mkideal avatar mkideal commented on June 2, 2024

See commit 13e2fe4.

from cli.

suntong avatar suntong commented on June 2, 2024

Perfect! Thanks a lot for your hard works!

from cli.

suntong avatar suntong commented on June 2, 2024

Hi ไป•ๆ™‹,

Found a very strange error, please take a look at
https://gist.github.com/suntong/9b85f3f96f6d9333701ce4a78e3221b3#file-dump-go

This is what i got when run it:

$ go run /tmp/dump.go dump
ERR! required argument --input missing

What strange is I have my demo code working for this case --
https://gist.github.com/suntong/c387dffef76b02df85f18857cf11d66a

echo '{}' > redo.json

$ go run /tmp/027-global-redo.go install
Install the network application

Usage:
  redo install [Options] package [package...]
...

To me the two code are exactly the same:

var dumpDef = &cli.Command{
    Name: "dump",
    Desc: "*Dump as text-only file",
    Argv: func() interface{} { return new(dumpT) },
    Fn:   dumpCLI,

    NumArg:      cli.AtLeast(1),
    CanSubRoute: true,
}

func dumpCLI(ctx *cli.Context) error {
    rootArgv := ctx.RootArgv().(*rootT)
    argv := ctx.Argv().(*dumpT)
    fmt.Printf("[dump]:\n  %+v\n  %+v\n  %v\n", rootArgv, argv, ctx.Args())
    return nil
}
var installDef = &cli.Command{
    Name: "install",
    Desc: "Install the network application",
    Text: "Usage:\n  redo install [Options] package [package...]",
    Argv: func() interface{} { return new(installT) },
    Fn:   installCLI,

    NumArg:      cli.AtLeast(1),
    CanSubRoute: true,
}

func installCLI(ctx *cli.Context) error {
    rootArgv := ctx.RootArgv().(*rootT)
    argv := ctx.Argv().(*installT)
    fmt.Printf("[install]:\n  %+v\n  %+v\n  %v\n", rootArgv, argv, ctx.Args())
    return nil
}

So why the two behaves differently? Thx

from cli.

mkideal avatar mkideal commented on June 2, 2024
Dir    string `cli:"*d,dir" usage:"source code root dir" dft:"./"`

Note the dft tag. If dft tag is specified with a non-empty value, required argument have been present.

from cli.

suntong avatar suntong commented on June 2, 2024

Oh, that's where I forgot to change -- I should have removed it as mandatory options should not have default values.

So the behavior of dump.go would be the normal usage. In this case, when none-option parameters are needed, and they are less than NumArg, let's show usage help without complaining. Make sense? thx.

from cli.

mkideal avatar mkideal commented on June 2, 2024

See commit 7bfc6df

from cli.

suntong avatar suntong commented on June 2, 2024

Perfect! and super fast as always! ๐Ÿ‘

from cli.

suntong avatar suntong commented on June 2, 2024

Hi ไป•ๆ™‹,

Found another strange error, please take a look at
https://gist.github.com/suntong/fdd74049660315e54fa72ecb5fd2f04e

If I run it with go run /tmp/dump.go, the help output is OK.

However, if I change "NumArg: cli.AtLeast(1)" to "NumOption: cli.AtLeast(1)", and run it with go run /tmp/dump.go, it complains about required argument missing again:

$ go run /tmp/dump.go 
ERR! required argument --input missing

Moreover, another problem, I remember that the *clix.Reader will read from stdin if file is not specified, but mine is not:

$ go run /tmp/dump.go -i
ERR! option -i invalid: missing argument

How can I correct it? Thx.

from cli.

mkideal avatar mkideal commented on June 2, 2024

Eh..., I run it with NumOption: cli.AtLeast(1), but the help output is OK.

from cli.

mkideal avatar mkideal commented on June 2, 2024

Maybe you should update cli

from cli.

suntong avatar suntong commented on June 2, 2024

Oh, my bad, my home env is not properly setup as my work env. My bad, sorry.

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.