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:
@@ -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
|
// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/integrii/flaggy"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"marisa.chaotic.ninja/suwako"
|
"marisa.chaotic.ninja/suwako"
|
||||||
)
|
)
|
||||||
@@ -19,7 +19,7 @@ var (
|
|||||||
engine string
|
engine string
|
||||||
instance string
|
instance string
|
||||||
input string
|
input string
|
||||||
source string
|
source string = "auto"
|
||||||
target string
|
target string
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,13 +34,13 @@ func errCheck(err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadCfg() {
|
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")
|
flaggy.SetName("suwako")
|
||||||
flag.StringVar(&input, "i", "", "Enter the text to be translated")
|
flaggy.SetDescription("Command line client for SimplyTranslate")
|
||||||
flag.StringVar(&target, "t", "", "Set the language to translate to")
|
flaggy.SetVersion(suwako.FullVersion())
|
||||||
|
|
||||||
flag.Usage = func() {
|
flaggy.String(&source, "f", "from", "Source language")
|
||||||
fmt.Printf("usage: suwako -f [lang] -i [text] -t [lang]\nversion: %v\n", suwako.FullVersion())
|
flaggy.String(&target, "t", "to", "Target language")
|
||||||
}
|
flaggy.AddPositionalValue(&input, "input", 1, true, "Text to translate")
|
||||||
|
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
errCheck(err)
|
errCheck(err)
|
||||||
@@ -51,7 +51,7 @@ func loadCfg() {
|
|||||||
engine = os.Getenv("SUWAKO_ENGINE")
|
engine = os.Getenv("SUWAKO_ENGINE")
|
||||||
instance = os.Getenv("SUWAKO_INSTANCE")
|
instance = os.Getenv("SUWAKO_INSTANCE")
|
||||||
|
|
||||||
flag.Parse()
|
flaggy.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -59,9 +59,6 @@ func main() {
|
|||||||
loadCfg()
|
loadCfg()
|
||||||
|
|
||||||
// Verify command-line inputs
|
// Verify command-line inputs
|
||||||
if len(input) == 0 {
|
|
||||||
log.Fatal("There is no input")
|
|
||||||
}
|
|
||||||
if len(target) == 0 {
|
if len(target) == 0 {
|
||||||
log.Fatal("No target language")
|
log.Fatal("No target language")
|
||||||
}
|
}
|
||||||
|
|||||||
5
go.mod
5
go.mod
@@ -2,4 +2,7 @@ module marisa.chaotic.ninja/suwako
|
|||||||
|
|
||||||
go 1.18
|
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
5
go.sum
@@ -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 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
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=
|
||||||
|
|||||||
Reference in New Issue
Block a user