aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd-target.go66
-rw-r--r--utils.go2
2 files changed, 34 insertions, 34 deletions
diff --git a/cmd-target.go b/cmd-target.go
index 688aef6..db97e91 100644
--- a/cmd-target.go
+++ b/cmd-target.go
@@ -471,50 +471,50 @@ func TerminalSendSignal(tgt *xaapiv1.TargetConfig, term *xaapiv1.TerminalConfig,
// GetTargetAndTerminalIDs Retrieve Target and Terminal definition from IDs
func GetTargetAndTerminalIDs(ctx *cli.Context, useFirstFree bool) (*xaapiv1.TargetConfig, *xaapiv1.TerminalConfig, error) {
- idArg := ctx.String("id")
- tidArg := GetIDName(ctx, "termId")
- if tidArg == "" {
- tidArg = GetIDName(ctx, "tid")
- }
- if idArg == "" && tidArg == "" {
- return nil, nil, fmt.Errorf("id or termId argument must be set")
- }
-
tgts := []xaapiv1.TargetConfig{}
if err := TargetsListGet(&tgts); err != nil {
return nil, nil, err
}
- matching := 0
- ti := 0
- tj := 0
- for ii, tt := range tgts {
- for jj, ttm := range tt.Terms {
- if idArg == "" && compareID(ttm.ID, tidArg) {
- ti = ii
- tj = jj
- matching++
- }
- if idArg != "" && compareID(tt.ID, idArg) && compareID(ttm.ID, tidArg) {
- ti = ii
- tj = jj
- matching++
+ idArg := ctx.String("id")
+ tidArg := ctx.String("termId")
+ if tidArg == "" {
+ tidArg = ctx.String("tid")
+ }
+ if idArg != "" || tidArg != "" {
+ matching := 0
+ ti := 0
+ tj := 0
+ for ii, tt := range tgts {
+ for jj, ttm := range tt.Terms {
+ if idArg == "" && compareID(ttm.ID, tidArg) {
+ ti = ii
+ tj = jj
+ matching++
+ }
+ if idArg != "" && compareID(tt.ID, idArg) && compareID(ttm.ID, tidArg) {
+ ti = ii
+ tj = jj
+ matching++
+ }
}
}
- }
- if matching > 1 {
- return nil, nil, fmt.Errorf("Multiple IDs found, please set -id and -tid with full ID notation")
- } else if matching == 1 {
- return &tgts[ti], &tgts[ti].Terms[tj], nil
+ if matching > 1 {
+ return nil, nil, fmt.Errorf("Multiple IDs found, please set -id and -tid with full ID notation")
+ } else if matching == 1 {
+ return &tgts[ti], &tgts[ti].Terms[tj], nil
+ }
}
// Allow to create a new terminal when only target id is set
idArg = GetIDName(ctx, "id")
- if idArg != "" {
- for _, tt := range tgts {
- if compareID(tt.ID, idArg) {
- return &tt, nil, nil
- }
+ if idArg == "" {
+ return nil, nil, fmt.Errorf("id or termId argument must be set")
+ }
+
+ for _, tt := range tgts {
+ if compareID(tt.ID, idArg) {
+ return &tt, nil, nil
}
}
diff --git a/utils.go b/utils.go
index 0ca6471..393ee2a 100644
--- a/utils.go
+++ b/utils.go
@@ -150,5 +150,5 @@ func Confirm(question 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)
}