leaanthony / clir Goto Github PK
View Code? Open in Web Editor NEWA Simple and Clear CLI library. Dependency free.
License: MIT License
A Simple and Clear CLI library. Dependency free.
License: MIT License
Hey,
your package looks promising in my eyes, I especially like the logo. However it is not clear to me, what the benefits of this yet-another-CLI-framework™ in comparsion to other cli-frameworks like commandeer or cobra are. Could you explain them a little bit?
Would be really nice. I recently started working on a wails project, which uses this library for its cli. It would be nice to have clir automatically generate a bash completion script. From my quick glance at the source, a modified copy of the PrintHelp function could do the job.
Hi guys,
We are currently evaluating a CLI utility to use with goxygen (a generator of web projects). I like the idea of a light-weight CLI utility that is straight forward and doesn't bring unneeded dependencies. That's why I thought we could try Clir. But I went through the Clirs documentation/examples and I can't figure out if it is capable of covering our use-case.
Soon we'll have to implement something like this:
goxygen init --frontend angular --db mysql my-new-app
or
goxygen init --frontend=angular --db=mysql my-new-app
The options for the flags would have to be validated against a predefined set of parameters. Say for the --frontend
flag the options could only be angular
,react
and vue
, etc.
Q: Can you please tell me if we can achieve this with Clir? Or how much of it can already be handled by the lib?
Thank you.
Best regards,
Sasha.
package main
import (
"fmt"
"github.com/leaanthony/clir"
)
func main() {
cli := clir.NewCli("test", "Test", "v0.0.0")
s := cli.NewSubCommand("sub", "Desc")
var f string
s.StringFlag("f", "De", &f)
s.Action(func() error {
fmt.Println(f)
return nil
})
cli.Run()
}
go run main.go sub file -help
test v0.0.0 - Test
test sub - Desc
Flags:
-f string
De
-help
Get help on the 'test sub' command.
It seems that if the additional argument is provided after the flags it just works fine. However I don't consider this a viable solution. Now I can see some parallels to #9.
I am going to address this in a PR.
Is it possible to pass arguments to the cli?
E.g. I have a command like cli create test
and I'd like the create cmd know that it has to create something named e.g. test.
Hello,
does clir support it to make for each command one file or do I have to write my own little hack?
As it stands the behaviour of the library when user inputs undefined flags is to print a. the error b. help.
While the above described approach is thoughtful default behaviour and I could achieve parity with say kubectl
or docker
or git
for non existent commands like so
cli.Action(func() error {
w := cli.OtherArgs()
return fmt.Errorf(`unknown command %q for %q
Run '%[2]s --help' for usage`, w[0], cli.Name())
})
if err := cli.Run(); err != nil {
fmt.Printf("Error: %s\n", err)
}
$ go run ./cmd/pilates wrong
Error: unknown command "wrong" for "pilates"
Run 'pilates --help' for usage
if I attempt to run $ go run ./cmd/pilates -w
I can not suppress the help being printed or return custom messages. Maybe worse the error is hardcoded so I end up with the error printed twice without me being able to stop it.
$ go run ./cmd/pilates -w
Error: flag provided but not defined: -w <--- #1
Pilates
v0.0.1 - Ultimate Pilates Machine
Flags:
-help
Get help on the 'pilates' command.
Error: flag provided but not defined: -w <--- #2
a. have an option to suppress printing help on undefined flags.
cli.SuppresHelp()
b. custom undefined flag errors. Return golang err followed by a custom error message. examples:
$ git -w
unknown option: -w
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
or
$ kubectl -w
Error: unknown shorthand flag: 'w' in -w
See 'kubectl --help' for usage.
c. fix what seems to be buggy behaviour in line 83 command.go
by removing the fmt.Print.
Line 83 in 3b847b2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.