github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/internal/pkg/inputprocessor/action/tool/flagsparser.go (about) 1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tool 16 17 import ( 18 "context" 19 "fmt" 20 21 "github.com/bazelbuild/reclient/internal/pkg/inputprocessor/flags" 22 ) 23 24 // parseFlags is used to parse the flags in a tool invocation command. 25 func parseFlags(ctx context.Context, command []string, workingDir, execRoot string) (*flags.CommandFlags, error) { 26 numArgs := len(command) 27 if numArgs < 1 { 28 return nil, fmt.Errorf("insufficient number of arguments in command: %v", command) 29 } 30 31 res := &flags.CommandFlags{ 32 WorkingDirectory: workingDir, 33 ExecRoot: execRoot, 34 ExecutablePath: command[0], 35 } 36 for _, arg := range command[1:] { 37 res.Flags = append(res.Flags, &flags.Flag{Value: arg}) 38 } 39 return res, nil 40 }