flag not allowing positional arguments is lame, move from it to using flaggy

Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>

git-svn-id: file:///srv/svn/repo/suwako/trunk@23 0b558ee1-521d-8b46-a41b-40029c97c055
This commit is contained in:
yakumo.izuru
2023-10-22 02:04:27 +00:00
parent be9aea3424
commit 7aea9ad0c4
3 changed files with 19 additions and 14 deletions

View File

@@ -1,16 +1,16 @@
// $TheSupernovaDuo: suwako,v 1.5.2 2023/10/21 00:58:44 yakumo_izuru Exp $
// $TheSupernovaDuo: suwako,v 1.5.3 2023/10/22 02:01:48 yakumo_izuru Exp $
// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"net/url"
"os"
"github.com/integrii/flaggy"
"github.com/joho/godotenv"
"marisa.chaotic.ninja/suwako"
)
@@ -19,7 +19,7 @@ var (
engine string
instance string
input string
source string
source string = "auto"
target string
)
@@ -34,13 +34,13 @@ func errCheck(err error) {
}
func loadCfg() {
flag.StringVar(&source, "f", "auto", "Set the language to translate from. This can be skipped as it will autodetect the language you're translating from")
flag.StringVar(&input, "i", "", "Enter the text to be translated")
flag.StringVar(&target, "t", "", "Set the language to translate to")
flaggy.SetName("suwako")
flaggy.SetDescription("Command line client for SimplyTranslate")
flaggy.SetVersion(suwako.FullVersion())
flag.Usage = func() {
fmt.Printf("usage: suwako -f [lang] -i [text] -t [lang]\nversion: %v\n", suwako.FullVersion())
}
flaggy.String(&source, "f", "from", "Source language")
flaggy.String(&target, "t", "to", "Target language")
flaggy.AddPositionalValue(&input, "input", 1, true, "Text to translate")
home, err := os.UserHomeDir()
errCheck(err)
@@ -51,7 +51,7 @@ func loadCfg() {
engine = os.Getenv("SUWAKO_ENGINE")
instance = os.Getenv("SUWAKO_INSTANCE")
flag.Parse()
flaggy.Parse()
}
func main() {
@@ -59,9 +59,6 @@ func main() {
loadCfg()
// Verify command-line inputs
if len(input) == 0 {
log.Fatal("There is no input")
}
if len(target) == 0 {
log.Fatal("No target language")
}