Skip to content

Commit

Permalink
perf: 减少依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan committed May 7, 2023
1 parent 0a5963b commit 6acea77
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 276 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

使用 `.\smq.exe gen` 命令转换格式。

支持格式:_极速赛码表(jisu)_[_其他_](https://github.com/flowerime/rose)
支持格式:_极速赛码表(jisu|js)__多多(duoduo|dd)__冰凌(bingling|bl)_

### 主命令参数解释

Expand Down
35 changes: 18 additions & 17 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/flowerime/gosmq/internal/gen"
util "github.com/flowerime/goutil"
"github.com/nopdan/ku"
"github.com/spf13/cobra"
)

var genCmd = &cobra.Command{
Use: "gen",
Short: "转换赛码表",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("交互模式转换赛码表")
genWithSurvey()
return
}
table := Config.Gen()
path := "dict/" + util.GetFileName(Config.Path) + ".txt"
gen.Write(table, path)
_gen()
},
}

Expand All @@ -37,7 +30,14 @@ func init() {
genCmd.Flags().BoolVarP(&Config.SortByWordLen, "sort", "s", false, "按照词长重新排序")
}

func genWithSurvey() {
func _gen() {
// 命令行模式
if Config.Path != "" {
gen_write(Config)
return
}

// 交互模式
var conf gen.Config
handle := func(err error) {
if err != nil {
Expand All @@ -58,15 +58,14 @@ func genWithSurvey() {

err = survey.AskOne(&survey.Select{
Message: "码表格式:",
Options: []string{"极速赛码表", "多多(词在前)", "冰凌(编码在前)", "极点"},
Options: []string{"极速赛码表", "多多", "冰凌"},
}, &conf.Format)
handle(err)

mFormat := make(map[string]string)
mFormat["极速赛码表"] = "jisu"
mFormat["多多(词在前)"] = "duoduo"
mFormat["冰凌(编码在前)"] = "bingling"
mFormat["极点"] = "jidian"
mFormat["多多"] = "duoduo"
mFormat["冰凌"] = "bingling"
conf.Format = mFormat[conf.Format]

if conf.Format != "jisu" {
Expand All @@ -91,10 +90,12 @@ func genWithSurvey() {
handle(err)
}

fmt.Println()
fmt.Println(conf)
fmt.Printf("\nconf: %v\n", conf)
gen_write(conf)
}

func gen_write(conf gen.Config) {
table := conf.Gen()
path := "dict/" + util.GetFileName(conf.Path) + ".txt"
path := "dict/" + ku.GetFileName(conf.Path) + ".txt"
gen.Write(table, path)
}
159 changes: 0 additions & 159 deletions cmd/go.go

This file was deleted.

30 changes: 30 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "",
Short: "",
Long: "这是最快的赛码器\n用于对基于码表的输入法针对特定文章进行测评\nhttps://github.com/flowerime/gosmq",
Run: func(cmd *cobra.Command, args []string) {
_root()
},
}

func init() {
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(serveCmd)
rootCmd.AddCommand(genCmd)
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Loading

0 comments on commit 6acea77

Please sign in to comment.