adding interactive mode for command line newbs
This commit is contained in:
parent
ce5ce1c902
commit
7477a44e2b
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "zero-epwing"]
|
||||||
|
path = zero-epwing
|
||||||
|
url = https://github.com/FooSoft/zero-epwing
|
Binary file not shown.
Binary file not shown.
58
main.go
58
main.go
@ -23,6 +23,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -31,6 +32,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
@ -75,38 +77,70 @@ func main() {
|
|||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if flag.NArg() != 1 && flag.NArg() != 2 {
|
var (
|
||||||
usage()
|
interactive bool
|
||||||
os.Exit(2)
|
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)
|
||||||
|
interactive = true
|
||||||
|
|
||||||
|
fmt.Print("\n")
|
||||||
|
} else {
|
||||||
|
inputPath = flag.Arg(0)
|
||||||
|
if flag.NArg() > 1 {
|
||||||
|
outputDir = flag.Arg(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
terminate := func() {
|
||||||
|
if interactive {
|
||||||
|
fmt.Print("\nPress [ENTER] to terminate...")
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
inputPath := flag.Arg(0)
|
|
||||||
if *format == "" {
|
if *format == "" {
|
||||||
if *format = detectFormat(inputPath); *format == "" {
|
if *format = detectFormat(inputPath); *format == "" {
|
||||||
log.Fatal("failed to detect dictionary format")
|
log.Print("failed to detect dictionary format")
|
||||||
|
terminate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var outputDir string
|
if outputDir == "" {
|
||||||
if flag.NArg() == 2 {
|
|
||||||
outputDir = flag.Arg(1)
|
|
||||||
} else {
|
|
||||||
var err error
|
var err error
|
||||||
outputDir, err = ioutil.TempDir("", "yomichan_tmp_")
|
outputDir, err = ioutil.TempDir("", "yomichan_tmp_")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Print(err)
|
||||||
|
terminate()
|
||||||
}
|
}
|
||||||
|
|
||||||
*serve = true
|
*serve = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exportDb(inputPath, outputDir, *format, *title, *stride, *pretty); err != nil {
|
if err := exportDb(inputPath, outputDir, *format, *title, *stride, *pretty); err != nil {
|
||||||
log.Fatal(err)
|
log.Print(err)
|
||||||
|
terminate()
|
||||||
}
|
}
|
||||||
|
|
||||||
if *serve {
|
if *serve {
|
||||||
if err := serveDb(outputDir, *port); err != nil {
|
if err := serveDb(outputDir, *port); err != nil {
|
||||||
log.Fatal(err)
|
log.Print(err)
|
||||||
|
terminate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
zero-epwing
Submodule
1
zero-epwing
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 82158b0104880d462d47d5a27108cfc31f00208c
|
Loading…
Reference in New Issue
Block a user