🔨 refactor(): refactor resume code

refactor resume code with promptui

Signed-off-by: ehlxr <ehlxr.me@gmail.com>
master
ehlxr 2018-03-28 11:16:04 +08:00
parent 8289eaef8e
commit 4fbaca7996
1 changed files with 39 additions and 12 deletions

View File

@ -2,33 +2,60 @@ package main
import ( import (
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/manifoldco/promptui"
) )
func main() { func main() {
source := flag.String("source", "/Users/ehlxr/ehlxr/blog/Hexo/source/resume/index.md", "source file path") // source := flag.String("source", "/Users/ehlxr/ehlxr/blog/Hexo/source/resume/index.md", "source file path")
dest := flag.String("dest", "/Users/ehlxr/ehlxr/blog/resume/data.json", "destination file path") // dest := flag.String("dest", "/Users/ehlxr/ehlxr/blog/resume/data.json", "destination file path")
flag.Parse() // flag.Parse()
fmt.Printf("is these right? (n/no cancel)\n source file path: %s \n destination file path: %s\n", *source, *dest) // fmt.Printf("is these right? (n/no cancel)\n source file path: %s \n destination file path: %s\n", *source, *dest)
var in string // var in string
fmt.Scanln(&in) // fmt.Scanln(&in)
if in == "no" || in == "n" { // if in == "no" || in == "n" {
fmt.Println("bye!") // fmt.Println("bye!")
os.Exit(0) // os.Exit(0)
// }
prompt := promptui.SelectWithAdd{
Label: "What's your source file path",
Items: []string{"/Users/ehlxr/ehlxr/blog/Hexo/source/resume/index.md"},
AddLabel: "Other",
}
_, source, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
prompt = promptui.SelectWithAdd{
Label: "What's your destination file path",
Items: []string{"/Users/ehlxr/ehlxr/blog/resume/data.json"},
AddLabel: "Other",
}
_, dest, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
} }
m := make(map[string]interface{}) m := make(map[string]interface{})
m["show"] = "1" m["show"] = "1"
m["content"] = string(readFile(*source)) m["content"] = string(readFile(source))
j, err := json.Marshal(m) j, err := json.Marshal(m)
if err != nil { if err != nil {
panic(err) panic(err)
} }
writeFile(*dest, j) writeFile(dest, j)
fmt.Println("Done !") fmt.Println("Done !")
} }