Comments (18)
How about if I add a NumOption
like NumArg
?
from cli.
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.
NumOption
is added.
from cli.
Thanks, send you some PM, to the one you listed on github.com.
from cli.
Documenting our conversation in PM, please take a look at
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.
Now, everything is OK, See commit 1ed3d0d
from cli.
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.
See commit 13e2fe4.
from cli.
Perfect! Thanks a lot for your hard works!
from cli.
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.
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.
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.
See commit 7bfc6df
from cli.
Perfect! and super fast as always! ๐
from cli.
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.
Eh..., I run it with NumOption: cli.AtLeast(1)
, but the help output is OK.
from cli.
Maybe you should update cli
from cli.
Oh, my bad, my home env is not properly setup as my work env. My bad, sorry.
from cli.
Related Issues (20)
- Reader read from url HOT 2
- How to add default flag for jsonfile? HOT 4
- Add support for url.URL argument type HOT 7
- Simplify access to nested args HOT 3
- Publish new release please HOT 4
- Self config allows to go with the executable file HOT 5
- Excessive spacing with defaults when in NormalStyle HOT 19
- Terminate with non-zero exit code in case of an error HOT 2
- Something went wrong with dep HOT 6
- This project is now dormant, but there is a new forked repo HOT 8
- Catching up HOT 1
- Need separator to arrange parameters in groups HOT 4
- Need to loosen the tight control of the config name HOT 14
- When decoding Time with empty string, toggle IsSet HOT 1
- dft not accepting '$' value HOT 2
- Printing self help HOT 5
- Command alias HOT 4
- IsSet always returns false HOT 3
- Default value incorrect when printing usage
- Default arguments from embedded struct not realised HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli.