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")
}

5
go.mod
View File

@ -2,4 +2,7 @@ module marisa.chaotic.ninja/suwako
go 1.18
require github.com/joho/godotenv v1.5.1
require (
github.com/integrii/flaggy v1.5.2
github.com/joho/godotenv v1.5.1
)

5
go.sum
View File

@ -1,2 +1,7 @@
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/integrii/flaggy v1.5.2 h1:bWV20MQEngo4hWhno3i5Z9ISPxLPKj9NOGNwTWb/8IQ=
github.com/integrii/flaggy v1.5.2/go.mod h1:dO13u7SYuhk910nayCJ+s1DeAAGC1THCMj1uSFmwtQ8=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=