github.com/blend/go-sdk@v1.20220411.3/sh/parse_command.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package sh 9 10 import ( 11 "github.com/blend/go-sdk/stringutil" 12 ) 13 14 // ParseCommand returns the bin and args for a given statement. 15 // 16 // Typical use cases are to break apart single strings that represent 17 // comamnds and their arguments. 18 // 19 // Example: 20 // 21 // bin, args := sh.ParseCommand("git rebase master") 22 // 23 // Would yield "git", and "rebase","master" as the args. 24 func ParseCommand(statement string) (bin string, args []string) { 25 parts := stringutil.SplitSpaceQuoted(statement) 26 if len(parts) > 0 { 27 bin = parts[0] 28 } 29 if len(parts) > 1 { 30 args = parts[1:] 31 } 32 return 33 }