Skip to content

Commit 49cf8ce

Browse files
authored
Merge pull request #157 from ipfs/feat/stdin-name
Handle stdin name in cli/parse
2 parents 4ca651a + a55e111 commit 49cf8ce

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

cli/parse.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func Parse(ctx context.Context, input []string, stdin *os.File, root *cmds.Comma
7070
}
7171

7272
func isHidden(req *cmds.Request) bool {
73-
h, ok := req.Options["hidden"].(bool)
73+
h, ok := req.Options[cmds.Hidden].(bool)
7474
return h && ok
7575
}
7676

@@ -79,6 +79,11 @@ func isRecursive(req *cmds.Request) bool {
7979
return rec && ok
8080
}
8181

82+
func stdinName(req *cmds.Request) string {
83+
name, _ := req.Options[cmds.StdinName].(string)
84+
return name
85+
}
86+
8287
type parseState struct {
8388
cmdline []string
8489
i int
@@ -265,7 +270,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
265270
return err
266271
}
267272

268-
fpath = ""
273+
fpath = stdinName(req)
269274
file, err = files.NewReaderPathFile(stdin.Name(), r, nil)
270275
if err != nil {
271276
return err
@@ -308,7 +313,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
308313
return err
309314
}
310315

311-
fileArgs[""], err = files.NewReaderPathFile(stdin.Name(), r, nil)
316+
fileArgs[stdinName(req)], err = files.NewReaderPathFile(stdin.Name(), r, nil)
312317
if err != nil {
313318
return err
314319
}

opts.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const (
1515
OptShortHelp = "h"
1616
OptLongHelp = "help"
1717
DerefLong = "dereference-args"
18+
StdinName = "stdin-name"
19+
Hidden = "hidden"
20+
HiddenShort = "H"
1821
)
1922

2023
// options that are used by this package
@@ -23,3 +26,5 @@ var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory pa
2326
var OptionStreamChannels = cmdkit.BoolOption(ChanOpt, "Stream channel output")
2427
var OptionTimeout = cmdkit.StringOption(TimeoutOpt, "Set a global timeout on the command")
2528
var OptionDerefArgs = cmdkit.BoolOption(DerefLong, "Symlinks supplied in arguments are dereferenced")
29+
var OptionStdinName = cmdkit.StringOption(StdinName, "Assign a name if the file source is stdin.")
30+
var OptionHidden = cmdkit.BoolOption(Hidden, HiddenShort, "Include files that are hidden. Only takes effect on recursive add.")

0 commit comments

Comments
 (0)