Code Review
/
src
/
xds
/
xds-cli.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Add gitreview file for Lucky Lamprey branch
[src/xds/xds-cli.git]
/
utils.go
diff --git
a/utils.go
b/utils.go
index
0ca6471
..
dc5cb57
100644
(file)
--- a/
utils.go
+++ b/
utils.go
@@
-21,6
+21,7
@@
package main
import (
"encoding/json"
"fmt"
import (
"encoding/json"
"fmt"
+ "os"
"sort"
"strconv"
"strings"
"sort"
"strconv"
"strings"
@@
-122,18
+123,27
@@
func LogPost(format string, data interface{}) {
}
// GetID Return a string ID set with --id option or as simple parameter
}
// GetID Return a string ID set with --id option or as simple parameter
-func GetID(ctx *cli.Context) string {
- return GetIDName(ctx, "id")
+func GetID(ctx *cli.Context
, idEnvVarName string
) string {
+ return GetIDName(ctx, "id"
, idEnvVarName
)
}
// GetIDName Return a string ID set with --XXX option or as simple parameter
}
// GetIDName Return a string ID set with --XXX option or as simple parameter
-func GetIDName(ctx *cli.Context, idName string) string {
+func GetIDName(ctx *cli.Context, idName
, idEnvVarName
string) string {
if idName == "" {
return ""
}
if idName == "" {
return ""
}
+
+ // Get id set using option --id
id := ctx.String(idName)
id := ctx.String(idName)
+
+ // Check if id has been set using env variable
+ envSdkid, _ := os.LookupEnv(idEnvVarName)
+
+ // Support as 1st arg without --id option string (for example xds-cli sdk install 123456)
idArgs := ctx.Args().First()
idArgs := ctx.Args().First()
- if id == "" && idArgs != "" {
+
+ // Set or overwrite id using first arg (knowing that 1st is overwrite env variable)
+ if (id == "" && idArgs != "") || (envSdkid != "" && idArgs != "") {
id = idArgs
}
return id
id = idArgs
}
return id
@@
-150,5
+160,5
@@
func Confirm(question string) bool {
// compareID Compare an ID to a reference ID
func compareID(refID, ID string) bool {
// compareID Compare an ID to a reference ID
func compareID(refID, ID string) bool {
- return refID != "" && ID != "" && strings.
Contains
(refID, ID)
+ return refID != "" && ID != "" && strings.
HasPrefix
(refID, ID)
}
}