@cryptotaxi247 / kubo / commits / 015bd06cf

commands/cli: Fixed stdin arg handling

Matt Bell committed Nov 17, 2014 at 01:58 UTC 015bd06cffe4003773f3bafaf01f1198055accca
1 file changed +6 -6
commands/cli/parse.go
+6 -6
@@ -167,7 +167,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
167 fileArgs := make([]cmds.File, 0, numInputs)
168
169 argDefIndex := 0 // the index of the current argument definition
170 - for i, input := range inputs {
170 + for i := 0; i < numInputs; i++ {
171 // get the argument definiton (should be argDefs[argDefIndex],
172 // but if argDefIndex > len(argDefs) we use the last argument definition)
173 var argDef cmds.Argument
@@ -187,7 +187,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
187 if argDef.Type == cmds.ArgString {
188 if stdin == nil {
189 // add string values
190 - stringArgs = append(stringArgs, input)
190 + stringArgs = append(stringArgs, inputs[0])
191 inputs = inputs[1:]
192
193 } else if argDef.SupportsStdin {
@@ -204,7 +204,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
204 } else if argDef.Type == cmds.ArgFile {
205 if stdin == nil {
206 // treat stringArg values as file paths
207 - path := input
207 + path := inputs[0]
208 inputs = inputs[1:]
209
210 file, err := os.Open(path)
@@ -220,17 +220,17 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
220 if stat.IsDir() {
221 if !argDef.Recursive {
222 err = fmt.Errorf("Invalid path '%s', argument '%s' does not support directories",
223 - input, argDef.Name)
223 + path, argDef.Name)
224 return nil, nil, err
225 }
226 if !recursive {
227 err = fmt.Errorf("'%s' is a directory, use the '-%s' flag to specify directories",
228 - input, cmds.RecShort)
228 + path, cmds.RecShort)
229 return nil, nil, err
230 }
231 }
232
233 - fileArg, err := getFile(file, input)
233 + fileArg, err := getFile(file, path)
234 if err != nil {
235 return nil, nil, err
236 }