re-implement interactive mode as a simple batch file wrapper
This commit is contained in:
parent
a071e5f58d
commit
bc847992bd
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
yomichan-import*
|
||||
!yomichan-import.bat
|
||||
|
46
main.go
46
main.go
@ -23,7 +23,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
@ -32,7 +31,6 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func usage() {
|
||||
@ -78,21 +76,13 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
var (
|
||||
interactive bool
|
||||
inputPath string
|
||||
outputDir string
|
||||
inputPath string
|
||||
outputDir string
|
||||
)
|
||||
|
||||
if flag.NArg() == 0 {
|
||||
fmt.Print("Specify path of dictionary to convert: ")
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
inputPath, _ = reader.ReadString('\n')
|
||||
inputPath = strings.Replace(inputPath, "\n", "", -1)
|
||||
inputPath = strings.Replace(inputPath, "\r", "", -1)
|
||||
interactive = true
|
||||
|
||||
fmt.Print("\n")
|
||||
usage()
|
||||
os.Exit(2)
|
||||
} else {
|
||||
inputPath = flag.Arg(0)
|
||||
if flag.NArg() > 1 {
|
||||
@ -100,48 +90,32 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
terminate := func() {
|
||||
if interactive {
|
||||
fmt.Print("\nPress [ENTER] to exit...")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
reader.ReadString('\n')
|
||||
}
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(inputPath); err != nil {
|
||||
log.Printf("dictionary path '%s' does not exist", inputPath)
|
||||
terminate()
|
||||
log.Fatalf("dictionary path '%s' does not exist", inputPath)
|
||||
}
|
||||
|
||||
if *format == "" {
|
||||
if *format = detectFormat(inputPath); *format == "" {
|
||||
log.Print("failed to detect dictionary format")
|
||||
terminate()
|
||||
log.Fatal("failed to detect dictionary format")
|
||||
}
|
||||
}
|
||||
|
||||
if outputDir == "" {
|
||||
var err error
|
||||
outputDir, err = ioutil.TempDir("", "yomichan_tmp_")
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
terminate()
|
||||
if outputDir, err = ioutil.TempDir("", "yomichan_tmp_"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
*serve = true
|
||||
}
|
||||
|
||||
if err := exportDb(inputPath, outputDir, *format, *title, *stride, *pretty); err != nil {
|
||||
log.Print(err)
|
||||
terminate()
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if *serve {
|
||||
if err := serveDb(outputDir, *port); err != nil {
|
||||
log.Print(err)
|
||||
terminate()
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ gox -os="linux windows" -arch="386"
|
||||
|
||||
mkdir -p yomichan-import_windows/bin/windows
|
||||
mv yomichan-import_windows_386.exe yomichan-import_windows/yomichan-import.exe
|
||||
cp yomichan-import.bat yomichan-import_windows
|
||||
cp bin/windows/* yomichan-import_windows/bin/windows/
|
||||
7z a yomichan-import_windows.zip yomichan-import_windows
|
||||
rm -rf yomichan-import_windows
|
||||
|
4
yomichan-import.bat
Normal file
4
yomichan-import.bat
Normal file
@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
set /p dict_path="Specify dictionary path: "
|
||||
yomichan-import.exe %dict_path%
|
||||
pause
|
Loading…
Reference in New Issue
Block a user