mozhi/cmd/langlist.go

57 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
"codeberg.org/aryak/libmozhi"
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 := libmozhi.LangList(engineused, listtype)
2023-08-28 21:55:00 +05:30
if err != nil {
fmt.Println(err)
2023-08-30 16:05:16 +05:30
} else {
idxs, err := fuzzyfinder.FindMulti(
list,
func(i int) string {
return list[i].Name
})
if err != nil {
fmt.Println(err)
}
for _, idx := range idxs {
2024-02-20 14:41:45 +05:30
if raw {
2023-08-30 16:05:16 +05:30
fmt.Println(list[idx].Id)
} else {
fmt.Println("Selected Language:", list[idx].Id, "("+list[idx].Name+")")
}
2023-08-28 21:55:00 +05:30
}
}
},
}
func init() {
rootCmd.AddCommand(langlistCmd)
translateCmd.Flags().SortFlags = false
2024-05-24 14:16:31 +05:30
langlistCmd.Flags().StringVarP(&engineused, "engine", "e", "", "[google|libre|reverso|deepl|yandex|mymemory|duckduckgo]")
2023-08-28 21:55:00 +05:30
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")
}