From ca14fdc5a130579cc8311126ac6ba8d40836cc37 Mon Sep 17 00:00:00 2001 From: Alfarih Faza Date: Mon, 3 Jan 2022 10:31:19 +0700 Subject: [PATCH] feat: added GetOptArg --- args.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 args.go diff --git a/args.go b/args.go new file mode 100644 index 0000000..3ad0bb8 --- /dev/null +++ b/args.go @@ -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 +}