github.com/kubeshop/testkube@v1.17.23/cmd/tcl/testworkflow-toolkit/commands/utils.go (about) 1 // Copyright 2024 Testkube. 2 // 3 // Licensed as a Testkube Pro file under the Testkube Community 4 // License (the "License"); you may not use this file except in compliance with 5 // the License. You may obtain a copy of the License at 6 // 7 // https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt 8 9 package commands 10 11 import ( 12 "os" 13 "os/exec" 14 "strconv" 15 ) 16 17 func concat(args ...interface{}) []string { 18 result := make([]string, 0) 19 for _, a := range args { 20 switch a.(type) { 21 case string: 22 result = append(result, a.(string)) 23 case int: 24 result = append(result, strconv.Itoa(a.(int))) 25 case []string: 26 result = append(result, a.([]string)...) 27 case []interface{}: 28 result = append(result, concat(a.([]interface{})...)...) 29 } 30 } 31 return result 32 } 33 34 func Comm(cmd string, args ...interface{}) *exec.Cmd { 35 return exec.Command(cmd, concat(args...)...) 36 } 37 38 func Run(c string, args ...interface{}) error { 39 sub := Comm(c, args...) 40 sub.Stdout = os.Stdout 41 sub.Stderr = os.Stderr 42 return sub.Run() 43 }