github.com/anjalikarhana/fabric@v2.1.1+incompatible/integration/nwo/command.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package nwo 8 9 import ( 10 "os" 11 "os/exec" 12 ) 13 14 type Command interface { 15 Args() []string 16 SessionName() string 17 } 18 19 type Enver interface { 20 Env() []string 21 } 22 23 type WorkingDirer interface { 24 WorkingDir() string 25 } 26 27 func ConnectsToOrderer(c Command) bool { 28 for _, arg := range c.Args() { 29 if arg == "--orderer" { 30 return true 31 } 32 } 33 return false 34 } 35 36 func ClientAuthEnabled(c Command) bool { 37 for _, arg := range c.Args() { 38 if arg == "--clientauth" { 39 return true 40 } 41 } 42 return false 43 } 44 45 func NewCommand(path string, command Command) *exec.Cmd { 46 cmd := exec.Command(path, command.Args()...) 47 cmd.Env = os.Environ() 48 if ce, ok := command.(Enver); ok { 49 cmd.Env = append(cmd.Env, ce.Env()...) 50 } 51 if wd, ok := command.(WorkingDirer); ok { 52 cmd.Dir = wd.WorkingDir() 53 } 54 return cmd 55 }