1

re-implement interactive mode as a simple batch file wrapper

This commit is contained in:
Alex Yatskov 2017-01-02 15:14:09 -08:00
parent a071e5f58d
commit bc847992bd
4 changed files with 16 additions and 36 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
yomichan-import*
!yomichan-import.bat

46
main.go
View File

@ -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)
}
}
}

View File

@ -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
View File

@ -0,0 +1,4 @@
@echo off
set /p dict_path="Specify dictionary path: "
yomichan-import.exe %dict_path%
pause