Compare commits

..

7 Commits

Author SHA1 Message Date
1323fb9e1a Merge pull request '修正 #59 #99 转换后移除原始文件处理' (#100) from fix-59-99-remove-source into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #100
2024-10-08 21:06:44 +00:00
36df203bdd fix: record last error when calling processDir
Some checks failed
continuous-integration/drone/push Build is failing
2024-10-08 22:03:29 +01:00
2afc232eb1 fix: don't force exit when processFile fails. 2024-10-08 21:59:47 +01:00
2abdd47c9c fix: typo 2024-10-08 21:59:27 +01:00
8b59bc026d chore: ignore exe files 2024-10-08 21:59:19 +01:00
91855f8f5b fix #99: default output dir to where the input file is
All checks were successful
continuous-integration/drone/push Build is passing
2024-10-08 21:52:23 +01:00
7edd326b95 fix #59: processDir should call processFile instead. 2024-10-08 21:47:10 +01:00
2 changed files with 27 additions and 25 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea
/dist
*.exe

View File

@ -8,6 +8,7 @@ import (
"io"
"os"
"os/signal"
"path"
"path/filepath"
"runtime"
"runtime/debug"
@ -84,6 +85,11 @@ func printSupportedExtensions() {
}
func appMain(c *cli.Context) (err error) {
cwd, err := os.Getwd()
if err != nil {
return err
}
if c.Bool("supported-ext") {
printSupportedExtensions()
return nil
@ -92,10 +98,7 @@ func appMain(c *cli.Context) (err error) {
if input == "" {
switch c.Args().Len() {
case 0:
input, err = os.Getwd()
if err != nil {
return err
}
input = cwd
case 1:
input = c.Args().Get(0)
default:
@ -104,22 +107,20 @@ func appMain(c *cli.Context) (err error) {
}
output := c.String("output")
if output == "" {
var err error
output, err = os.Getwd()
if err != nil {
return err
}
if input == output {
return errors.New("input and output path are same")
}
}
inputStat, err := os.Stat(input)
if err != nil {
return err
}
if output == "" {
// Default to where the input is
if inputStat.IsDir() {
output = input
} else {
output = path.Dir(input)
}
}
outputStat, err := os.Stat(output)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
@ -150,8 +151,8 @@ func appMain(c *cli.Context) (err error) {
}
if inputStat.IsDir() {
wacthDir := c.Bool("watch")
if !wacthDir {
watchDir := c.Bool("watch")
if !watchDir {
return proc.processDir(input)
} else {
return proc.watchDir(input)
@ -230,29 +231,29 @@ func (p *processor) processDir(inputDir string) error {
if err != nil {
return err
}
var lastError error = nil
for _, item := range items {
if item.IsDir() {
continue
}
filePath := filepath.Join(inputDir, item.Name())
allDec := common.GetDecoder(filePath, p.skipNoopDecoder)
if len(allDec) == 0 {
logger.Info("skipping while no suitable decoder", zap.String("source", item.Name()))
continue
}
if err := p.process(filePath, allDec); err != nil {
if err := p.processFile(filePath); err != nil {
lastError = err
logger.Error("conversion failed", zap.String("source", item.Name()), zap.Error(err))
}
}
if lastError != nil {
return fmt.Errorf("last error: %w", lastError)
}
return nil
}
func (p *processor) processFile(filePath string) error {
allDec := common.GetDecoder(filePath, p.skipNoopDecoder)
if len(allDec) == 0 {
logger.Fatal("skipping while no suitable decoder")
return errors.New("skipping while no suitable decoder")
}
if err := p.process(filePath, allDec); err != nil {