提交 b034a0d8 作者: Jeromy

and special case that one thing because why not

License: MIT
Signed-off-by: 's avatarJeromy <why@ipfs.io>
上级 5d301cb8
......@@ -61,6 +61,16 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
}
}
// This is an ugly hack to maintain our current CLI interface while fixing
// other stdin usage bugs. Let this serve as a warning, be careful about the
// choices you make, they will haunt you forever.
if len(path) == 2 && path[0] == "bootstrap" {
if (path[1] == "add" && opts["default"] == true) ||
(path[1] == "rm" && opts["all"] == true) {
stdin = nil
}
}
stringArgs, fileArgs, err := parseArgs(stringVals, stdin, cmd.Arguments, recursive, hidden, root)
if err != nil {
return req, cmd, path, err
......@@ -301,17 +311,10 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
stringArgs, inputs = append(stringArgs, inputs[0]), inputs[1:]
} else {
if stdin != nil && argDef.SupportsStdin && !fillingVariadic {
fname := ""
istty, err := isTty(stdin)
if err != nil {
return nil, nil, err
}
if istty {
fname = stdinSpecialName
if err := printReadInfo(stdin, msgStdinInfo); err == nil {
fileArgs[stdin.Name()] = files.NewReaderFile(stdinSpecialName, "", stdin, nil)
stdin = nil
}
fileArgs[stdin.Name()] = files.NewReaderFile(fname, "", stdin, nil)
stdin = nil
}
}
case cmds.ArgFile:
......
......@@ -128,7 +128,7 @@ func getQuery(req cmds.Request) (string, error) {
query.Set(k, str)
}
args := req.Arguments()
args := req.StringArguments()
argDefs := req.Command().Arguments
argDefIndex := 0
......
......@@ -56,7 +56,7 @@ func (rl *ReqLog) Add(req Request) *ReqLogEntry {
Active: true,
Command: strings.Join(req.Path(), "/"),
Options: req.Options(),
Args: req.Arguments(),
Args: req.StringArguments(),
ID: rl.nextID,
req: req,
log: rl,
......
......@@ -71,6 +71,7 @@ type Request interface {
SetOption(name string, val interface{})
SetOptions(opts OptMap) error
Arguments() []string
StringArguments() []string
SetArguments([]string)
Files() files.File
SetFiles(files.File)
......@@ -168,6 +169,10 @@ func (r *request) SetOptions(opts OptMap) error {
return r.ConvertOptions()
}
func (r *request) StringArguments() []string {
return r.arguments
}
// Arguments returns the arguments slice
func (r *request) Arguments() []string {
if r.haveVarArgsFromStdin() {
......@@ -207,7 +212,7 @@ func (r *request) haveVarArgsFromStdin() bool {
}
last := r.cmd.Arguments[len(r.cmd.Arguments)-1]
return last.SupportsStdin && last.Type == ArgString &&
return last.SupportsStdin && last.Type == ArgString && (last.Required || last.Variadic) &&
len(r.arguments) < len(r.cmd.Arguments)
}
......@@ -234,10 +239,6 @@ func (r *request) VarArgs(f func(string) error) error {
return err
}
if fi.FileName() == "*stdin*" {
fmt.Fprintln(os.Stderr, "ipfs: Reading from stdin; send Ctrl-d to stop.")
}
scan := bufio.NewScanner(fi)
for scan.Scan() {
err := f(scan.Text())
......
......@@ -58,7 +58,7 @@ EXAMPLE:
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("peerid", false, false, "Peer.ID of node to look up.").EnableStdin(),
cmds.StringArg("peerid", false, false, "Peer.ID of node to look up."),
},
Options: []cmds.Option{
cmds.StringOption("format", "f", "Optional output format."),
......
......@@ -117,6 +117,30 @@ test_bootstrap_cmd() {
'
test_bootstrap_list_cmd
test_expect_success "'ipfs bootstrap add' accepts args from stdin" '
echo $BP1 > bpeers &&
echo $BP2 >> bpeers &&
echo $BP3 >> bpeers &&
echo $BP4 >> bpeers &&
cat bpeers | ipfs bootstrap add > add_stdin_actual
'
test_expect_success "output looks good" '
test_cmp add_stdin_actual bpeers
'
test_bootstrap_list_cmd $BP1 $BP2 $BP3 $BP4
test_expect_success "'ipfs bootstrap rm' accepts args from stdin" '
cat bpeers | ipfs bootstrap rm > rm_stdin_actual
'
test_expect_success "output looks good" '
test_cmp rm_stdin_actual bpeers
'
test_bootstrap_list_cmd
}
# should work offline
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论