Skip to content

Commit

Permalink
feat: added GetOptArg
Browse files Browse the repository at this point in the history
  • Loading branch information
alfarih31 committed Jan 3, 2022
1 parent 16a9901 commit ca14fdc
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package parser

func GetOptArg(opts []interface{}, defaultValue ...interface{}) interface{} {
var o interface{} = nil
if len(defaultValue) > 0 {
o = defaultValue[0]
}

if len(opts) > 0 {
o = opts[0]
}

return o
}

func GetOptIntArg(opts []int, defaultValue ...int) int {
var o = 0
if len(defaultValue) > 0 {
o = defaultValue[0]
}

if len(opts) > 0 {
o = opts[0]
}

return o
}

func GetOptBoolArg(opts []bool, defaultValue ...bool) bool {
var o = false
if len(defaultValue) > 0 {
o = defaultValue[0]
}

if len(opts) > 0 {
o = opts[0]
}

return o
}

func GetOptStringArg(opts []string, defaultValue ...string) string {
var o = ""
if len(defaultValue) > 0 {
o = defaultValue[0]
}

if len(opts) > 0 {
o = opts[0]
}

return o
}

0 comments on commit ca14fdc

Please # to comment.