Compare commits
2 Commits
28ca8cef60
...
28b2b9a6db
Author | SHA1 | Date | |
---|---|---|---|
28b2b9a6db | |||
620154e207 |
155
cmd/um/main.go
155
cmd/um/main.go
@ -122,88 +122,99 @@ 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 {
|
||||
logger.Warn("get abs path failed", zap.String("input", input), zap.Error(absErr))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
input, absErr := filepath.Abs(input)
|
||||
if absErr != nil {
|
||||
return fmt.Errorf("get abs path failed: %w", absErr)
|
||||
}
|
||||
|
||||
output := c.String("output")
|
||||
inputStat, err := os.Stat(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var inputDir string
|
||||
if inputStat.IsDir() {
|
||||
inputDir = input
|
||||
} else {
|
||||
inputDir = filepath.Dir(input)
|
||||
}
|
||||
inputDir, absErr = filepath.Abs(inputDir)
|
||||
if absErr != nil {
|
||||
return fmt.Errorf("get abs path (inputDir) failed: %w", absErr)
|
||||
}
|
||||
|
||||
if output == "" {
|
||||
// Default to where the input dir is
|
||||
output = inputDir
|
||||
}
|
||||
logger.Debug("resolve input/output path", zap.String("inputDir", inputDir), zap.String("input", input), zap.String("output", output))
|
||||
|
||||
outputStat, err := os.Stat(output)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = os.MkdirAll(output, 0755)
|
||||
}
|
||||
inputStat, err := os.Stat(input)
|
||||
if err != nil {
|
||||
return err
|
||||
logger.Warn("stat input failed", zap.String("input", input), zap.Error(err))
|
||||
continue
|
||||
}
|
||||
} else if !outputStat.IsDir() {
|
||||
return errors.New("output should be a writable directory")
|
||||
}
|
||||
|
||||
if mmkv := c.String("qmc-mmkv"); mmkv != "" {
|
||||
// If key is not set, the mmkv vault will be treated as unencrypted.
|
||||
key := c.String("qmc-mmkv-key")
|
||||
err := qmc.OpenMMKV(mmkv, key, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
proc := &processor{
|
||||
logger: logger,
|
||||
inputDir: inputDir,
|
||||
outputDir: output,
|
||||
skipNoopDecoder: c.Bool("skip-noop"),
|
||||
removeSource: c.Bool("remove-source"),
|
||||
updateMetadata: c.Bool("update-metadata"),
|
||||
overwriteOutput: c.Bool("overwrite"),
|
||||
}
|
||||
|
||||
if inputStat.IsDir() {
|
||||
watchDir := c.Bool("watch")
|
||||
if !watchDir {
|
||||
return proc.processDir(input)
|
||||
var inputDir string
|
||||
if inputStat.IsDir() {
|
||||
inputDir = input
|
||||
} else {
|
||||
return proc.watchDir(input)
|
||||
inputDir = filepath.Dir(input)
|
||||
}
|
||||
inputDir, absErr = filepath.Abs(inputDir)
|
||||
if absErr != nil {
|
||||
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
|
||||
}
|
||||
logger.Debug("resolve input/output path", zap.String("inputDir", inputDir), zap.String("input", input), zap.String("output", output))
|
||||
|
||||
outputStat, err := os.Stat(output)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = os.MkdirAll(output, 0755)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if !outputStat.IsDir() {
|
||||
return errors.New("output should be a writable directory")
|
||||
}
|
||||
|
||||
if mmkv := c.String("qmc-mmkv"); mmkv != "" {
|
||||
// If key is not set, the mmkv vault will be treated as unencrypted.
|
||||
key := c.String("qmc-mmkv-key")
|
||||
err := qmc.OpenMMKV(mmkv, key, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
proc := &processor{
|
||||
logger: logger,
|
||||
inputDir: inputDir,
|
||||
outputDir: output,
|
||||
skipNoopDecoder: c.Bool("skip-noop"),
|
||||
removeSource: c.Bool("remove-source"),
|
||||
updateMetadata: c.Bool("update-metadata"),
|
||||
overwriteOutput: c.Bool("overwrite"),
|
||||
}
|
||||
|
||||
if inputStat.IsDir() {
|
||||
watchDir := c.Bool("watch")
|
||||
if !watchDir {
|
||||
err = proc.processDir(input)
|
||||
} else {
|
||||
err = proc.watchDir(input)
|
||||
}
|
||||
} else {
|
||||
err = proc.processFile(input)
|
||||
}
|
||||
if err != nil {
|
||||
logger.Error("conversion failed", zap.String("source", input), zap.Error(err))
|
||||
}
|
||||
} else {
|
||||
return proc.processFile(input)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type processor struct {
|
||||
|
Loading…
Reference in New Issue
Block a user