mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
improve default output
This commit is contained in:
parent
cae2f01dba
commit
72765ff961
30
main.go
30
main.go
@ -136,19 +136,41 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt.Output == "" {
|
var defaultOutput string
|
||||||
fi, err := os.Stat(opt.Input)
|
fi, err := os.Stat(opt.Input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
inputBase := filepath.Clean(opt.Input)
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
opt.Output = fmt.Sprintf("%s.epub", filepath.Clean(opt.Input))
|
defaultOutput = fmt.Sprintf("%s.epub", inputBase)
|
||||||
} else {
|
} else {
|
||||||
ext := filepath.Ext(opt.Input)
|
ext := filepath.Ext(inputBase)
|
||||||
opt.Output = fmt.Sprintf("%s.epub", opt.Input[0:len(opt.Input)-len(ext)])
|
defaultOutput = fmt.Sprintf("%s.epub", inputBase[0:len(inputBase)-len(ext)])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opt.Output == "" {
|
||||||
|
opt.Output = defaultOutput
|
||||||
|
}
|
||||||
|
|
||||||
|
if filepath.Ext(opt.Output) != ".epub" {
|
||||||
|
fo, err := os.Stat(opt.Output)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
flag.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if !fo.IsDir() {
|
||||||
|
fmt.Fprintln(os.Stderr, "output must be an existing dir or end with .epub")
|
||||||
|
flag.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
opt.Output = filepath.Join(
|
||||||
|
opt.Output,
|
||||||
|
filepath.Base(defaultOutput),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
profileIdx, profileMatch := ProfilesIdx[opt.Profile]
|
profileIdx, profileMatch := ProfilesIdx[opt.Profile]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user