Compare commits
3 Commits
d6e397cc10
...
v0.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
| ce84a374cc | |||
| 6842224b37 | |||
| 541886e9ad |
@@ -1,5 +1,5 @@
|
||||
# go-cli
|
||||
|
||||
[](https://pkg.go.dev/git.tebibyte.media/sashakoshka/cli)
|
||||
[](https://pkg.go.dev/git.tebibyte.media/sashakoshka/go-cli)
|
||||
|
||||
CLI module for Go programs.
|
||||
|
||||
7
cli.go
7
cli.go
@@ -81,6 +81,7 @@ func (this *Cli) Parse (args []string) (*Cli, error) {
|
||||
if len(args) > 0 { args = args[1:] }
|
||||
|
||||
next := func () string {
|
||||
if len(args) < 1 { return "" }
|
||||
args = args[1:]
|
||||
if len(args) > 0 {
|
||||
return args[0]
|
||||
@@ -168,7 +169,8 @@ func (this *Cli) ParseOrExit (args []string) *Cli {
|
||||
// was found, it returns true. If it was not found, it returns nil, false.
|
||||
func (this *Cli) ShortFlag (short rune) (*Flag, bool) {
|
||||
if short == 0 { return nil, false }
|
||||
for _, flag := range this.Flags {
|
||||
for index := len(this.Flags) - 1; index >= 0; index -- {
|
||||
flag := this.Flags[index]
|
||||
if flag.Short == short { return flag, true }
|
||||
}
|
||||
return nil, false
|
||||
@@ -178,7 +180,8 @@ func (this *Cli) ShortFlag (short rune) (*Flag, bool) {
|
||||
// was found, it returns true. If it was not found, it returns nil, false.
|
||||
func (this *Cli) LongFlag (long string) (*Flag, bool) {
|
||||
if long == "" { return nil, false }
|
||||
for _, flag := range this.Flags {
|
||||
for index := len(this.Flags) - 1; index >= 0; index -- {
|
||||
flag := this.Flags[index]
|
||||
if flag.Long == long { return flag, true }
|
||||
}
|
||||
return nil, false
|
||||
|
||||
Reference in New Issue
Block a user