mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00
parse: don't use stdin if there are arguments
This should fix issue #1141 (ipfs cat "multihash too short" error when using stdin) and perhaps others. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
@ -255,13 +255,17 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
|
|||||||
stringArgs, inputs = appendString(stringArgs, inputs)
|
stringArgs, inputs = appendString(stringArgs, inputs)
|
||||||
|
|
||||||
} else if argDef.SupportsStdin {
|
} else if argDef.SupportsStdin {
|
||||||
// if we have a stdin, read it in and use the data as a string value
|
if len(inputs) > 0 {
|
||||||
stringArgs, stdin, err = appendStdinAsString(stringArgs, stdin)
|
// don't use stdin if we have inputs
|
||||||
if err != nil {
|
stdin = nil
|
||||||
return nil, nil, err
|
} else {
|
||||||
|
// if we have a stdin, read it in and use the data as a string value
|
||||||
|
stringArgs, stdin, err = appendStdinAsString(stringArgs, stdin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if argDef.Type == cmds.ArgFile {
|
} else if argDef.Type == cmds.ArgFile {
|
||||||
if stdin == nil {
|
if stdin == nil {
|
||||||
// treat stringArg values as file paths
|
// treat stringArg values as file paths
|
||||||
@ -271,8 +275,13 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if argDef.SupportsStdin {
|
} else if argDef.SupportsStdin {
|
||||||
// if we have a stdin, create a file from it
|
if len(inputs) > 0 {
|
||||||
fileArgs, stdin = appendStdinAsFile(fileArgs, stdin)
|
// don't use stdin if we have inputs
|
||||||
|
stdin = nil
|
||||||
|
} else {
|
||||||
|
// if we have a stdin, create a file from it
|
||||||
|
fileArgs, stdin = appendStdinAsFile(fileArgs, stdin)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,8 +222,8 @@ func TestArgumentParsing(t *testing.T) {
|
|||||||
fstdin := fileToSimulateStdin(t, "stdin1")
|
fstdin := fileToSimulateStdin(t, "stdin1")
|
||||||
|
|
||||||
test([]string{"stdinenabled"}, fstdin, []string{"stdin1"})
|
test([]string{"stdinenabled"}, fstdin, []string{"stdin1"})
|
||||||
test([]string{"stdinenabled", "value1"}, fstdin, []string{"stdin1", "value1"})
|
test([]string{"stdinenabled", "value1"}, fstdin, []string{"value1"})
|
||||||
test([]string{"stdinenabled", "value1", "value2"}, fstdin, []string{"stdin1", "value1", "value2"})
|
test([]string{"stdinenabled", "value1", "value2"}, fstdin, []string{"value1", "value2"})
|
||||||
|
|
||||||
fstdin = fileToSimulateStdin(t, "stdin1\nstdin2")
|
fstdin = fileToSimulateStdin(t, "stdin1\nstdin2")
|
||||||
test([]string{"stdinenabled"}, fstdin, []string{"stdin1", "stdin2"})
|
test([]string{"stdinenabled"}, fstdin, []string{"stdin1", "stdin2"})
|
||||||
|
Reference in New Issue
Block a user