mozhi/cmd/langlist.go

56 lines
1.3 KiB
Go
Raw Normal View History

2023-08-28 21:55:00 +05:30
package cmd
import (
"fmt"
2023-08-29 14:50:56 +05:30
2023-08-28 21:55:00 +05:30
"codeberg.org/aryak/mozhi/utils"
2023-08-29 14:50:56 +05:30
2023-08-28 21:55:00 +05:30
"github.com/ktr0731/go-fuzzyfinder"
2023-08-29 14:50:56 +05:30
"github.com/spf13/cobra"
2023-08-28 21:55:00 +05:30
)
var (
engineused string
2023-08-29 14:50:56 +05:30
listtype string
raw bool
2023-08-28 21:55:00 +05:30
)
// 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)
}
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+")")
}
}
},
}
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")
}