fix #99: default output dir to where the input file is

pull/100/head
鲁树人 1 month ago
parent 7edd326b95
commit 91855f8f5b

@ -8,6 +8,7 @@ import (
"io" "io"
"os" "os"
"os/signal" "os/signal"
"path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"runtime/debug" "runtime/debug"
@ -84,6 +85,11 @@ func printSupportedExtensions() {
} }
func appMain(c *cli.Context) (err error) { func appMain(c *cli.Context) (err error) {
cwd, err := os.Getwd()
if err != nil {
return err
}
if c.Bool("supported-ext") { if c.Bool("supported-ext") {
printSupportedExtensions() printSupportedExtensions()
return nil return nil
@ -92,10 +98,7 @@ func appMain(c *cli.Context) (err error) {
if input == "" { if input == "" {
switch c.Args().Len() { switch c.Args().Len() {
case 0: case 0:
input, err = os.Getwd() input = cwd
if err != nil {
return err
}
case 1: case 1:
input = c.Args().Get(0) input = c.Args().Get(0)
default: default:
@ -104,20 +107,18 @@ func appMain(c *cli.Context) (err error) {
} }
output := c.String("output") output := c.String("output")
if output == "" { inputStat, err := os.Stat(input)
var err error
output, err = os.Getwd()
if err != nil { if err != nil {
return err return err
} }
if input == output {
return errors.New("input and output path are same")
}
}
inputStat, err := os.Stat(input) if output == "" {
if err != nil { // Default to where the input is
return err if inputStat.IsDir() {
output = input
} else {
output = path.Dir(input)
}
} }
outputStat, err := os.Stat(output) outputStat, err := os.Stat(output)

Loading…
Cancel
Save