Skip to content

Commit 436b566

Browse files
committed
feat(param/cli): support using "-" as stdin config file
1 parent c287532 commit 436b566

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ ghfs [options]
300300
The external config's priority is lower than arguments specified on command line.
301301
If one option is specified on command line, then external config of that option is ignored.
302302
303+
Set "-" to use stdin.
304+
303305
,,
304306
To specify multiple virtual hosts with options, split these hosts' options by this sign.
305307
Options above can be specified for each virtual host.

README.zh-CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ ghfs [选项]
291291
外部配置的优先级低于命令行选项。
292292
如果在命令行指定了某个选项,则其外部配置被忽略。
293293
294+
使用“-”指定为标准输入。
295+
294296
,,
295297
要指定多台虚拟主机的选项,用此符号分割每台主机的选项。
296298
可以为每台虚拟主机分别指定以上选项。

src/param/cli.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ func ArgsToCmdResults(cmd *goNixArgParser.Command, args []string) (results []*go
229229
// append config and re-parse
230230
configs := []string{}
231231
groupSeps := cmd.Options().GroupSeps()[0]
232-
foundConfig := false
232+
hasConfig := false
233+
var stdinConfigArgs []string
233234
for i := range results {
234235
configs = append(configs, groupSeps)
235236

@@ -239,20 +240,29 @@ func ArgsToCmdResults(cmd *goNixArgParser.Command, args []string) (results []*go
239240
continue
240241
}
241242

242-
configArgs, err := goNixArgParser.LoadConfigArgs(config)
243-
if err != nil {
244-
errs = append(errs, err)
245-
continue
243+
var configArgs []string
244+
if stdinConfigArgs != nil && config == "-" {
245+
configArgs = stdinConfigArgs
246+
} else {
247+
var err error
248+
configArgs, err = goNixArgParser.LoadConfigArgs(config)
249+
if err != nil {
250+
errs = append(errs, err)
251+
continue
252+
}
253+
if config == "-" {
254+
stdinConfigArgs = configArgs
255+
}
246256
}
247257

248-
foundConfig = true
258+
hasConfig = true
249259
configs = append(configs, configArgs...)
250260
}
251261
if len(errs) > 0 {
252262
return
253263
}
254264

255-
if foundConfig {
265+
if hasConfig {
256266
configs = configs[1:]
257267
results = cmd.ParseGroups(args, configs)
258268
for i := range results {

0 commit comments

Comments
 (0)