diff --git a/Makefile b/Makefile index c8619ac..fd173d8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,16 @@ -PREFIX=/usr/local +PREFIX ?= /usr/local + +GOARCH ?= amd64 +GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=$(VERSION) -X `go list`.Commit=$(COMMIT) -X `go list`.Build=$(BUILD)" -tags "static_build" +GOOS ?= linux + +BRANCH = `git rev-parse --abbrev-ref HEAD` +BUILD = `git show -s --pretty=format:%cI` +COMMIT = `git rev-parse --short HEAD || echo "$COMMIT"` +VERSION = `git describe --abbrev=0 --tags 2>/dev/null || echo "$VERSION"` build: - go build + go build $(GOFLAGS) ./cmd/stcli strip stcli clean: rm -f stcli diff --git a/README b/README index 05c8bbb..512d56b 100644 --- a/README +++ b/README @@ -4,14 +4,11 @@ Command-line client for SimplyTranslate in Go. Usage ----- --I string - Enter the text to be translated --e string - Translation engine to use (default: google) (default "google") --f string - Set the language to translate from. This can be skipped as it will autodetect the language you're translating from (default "auto") --i string - Instance to use (default: https://simplytranslate.org/api/translate/) (default "https://simplytranslate.org/api/translate/") --t string - Set the language to translate to (default: en) (default "en") +-f [lang] (default: auto) +-i [input] +-t [lang] (default: en) +Environment variables +--------------------- +* STCLI_ENGINE +* STCLI_INSTANCE diff --git a/main.go b/main.go deleted file mode 100644 index 7495daa..0000000 --- a/main.go +++ /dev/null @@ -1,59 +0,0 @@ -// $TheSupernovaDuo: stcli,v 1.4.0 2023/03/13 08:14:55 akoizumi 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" -) - -var ( - engine string - instance string - input string - source string - target string -) -type Translate struct { - Output string `json:"translated-text"` -} -func init() { - flag.StringVar(&engine, "e", "google", "Translation engine to use") - 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(&instance, "i", "https://translate.bus-hit.me", "Instance to use)") - flag.StringVar(&input, "I", "", "Enter the text to be translated") - flag.StringVar(&target, "t", "en", "Set the language to translate to") -} -func main() { - // Begin flag parsing - flag.Parse() - // Check if there's any input, otherwise bail out. - if len(input) == 0 { - log.Fatal("Missing input.") - } - // Map a variable to the struct - var translate Translate - // Build the full URL to query - var encInput = url.PathEscape(input) - var apiEndpoint = "/api/translate" - var queryURL = instance + apiEndpoint + "?engine=" + engine + "&from=" + source + "&to=" + target + "&text=" + encInput - // Begin the request and process the response - resp, err := http.Get(queryURL) - sanityCheck(err) - defer resp.Body.Close() - // JSON decoding - _ = json.NewDecoder(resp.Body).Decode(&translate) - sanityCheck(err) - // Pretty-print both the input and the output given. - fmt.Printf("Input: %v\n", input) - fmt.Printf("Output: %v\n",translate.Output) -} -func sanityCheck(err error) { - if err != nil { - log.Fatal(err) - } -}