Compare commits

...

2 Commits
main ... main

Author SHA1 Message Date
28b2b9a6db Merge pull request '更新 cmd/um/main.go' (#1) from cometjun-MutliFile into main
Reviewed-on: cometjun/cli#1
2025-01-08 17:39:10 +00:00
620154e207 更新 cmd/um/main.go
增加可以接收拖动多个文件参数,或多个文件夹参数功能
2025-01-08 17:38:24 +00:00

View File

@ -122,27 +122,32 @@ func appMain(c *cli.Context) (err error) {
printSupportedExtensions()
return nil
}
var inputs []string
input := c.String("input")
if input == "" {
switch c.Args().Len() {
case 0:
input = cwd
case 1:
input = c.Args().Get(0)
default:
return errors.New("please specify input file (or directory)")
}
if input != "" {
inputs = append(inputs, input)
}
if c.Args().Len() > 0 {
inputs = append(inputs, c.Args().Slice()...)
}
if len(inputs) == 0 {
inputs = append(inputs, cwd)
}
for _, input := range inputs {
input, absErr := filepath.Abs(input)
if absErr != nil {
return fmt.Errorf("get abs path failed: %w", absErr)
logger.Warn("get abs path failed", zap.String("input", input), zap.Error(absErr))
continue
}
output := c.String("output")
inputStat, err := os.Stat(input)
if err != nil {
return err
logger.Warn("stat input failed", zap.String("input", input), zap.Error(err))
continue
}
var inputDir string
@ -156,6 +161,7 @@ func appMain(c *cli.Context) (err error) {
return fmt.Errorf("get abs path (inputDir) failed: %w", absErr)
}
output := c.String("output")
if output == "" {
// Default to where the input dir is
output = inputDir
@ -196,14 +202,19 @@ func appMain(c *cli.Context) (err error) {
if inputStat.IsDir() {
watchDir := c.Bool("watch")
if !watchDir {
return proc.processDir(input)
err = proc.processDir(input)
} else {
return proc.watchDir(input)
err = proc.watchDir(input)
}
} else {
return proc.processFile(input)
err = proc.processFile(input)
}
if err != nil {
logger.Error("conversion failed", zap.String("source", input), zap.Error(err))
}
}
return nil
}
type processor struct {