2023-08-28 16:25:00 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-08-29 09:20:56 +00:00
|
|
|
|
2023-08-28 16:25:00 +00:00
|
|
|
"codeberg.org/aryak/mozhi/utils"
|
2023-08-29 09:20:56 +00:00
|
|
|
|
2023-08-28 16:25:00 +00:00
|
|
|
"github.com/ktr0731/go-fuzzyfinder"
|
2023-08-29 09:20:56 +00:00
|
|
|
"github.com/spf13/cobra"
|
2023-08-28 16:25:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
engineused string
|
2023-08-29 09:20:56 +00:00
|
|
|
listtype string
|
|
|
|
raw bool
|
2023-08-28 16:25:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// langlistCmd represents the langlist command
|
|
|
|
var langlistCmd = &cobra.Command{
|
|
|
|
Use: "langlist",
|
|
|
|
Short: "List/select languages supported by an engine.",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
list, err := utils.LangList(engineused, listtype)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
2023-08-30 10:35:16 +00:00
|
|
|
} else {
|
|
|
|
idxs, err := fuzzyfinder.FindMulti(
|
|
|
|
list,
|
|
|
|
func(i int) string {
|
|
|
|
return list[i].Name
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
for _, idx := range idxs {
|
|
|
|
if raw == true {
|
|
|
|
fmt.Println(list[idx].Id)
|
|
|
|
} else {
|
|
|
|
fmt.Println("Selected Language:", list[idx].Id, "("+list[idx].Name+")")
|
|
|
|
}
|
2023-08-28 16:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(langlistCmd)
|
|
|
|
translateCmd.Flags().SortFlags = false
|
|
|
|
|
|
|
|
langlistCmd.Flags().StringVarP(&engineused, "engine", "e", "", "[google|libre|reverso|deepl|watson|yandex|mymemory|duckduckgo]")
|
|
|
|
langlistCmd.Flags().StringVarP(&listtype, "type", "t", "", "[sl|tl] Choose language for source or target")
|
|
|
|
langlistCmd.Flags().BoolVarP(&raw, "raw", "r", false, "Return only selected language code.")
|
|
|
|
|
|
|
|
langlistCmd.MarkFlagRequired("engine")
|
|
|
|
langlistCmd.MarkFlagRequired("type")
|
|
|
|
}
|