summaryrefslogtreecommitdiffstats
path: root/cmd-target.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-target.go')
-rw-r--r--cmd-target.go66
1 files changed, 33 insertions, 33 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
}
}