X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=utils.go;h=393ee2a21bb05d28108b4f2f0048adc4d034a670;hb=e0faa97416aee22fa0c09f75a4040bb2bb16e2dd;hp=afa0942071761e8bdcbe82250b8126058e05f42d;hpb=5ce05ccae810f532e73350a205b979faf2603235;p=src%2Fxds%2Fxds-cli.git diff --git a/utils.go b/utils.go index afa0942..393ee2a 100644 --- a/utils.go +++ b/utils.go @@ -123,7 +123,15 @@ func LogPost(format string, data interface{}) { // GetID Return a string ID set with --id option or as simple parameter func GetID(ctx *cli.Context) string { - id := ctx.String("id") + return GetIDName(ctx, "id") +} + +// GetIDName Return a string ID set with --XXX option or as simple parameter +func GetIDName(ctx *cli.Context, idName string) string { + if idName == "" { + return "" + } + id := ctx.String(idName) idArgs := ctx.Args().First() if id == "" && idArgs != "" { id = idArgs @@ -139,3 +147,8 @@ func Confirm(question string) bool { ans := strings.ToLower(strings.TrimSpace(answer)) return (ans == "y" || ans == "yes") } + +// compareID Compare an ID to a reference ID +func compareID(refID, ID string) bool { + return refID != "" && ID != "" && strings.HasPrefix(refID, ID) +}