Changeset 23 in code


Ignore:
Timestamp:
Oct 22, 2023, 2:04:27 AM (20 months ago)
Author:
yakumo.izuru
Message:

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

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/cmd/suwako/main.go

    r22 r23  
    1 // $TheSupernovaDuo: suwako,v 1.5.2 2023/10/21 00:58:44 yakumo_izuru Exp $
     1// $TheSupernovaDuo: suwako,v 1.5.3 2023/10/22 02:01:48 yakumo_izuru Exp $
    22// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
    33package main
     
    55import (
    66        "encoding/json"
    7         "flag"
    87        "fmt"
    98        "log"
     
    1211        "os"
    1312
     13        "github.com/integrii/flaggy"
    1414        "github.com/joho/godotenv"
    1515        "marisa.chaotic.ninja/suwako"
     
    2020        instance string
    2121        input string
    22         source string
     22        source string = "auto"
    2323        target string
    2424)
     
    3535
    3636func loadCfg() {
    37         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")
    38         flag.StringVar(&input, "i", "", "Enter the text to be translated")
    39         flag.StringVar(&target, "t", "", "Set the language to translate to")
     37        flaggy.SetName("suwako")
     38        flaggy.SetDescription("Command line client for SimplyTranslate")
     39        flaggy.SetVersion(suwako.FullVersion())
    4040
    41         flag.Usage = func() {
    42                 fmt.Printf("usage: suwako -f [lang] -i [text] -t [lang]\nversion: %v\n", suwako.FullVersion())
    43         }
     41        flaggy.String(&source, "f", "from", "Source language")
     42        flaggy.String(&target, "t", "to", "Target language")
     43        flaggy.AddPositionalValue(&input, "input", 1, true, "Text to translate")
    4444
    4545        home, err := os.UserHomeDir()
     
    5252        instance = os.Getenv("SUWAKO_INSTANCE")
    5353
    54         flag.Parse()
     54        flaggy.Parse()
    5555}
    5656
     
    6060
    6161        // Verify command-line inputs
    62         if len(input) == 0 {
    63                 log.Fatal("There is no input")
    64         }
    6562        if len(target) == 0 {
    6663                log.Fatal("No target language")
  • trunk/go.mod

    r21 r23  
    33go 1.18
    44
    5 require github.com/joho/godotenv v1.5.1
     5require (
     6        github.com/integrii/flaggy v1.5.2
     7        github.com/joho/godotenv v1.5.1
     8)
  • trunk/go.sum

    r21 r23  
     1github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
     2github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
     3github.com/integrii/flaggy v1.5.2 h1:bWV20MQEngo4hWhno3i5Z9ISPxLPKj9NOGNwTWb/8IQ=
     4github.com/integrii/flaggy v1.5.2/go.mod h1:dO13u7SYuhk910nayCJ+s1DeAAGC1THCMj1uSFmwtQ8=
    15github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
    26github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
     7golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Note: See TracChangeset for help on using the changeset viewer.