]> Git repositories of Izuru Yakumo - suwako.git/commitdiff
Mirrored from suwako.git master
authorwww <www@3ef18a7e-565d-fa41-9089-0c174edf95f4>
Sun, 29 Sep 2024 21:30:01 +0000 (21:30 +0000)
committerwww <www@3ef18a7e-565d-fa41-9089-0c174edf95f4>
Sun, 29 Sep 2024 21:30:01 +0000 (21:30 +0000)
git-svn-id: https://svn.chaotic.ninja/svn/suwako-yakumo.izuru@1 3ef18a7e-565d-fa41-9089-0c174edf95f4

44 files changed:
branches/master/.gitignore [new file with mode: 0644]
branches/master/COPYING [new file with mode: 0644]
branches/master/Makefile [new file with mode: 0644]
branches/master/README.md [new file with mode: 0644]
branches/master/cmd/suwako/main.go [new file with mode: 0644]
branches/master/doc.go [new file with mode: 0644]
branches/master/go.mod [new file with mode: 0644]
branches/master/go.sum [new file with mode: 0644]
branches/master/suwako.1 [new file with mode: 0644]
branches/master/suwako.conf.5 [new file with mode: 0644]
branches/master/version.go [new file with mode: 0644]
branches/origin-master/.gitignore [new file with mode: 0644]
branches/origin-master/COPYING [new file with mode: 0644]
branches/origin-master/Makefile [new file with mode: 0644]
branches/origin-master/README.md [new file with mode: 0644]
branches/origin-master/cmd/suwako/main.go [new file with mode: 0644]
branches/origin-master/doc.go [new file with mode: 0644]
branches/origin-master/go.mod [new file with mode: 0644]
branches/origin-master/go.sum [new file with mode: 0644]
branches/origin-master/suwako.1 [new file with mode: 0644]
branches/origin-master/suwako.conf.5 [new file with mode: 0644]
branches/origin-master/version.go [new file with mode: 0644]
branches/origin/.gitignore [new file with mode: 0644]
branches/origin/COPYING [new file with mode: 0644]
branches/origin/Makefile [new file with mode: 0644]
branches/origin/README.md [new file with mode: 0644]
branches/origin/cmd/suwako/main.go [new file with mode: 0644]
branches/origin/doc.go [new file with mode: 0644]
branches/origin/go.mod [new file with mode: 0644]
branches/origin/go.sum [new file with mode: 0644]
branches/origin/suwako.1 [new file with mode: 0644]
branches/origin/suwako.conf.5 [new file with mode: 0644]
branches/origin/version.go [new file with mode: 0644]
trunk/.gitignore [new file with mode: 0644]
trunk/COPYING [new file with mode: 0644]
trunk/Makefile [new file with mode: 0644]
trunk/README.md [new file with mode: 0644]
trunk/cmd/suwako/main.go [new file with mode: 0644]
trunk/doc.go [new file with mode: 0644]
trunk/go.mod [new file with mode: 0644]
trunk/go.sum [new file with mode: 0644]
trunk/suwako.1 [new file with mode: 0644]
trunk/suwako.conf.5 [new file with mode: 0644]
trunk/version.go [new file with mode: 0644]

diff --git a/branches/master/.gitignore b/branches/master/.gitignore
new file mode 100644 (file)
index 0000000..7a9b2f4
--- /dev/null
@@ -0,0 +1,2 @@
+!/cmd/suwako
+suwako
diff --git a/branches/master/COPYING b/branches/master/COPYING
new file mode 100644 (file)
index 0000000..e31cea1
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42.1):
+ * <yakumo.izuru@chaotic.ninja> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a bottle of sake in return Izuru Yakumo
+ * ----------------------------------------------------------------------------
+ */
diff --git a/branches/master/Makefile b/branches/master/Makefile
new file mode 100644 (file)
index 0000000..02ad292
--- /dev/null
@@ -0,0 +1,22 @@
+PREFIX ?= /usr/local
+
+GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=${VERSION} -X `go list`.Commit=${COMMIT} -X `go list`.Build=${BUILD}" -tags "static_build"
+
+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"`
+
+all: suwako
+
+suwako:
+       go build ${GOFLAGS} ./cmd/suwako
+clean:
+       rm -f suwako
+install: 
+       install -Dm0755 suwako ${PREFIX}/bin/suwako
+       install -Dm0644 suwako.1 ${PREFIX}/share/man/man1/suwako.1
+       install -Dm0644 suwako.conf.5 ${PREFIX}/share/man/man5/suwako.conf.5
+uninstall:
+       rm -f ${PREFIX}/bin/suwako
+       rm -f ${PREFIX}/share/man/man1/suwako.1
diff --git a/branches/master/README.md b/branches/master/README.md
new file mode 100644 (file)
index 0000000..6e84d8b
--- /dev/null
@@ -0,0 +1,50 @@
+SUWAKO(1) - FreeBSD General Commands Manual
+
+# NAME
+
+**suwako** - Command-line client for SimplyTranslate
+
+# SYNOPSIS
+
+**suwako**
+\[**-f**&nbsp;*from*]
+\[**-t**&nbsp;*to*]
+\[*input*]
+
+# DESCRIPTION
+
+Self-explanatory, besides, this was made as
+a rewrite from a shell script that had curl
+and awk for dependencies.
+It fully serves
+as a drop-in replacement.
+
+# USAGE
+
+**-f**
+
+> Input language to translate from.
+> Default is 'auto'
+
+**-t**
+
+> Target language to translate to
+
+&lt;input&gt;
+
+> Text to be translated
+
+# SEE ALSO
+
+suwako.conf(5)
+
+# AUTHORS
+
+Izuru Yakumo &lt;[yakumo.izuru@chaotic.ninja](mailto:yakumo.izuru@chaotic.ninja)&gt;
+
+# BUGS
+
+You cannot translate the string "version", this is
+a direct consequence of using flaggy.
+
+FreeBSD 13.2-RELEASE-p4 - December 16, 2023
diff --git a/branches/master/cmd/suwako/main.go b/branches/master/cmd/suwako/main.go
new file mode 100644 (file)
index 0000000..147baaf
--- /dev/null
@@ -0,0 +1,100 @@
+// $TheSupernovaDuo: suwako,v 1.5.5 2024/01/20 21:07:30 yakumo_izuru Exp $
+// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
+package main
+
+import (
+       "encoding/json"
+       "fmt"
+       "log"
+       "net/http"
+       "net/url"
+       "os"
+
+       "github.com/integrii/flaggy"
+       "gopkg.in/ini.v1"
+       "marisa.chaotic.ninja/suwako"
+)
+
+var conf struct {
+       engine string
+       instance string
+}
+
+var (
+       input string
+       source string = "auto"
+       target string
+)
+
+type Translate struct {
+       Output string `json:"translated_text"`
+}
+
+func errCheck(err error) {
+       if err != nil {
+               log.Println("Something happened :(")
+               log.Fatal(err)
+       }
+}
+
+func iniLoad(file string) error {
+       cfg, err := ini.Load(file)
+       if err != nil {
+               return err
+       }
+       conf.engine = cfg.Section("suwako").Key("engine").String()
+       conf.instance = cfg.Section("suwako").Key("instance").String()
+
+       return nil
+}
+
+func flagParse() {
+       flaggy.SetName("suwako")
+       flaggy.SetDescription("Command line client for SimplyTranslate")
+       flaggy.SetVersion(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")
+
+       flaggy.Parse()
+}
+
+func main() {
+       // Flag parsing
+       flagParse()
+
+       // Load configuration file
+       config, err := os.UserConfigDir()
+       errCheck(err)
+       cfgfile := config + "/suwako/suwako.ini"
+       iniLoad(cfgfile)
+
+       // Verify command-line inputs
+       if len(target) == 0 {
+               log.Fatal("No target language")
+       }
+       
+       // Map variable to struct
+       var translate Translate
+
+       // Encode input just in case
+       var encInput = url.PathEscape(input)
+
+       // Construct the final path to query
+       var queryURL = conf.instance + "/api/translate/" + "?engine=" + conf.engine + "&from=" + source + "&to=" + target + "&text=" + encInput
+
+       // Shoot danmaku to path
+       resp, err := http.Get(queryURL)
+       errCheck(err)
+       defer resp.Body.Close()
+
+       // Decode JSON response, discard everything else, print to standard output
+       _ = json.NewDecoder(resp.Body).Decode(&translate)
+       errCheck(err)
+       if len(translate.Output) == 0 {
+               log.Fatal("There was no output, maybe the server was down?")
+       } else {
+               fmt.Printf("%v\n", translate.Output)
+       }
+}
diff --git a/branches/master/doc.go b/branches/master/doc.go
new file mode 100644 (file)
index 0000000..730eb37
--- /dev/null
@@ -0,0 +1,2 @@
+// package suwako is yet another client for SimplyTranslate https://simple-web.org/projects/simplytranslate.html written in Go.
+package suwako
diff --git a/branches/master/go.mod b/branches/master/go.mod
new file mode 100644 (file)
index 0000000..f7ceef2
--- /dev/null
@@ -0,0 +1,10 @@
+module marisa.chaotic.ninja/suwako
+
+go 1.18
+
+require (
+       github.com/integrii/flaggy v1.5.2
+       gopkg.in/ini.v1 v1.67.0
+)
+
+require github.com/stretchr/testify v1.8.4 // indirect
diff --git a/branches/master/go.sum b/branches/master/go.sum
new file mode 100644 (file)
index 0000000..684fb31
--- /dev/null
@@ -0,0 +1,12 @@
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
+gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/branches/master/suwako.1 b/branches/master/suwako.1
new file mode 100644 (file)
index 0000000..984e9dc
--- /dev/null
@@ -0,0 +1,34 @@
+.Dd $Mdocdate$
+.Dt SUWAKO 1
+.Os
+.Sh NAME
+.Nm suwako
+.Nd Command-line client for SimplyTranslate
+.Sh SYNOPSIS
+.Nm
+.Op Fl f Ar from
+.Op Fl t Ar to
+.Op Ar input
+.Sh DESCRIPTION
+Self-explanatory, besides, this was made as
+a rewrite from a shell script that had curl
+and awk for dependencies.
+It fully serves
+as a drop-in replacement.
+.Sh USAGE
+.Bl -tag -width 11n -compact
+.It Fl f
+Input language to translate from.
+Default is 'auto'
+.It Fl t
+Target language to translate to
+.It <input>
+Text to be translated
+.El
+.Sh SEE ALSO
+.Xr suwako.conf 5
+.Sh AUTHORS
+.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
+.Sh BUGS
+You cannot translate the string "version", this is
+a direct consequence of using flaggy.
diff --git a/branches/master/suwako.conf.5 b/branches/master/suwako.conf.5
new file mode 100644 (file)
index 0000000..39c0e98
--- /dev/null
@@ -0,0 +1,36 @@
+.Dd $Mdocdate$
+.Dt SUWAKO.CONF 5
+.Os
+.Sh NAME
+.Nm suwako.conf
+.Nd INI-style configuration file for
+.Xr suwako 1
+.Sh DESCRIPTION
+The
+.Nm
+file specifies the instance address,
+including the API path and the
+translation engine to be used on
+the
+.Xr suwako 1
+command.
+.Sh OPTIONS
+.Bl -tag -width 11n -compact
+.It instance
+Contains the HTTPS URI to the
+server's up to the
+.Sy /api/translate
+endpoint.
+.It engine
+For most use cases, the
+.Em google
+engine should be enough,
+though some endpoints
+support more translation
+engines.
+.El
+.Sh FILES
+.Pa ~/.suwako/suwako.conf
+path to this file
+.Sh AUTHORS
+.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
diff --git a/branches/master/version.go b/branches/master/version.go
new file mode 100644 (file)
index 0000000..144213d
--- /dev/null
@@ -0,0 +1,50 @@
+package suwako
+
+import (
+       "fmt"
+       "runtime/debug"
+       "strings"
+)
+
+const (
+       defaultVersion = "0.0.0"
+       defaultCommit  = "HEAD"
+       defaultBuild   = "0000-01-01:00:00+00:00"
+)
+
+var (
+       // Version is the tagged release version in the form <major>.<minor>.<patch>
+       // following semantic versioning and is overwritten by the build system.
+       Version = defaultVersion
+
+       // Commit is the commit sha of the build (normally from Git) and is overwritten
+       // by the build system.
+       Commit = defaultCommit
+
+       // Build is the date and time of the build as an RFC3339 formatted string
+       // and is overwritten by the build system.
+       Build = defaultBuild
+)
+
+// FullVersion display the full version and build
+func FullVersion() string {
+       var sb strings.Builder
+
+       isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
+
+       if !isDefault {
+               sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
+       }
+
+       if info, ok := debug.ReadBuildInfo(); ok {
+               if isDefault {
+                       sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
+               }
+               sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
+               if info.Main.Sum != "" {
+                       sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
+               }
+       }
+
+       return sb.String()
+}
diff --git a/branches/origin-master/.gitignore b/branches/origin-master/.gitignore
new file mode 100644 (file)
index 0000000..7a9b2f4
--- /dev/null
@@ -0,0 +1,2 @@
+!/cmd/suwako
+suwako
diff --git a/branches/origin-master/COPYING b/branches/origin-master/COPYING
new file mode 100644 (file)
index 0000000..e31cea1
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42.1):
+ * <yakumo.izuru@chaotic.ninja> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a bottle of sake in return Izuru Yakumo
+ * ----------------------------------------------------------------------------
+ */
diff --git a/branches/origin-master/Makefile b/branches/origin-master/Makefile
new file mode 100644 (file)
index 0000000..02ad292
--- /dev/null
@@ -0,0 +1,22 @@
+PREFIX ?= /usr/local
+
+GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=${VERSION} -X `go list`.Commit=${COMMIT} -X `go list`.Build=${BUILD}" -tags "static_build"
+
+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"`
+
+all: suwako
+
+suwako:
+       go build ${GOFLAGS} ./cmd/suwako
+clean:
+       rm -f suwako
+install: 
+       install -Dm0755 suwako ${PREFIX}/bin/suwako
+       install -Dm0644 suwako.1 ${PREFIX}/share/man/man1/suwako.1
+       install -Dm0644 suwako.conf.5 ${PREFIX}/share/man/man5/suwako.conf.5
+uninstall:
+       rm -f ${PREFIX}/bin/suwako
+       rm -f ${PREFIX}/share/man/man1/suwako.1
diff --git a/branches/origin-master/README.md b/branches/origin-master/README.md
new file mode 100644 (file)
index 0000000..6e84d8b
--- /dev/null
@@ -0,0 +1,50 @@
+SUWAKO(1) - FreeBSD General Commands Manual
+
+# NAME
+
+**suwako** - Command-line client for SimplyTranslate
+
+# SYNOPSIS
+
+**suwako**
+\[**-f**&nbsp;*from*]
+\[**-t**&nbsp;*to*]
+\[*input*]
+
+# DESCRIPTION
+
+Self-explanatory, besides, this was made as
+a rewrite from a shell script that had curl
+and awk for dependencies.
+It fully serves
+as a drop-in replacement.
+
+# USAGE
+
+**-f**
+
+> Input language to translate from.
+> Default is 'auto'
+
+**-t**
+
+> Target language to translate to
+
+&lt;input&gt;
+
+> Text to be translated
+
+# SEE ALSO
+
+suwako.conf(5)
+
+# AUTHORS
+
+Izuru Yakumo &lt;[yakumo.izuru@chaotic.ninja](mailto:yakumo.izuru@chaotic.ninja)&gt;
+
+# BUGS
+
+You cannot translate the string "version", this is
+a direct consequence of using flaggy.
+
+FreeBSD 13.2-RELEASE-p4 - December 16, 2023
diff --git a/branches/origin-master/cmd/suwako/main.go b/branches/origin-master/cmd/suwako/main.go
new file mode 100644 (file)
index 0000000..147baaf
--- /dev/null
@@ -0,0 +1,100 @@
+// $TheSupernovaDuo: suwako,v 1.5.5 2024/01/20 21:07:30 yakumo_izuru Exp $
+// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
+package main
+
+import (
+       "encoding/json"
+       "fmt"
+       "log"
+       "net/http"
+       "net/url"
+       "os"
+
+       "github.com/integrii/flaggy"
+       "gopkg.in/ini.v1"
+       "marisa.chaotic.ninja/suwako"
+)
+
+var conf struct {
+       engine string
+       instance string
+}
+
+var (
+       input string
+       source string = "auto"
+       target string
+)
+
+type Translate struct {
+       Output string `json:"translated_text"`
+}
+
+func errCheck(err error) {
+       if err != nil {
+               log.Println("Something happened :(")
+               log.Fatal(err)
+       }
+}
+
+func iniLoad(file string) error {
+       cfg, err := ini.Load(file)
+       if err != nil {
+               return err
+       }
+       conf.engine = cfg.Section("suwako").Key("engine").String()
+       conf.instance = cfg.Section("suwako").Key("instance").String()
+
+       return nil
+}
+
+func flagParse() {
+       flaggy.SetName("suwako")
+       flaggy.SetDescription("Command line client for SimplyTranslate")
+       flaggy.SetVersion(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")
+
+       flaggy.Parse()
+}
+
+func main() {
+       // Flag parsing
+       flagParse()
+
+       // Load configuration file
+       config, err := os.UserConfigDir()
+       errCheck(err)
+       cfgfile := config + "/suwako/suwako.ini"
+       iniLoad(cfgfile)
+
+       // Verify command-line inputs
+       if len(target) == 0 {
+               log.Fatal("No target language")
+       }
+       
+       // Map variable to struct
+       var translate Translate
+
+       // Encode input just in case
+       var encInput = url.PathEscape(input)
+
+       // Construct the final path to query
+       var queryURL = conf.instance + "/api/translate/" + "?engine=" + conf.engine + "&from=" + source + "&to=" + target + "&text=" + encInput
+
+       // Shoot danmaku to path
+       resp, err := http.Get(queryURL)
+       errCheck(err)
+       defer resp.Body.Close()
+
+       // Decode JSON response, discard everything else, print to standard output
+       _ = json.NewDecoder(resp.Body).Decode(&translate)
+       errCheck(err)
+       if len(translate.Output) == 0 {
+               log.Fatal("There was no output, maybe the server was down?")
+       } else {
+               fmt.Printf("%v\n", translate.Output)
+       }
+}
diff --git a/branches/origin-master/doc.go b/branches/origin-master/doc.go
new file mode 100644 (file)
index 0000000..730eb37
--- /dev/null
@@ -0,0 +1,2 @@
+// package suwako is yet another client for SimplyTranslate https://simple-web.org/projects/simplytranslate.html written in Go.
+package suwako
diff --git a/branches/origin-master/go.mod b/branches/origin-master/go.mod
new file mode 100644 (file)
index 0000000..f7ceef2
--- /dev/null
@@ -0,0 +1,10 @@
+module marisa.chaotic.ninja/suwako
+
+go 1.18
+
+require (
+       github.com/integrii/flaggy v1.5.2
+       gopkg.in/ini.v1 v1.67.0
+)
+
+require github.com/stretchr/testify v1.8.4 // indirect
diff --git a/branches/origin-master/go.sum b/branches/origin-master/go.sum
new file mode 100644 (file)
index 0000000..684fb31
--- /dev/null
@@ -0,0 +1,12 @@
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
+gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/branches/origin-master/suwako.1 b/branches/origin-master/suwako.1
new file mode 100644 (file)
index 0000000..984e9dc
--- /dev/null
@@ -0,0 +1,34 @@
+.Dd $Mdocdate$
+.Dt SUWAKO 1
+.Os
+.Sh NAME
+.Nm suwako
+.Nd Command-line client for SimplyTranslate
+.Sh SYNOPSIS
+.Nm
+.Op Fl f Ar from
+.Op Fl t Ar to
+.Op Ar input
+.Sh DESCRIPTION
+Self-explanatory, besides, this was made as
+a rewrite from a shell script that had curl
+and awk for dependencies.
+It fully serves
+as a drop-in replacement.
+.Sh USAGE
+.Bl -tag -width 11n -compact
+.It Fl f
+Input language to translate from.
+Default is 'auto'
+.It Fl t
+Target language to translate to
+.It <input>
+Text to be translated
+.El
+.Sh SEE ALSO
+.Xr suwako.conf 5
+.Sh AUTHORS
+.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
+.Sh BUGS
+You cannot translate the string "version", this is
+a direct consequence of using flaggy.
diff --git a/branches/origin-master/suwako.conf.5 b/branches/origin-master/suwako.conf.5
new file mode 100644 (file)
index 0000000..39c0e98
--- /dev/null
@@ -0,0 +1,36 @@
+.Dd $Mdocdate$
+.Dt SUWAKO.CONF 5
+.Os
+.Sh NAME
+.Nm suwako.conf
+.Nd INI-style configuration file for
+.Xr suwako 1
+.Sh DESCRIPTION
+The
+.Nm
+file specifies the instance address,
+including the API path and the
+translation engine to be used on
+the
+.Xr suwako 1
+command.
+.Sh OPTIONS
+.Bl -tag -width 11n -compact
+.It instance
+Contains the HTTPS URI to the
+server's up to the
+.Sy /api/translate
+endpoint.
+.It engine
+For most use cases, the
+.Em google
+engine should be enough,
+though some endpoints
+support more translation
+engines.
+.El
+.Sh FILES
+.Pa ~/.suwako/suwako.conf
+path to this file
+.Sh AUTHORS
+.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
diff --git a/branches/origin-master/version.go b/branches/origin-master/version.go
new file mode 100644 (file)
index 0000000..144213d
--- /dev/null
@@ -0,0 +1,50 @@
+package suwako
+
+import (
+       "fmt"
+       "runtime/debug"
+       "strings"
+)
+
+const (
+       defaultVersion = "0.0.0"
+       defaultCommit  = "HEAD"
+       defaultBuild   = "0000-01-01:00:00+00:00"
+)
+
+var (
+       // Version is the tagged release version in the form <major>.<minor>.<patch>
+       // following semantic versioning and is overwritten by the build system.
+       Version = defaultVersion
+
+       // Commit is the commit sha of the build (normally from Git) and is overwritten
+       // by the build system.
+       Commit = defaultCommit
+
+       // Build is the date and time of the build as an RFC3339 formatted string
+       // and is overwritten by the build system.
+       Build = defaultBuild
+)
+
+// FullVersion display the full version and build
+func FullVersion() string {
+       var sb strings.Builder
+
+       isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
+
+       if !isDefault {
+               sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
+       }
+
+       if info, ok := debug.ReadBuildInfo(); ok {
+               if isDefault {
+                       sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
+               }
+               sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
+               if info.Main.Sum != "" {
+                       sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
+               }
+       }
+
+       return sb.String()
+}
diff --git a/branches/origin/.gitignore b/branches/origin/.gitignore
new file mode 100644 (file)
index 0000000..7a9b2f4
--- /dev/null
@@ -0,0 +1,2 @@
+!/cmd/suwako
+suwako
diff --git a/branches/origin/COPYING b/branches/origin/COPYING
new file mode 100644 (file)
index 0000000..e31cea1
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42.1):
+ * <yakumo.izuru@chaotic.ninja> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a bottle of sake in return Izuru Yakumo
+ * ----------------------------------------------------------------------------
+ */
diff --git a/branches/origin/Makefile b/branches/origin/Makefile
new file mode 100644 (file)
index 0000000..02ad292
--- /dev/null
@@ -0,0 +1,22 @@
+PREFIX ?= /usr/local
+
+GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=${VERSION} -X `go list`.Commit=${COMMIT} -X `go list`.Build=${BUILD}" -tags "static_build"
+
+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"`
+
+all: suwako
+
+suwako:
+       go build ${GOFLAGS} ./cmd/suwako
+clean:
+       rm -f suwako
+install: 
+       install -Dm0755 suwako ${PREFIX}/bin/suwako
+       install -Dm0644 suwako.1 ${PREFIX}/share/man/man1/suwako.1
+       install -Dm0644 suwako.conf.5 ${PREFIX}/share/man/man5/suwako.conf.5
+uninstall:
+       rm -f ${PREFIX}/bin/suwako
+       rm -f ${PREFIX}/share/man/man1/suwako.1
diff --git a/branches/origin/README.md b/branches/origin/README.md
new file mode 100644 (file)
index 0000000..6e84d8b
--- /dev/null
@@ -0,0 +1,50 @@
+SUWAKO(1) - FreeBSD General Commands Manual
+
+# NAME
+
+**suwako** - Command-line client for SimplyTranslate
+
+# SYNOPSIS
+
+**suwako**
+\[**-f**&nbsp;*from*]
+\[**-t**&nbsp;*to*]
+\[*input*]
+
+# DESCRIPTION
+
+Self-explanatory, besides, this was made as
+a rewrite from a shell script that had curl
+and awk for dependencies.
+It fully serves
+as a drop-in replacement.
+
+# USAGE
+
+**-f**
+
+> Input language to translate from.
+> Default is 'auto'
+
+**-t**
+
+> Target language to translate to
+
+&lt;input&gt;
+
+> Text to be translated
+
+# SEE ALSO
+
+suwako.conf(5)
+
+# AUTHORS
+
+Izuru Yakumo &lt;[yakumo.izuru@chaotic.ninja](mailto:yakumo.izuru@chaotic.ninja)&gt;
+
+# BUGS
+
+You cannot translate the string "version", this is
+a direct consequence of using flaggy.
+
+FreeBSD 13.2-RELEASE-p4 - December 16, 2023
diff --git a/branches/origin/cmd/suwako/main.go b/branches/origin/cmd/suwako/main.go
new file mode 100644 (file)
index 0000000..147baaf
--- /dev/null
@@ -0,0 +1,100 @@
+// $TheSupernovaDuo: suwako,v 1.5.5 2024/01/20 21:07:30 yakumo_izuru Exp $
+// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
+package main
+
+import (
+       "encoding/json"
+       "fmt"
+       "log"
+       "net/http"
+       "net/url"
+       "os"
+
+       "github.com/integrii/flaggy"
+       "gopkg.in/ini.v1"
+       "marisa.chaotic.ninja/suwako"
+)
+
+var conf struct {
+       engine string
+       instance string
+}
+
+var (
+       input string
+       source string = "auto"
+       target string
+)
+
+type Translate struct {
+       Output string `json:"translated_text"`
+}
+
+func errCheck(err error) {
+       if err != nil {
+               log.Println("Something happened :(")
+               log.Fatal(err)
+       }
+}
+
+func iniLoad(file string) error {
+       cfg, err := ini.Load(file)
+       if err != nil {
+               return err
+       }
+       conf.engine = cfg.Section("suwako").Key("engine").String()
+       conf.instance = cfg.Section("suwako").Key("instance").String()
+
+       return nil
+}
+
+func flagParse() {
+       flaggy.SetName("suwako")
+       flaggy.SetDescription("Command line client for SimplyTranslate")
+       flaggy.SetVersion(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")
+
+       flaggy.Parse()
+}
+
+func main() {
+       // Flag parsing
+       flagParse()
+
+       // Load configuration file
+       config, err := os.UserConfigDir()
+       errCheck(err)
+       cfgfile := config + "/suwako/suwako.ini"
+       iniLoad(cfgfile)
+
+       // Verify command-line inputs
+       if len(target) == 0 {
+               log.Fatal("No target language")
+       }
+       
+       // Map variable to struct
+       var translate Translate
+
+       // Encode input just in case
+       var encInput = url.PathEscape(input)
+
+       // Construct the final path to query
+       var queryURL = conf.instance + "/api/translate/" + "?engine=" + conf.engine + "&from=" + source + "&to=" + target + "&text=" + encInput
+
+       // Shoot danmaku to path
+       resp, err := http.Get(queryURL)
+       errCheck(err)
+       defer resp.Body.Close()
+
+       // Decode JSON response, discard everything else, print to standard output
+       _ = json.NewDecoder(resp.Body).Decode(&translate)
+       errCheck(err)
+       if len(translate.Output) == 0 {
+               log.Fatal("There was no output, maybe the server was down?")
+       } else {
+               fmt.Printf("%v\n", translate.Output)
+       }
+}
diff --git a/branches/origin/doc.go b/branches/origin/doc.go
new file mode 100644 (file)
index 0000000..730eb37
--- /dev/null
@@ -0,0 +1,2 @@
+// package suwako is yet another client for SimplyTranslate https://simple-web.org/projects/simplytranslate.html written in Go.
+package suwako
diff --git a/branches/origin/go.mod b/branches/origin/go.mod
new file mode 100644 (file)
index 0000000..f7ceef2
--- /dev/null
@@ -0,0 +1,10 @@
+module marisa.chaotic.ninja/suwako
+
+go 1.18
+
+require (
+       github.com/integrii/flaggy v1.5.2
+       gopkg.in/ini.v1 v1.67.0
+)
+
+require github.com/stretchr/testify v1.8.4 // indirect
diff --git a/branches/origin/go.sum b/branches/origin/go.sum
new file mode 100644 (file)
index 0000000..684fb31
--- /dev/null
@@ -0,0 +1,12 @@
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
+gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/branches/origin/suwako.1 b/branches/origin/suwako.1
new file mode 100644 (file)
index 0000000..984e9dc
--- /dev/null
@@ -0,0 +1,34 @@
+.Dd $Mdocdate$
+.Dt SUWAKO 1
+.Os
+.Sh NAME
+.Nm suwako
+.Nd Command-line client for SimplyTranslate
+.Sh SYNOPSIS
+.Nm
+.Op Fl f Ar from
+.Op Fl t Ar to
+.Op Ar input
+.Sh DESCRIPTION
+Self-explanatory, besides, this was made as
+a rewrite from a shell script that had curl
+and awk for dependencies.
+It fully serves
+as a drop-in replacement.
+.Sh USAGE
+.Bl -tag -width 11n -compact
+.It Fl f
+Input language to translate from.
+Default is 'auto'
+.It Fl t
+Target language to translate to
+.It <input>
+Text to be translated
+.El
+.Sh SEE ALSO
+.Xr suwako.conf 5
+.Sh AUTHORS
+.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
+.Sh BUGS
+You cannot translate the string "version", this is
+a direct consequence of using flaggy.
diff --git a/branches/origin/suwako.conf.5 b/branches/origin/suwako.conf.5
new file mode 100644 (file)
index 0000000..39c0e98
--- /dev/null
@@ -0,0 +1,36 @@
+.Dd $Mdocdate$
+.Dt SUWAKO.CONF 5
+.Os
+.Sh NAME
+.Nm suwako.conf
+.Nd INI-style configuration file for
+.Xr suwako 1
+.Sh DESCRIPTION
+The
+.Nm
+file specifies the instance address,
+including the API path and the
+translation engine to be used on
+the
+.Xr suwako 1
+command.
+.Sh OPTIONS
+.Bl -tag -width 11n -compact
+.It instance
+Contains the HTTPS URI to the
+server's up to the
+.Sy /api/translate
+endpoint.
+.It engine
+For most use cases, the
+.Em google
+engine should be enough,
+though some endpoints
+support more translation
+engines.
+.El
+.Sh FILES
+.Pa ~/.suwako/suwako.conf
+path to this file
+.Sh AUTHORS
+.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
diff --git a/branches/origin/version.go b/branches/origin/version.go
new file mode 100644 (file)
index 0000000..144213d
--- /dev/null
@@ -0,0 +1,50 @@
+package suwako
+
+import (
+       "fmt"
+       "runtime/debug"
+       "strings"
+)
+
+const (
+       defaultVersion = "0.0.0"
+       defaultCommit  = "HEAD"
+       defaultBuild   = "0000-01-01:00:00+00:00"
+)
+
+var (
+       // Version is the tagged release version in the form <major>.<minor>.<patch>
+       // following semantic versioning and is overwritten by the build system.
+       Version = defaultVersion
+
+       // Commit is the commit sha of the build (normally from Git) and is overwritten
+       // by the build system.
+       Commit = defaultCommit
+
+       // Build is the date and time of the build as an RFC3339 formatted string
+       // and is overwritten by the build system.
+       Build = defaultBuild
+)
+
+// FullVersion display the full version and build
+func FullVersion() string {
+       var sb strings.Builder
+
+       isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
+
+       if !isDefault {
+               sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
+       }
+
+       if info, ok := debug.ReadBuildInfo(); ok {
+               if isDefault {
+                       sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
+               }
+               sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
+               if info.Main.Sum != "" {
+                       sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
+               }
+       }
+
+       return sb.String()
+}
diff --git a/trunk/.gitignore b/trunk/.gitignore
new file mode 100644 (file)
index 0000000..7a9b2f4
--- /dev/null
@@ -0,0 +1,2 @@
+!/cmd/suwako
+suwako
diff --git a/trunk/COPYING b/trunk/COPYING
new file mode 100644 (file)
index 0000000..e31cea1
--- /dev/null
@@ -0,0 +1,8 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42.1):
+ * <yakumo.izuru@chaotic.ninja> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a bottle of sake in return Izuru Yakumo
+ * ----------------------------------------------------------------------------
+ */
diff --git a/trunk/Makefile b/trunk/Makefile
new file mode 100644 (file)
index 0000000..02ad292
--- /dev/null
@@ -0,0 +1,22 @@
+PREFIX ?= /usr/local
+
+GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=${VERSION} -X `go list`.Commit=${COMMIT} -X `go list`.Build=${BUILD}" -tags "static_build"
+
+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"`
+
+all: suwako
+
+suwako:
+       go build ${GOFLAGS} ./cmd/suwako
+clean:
+       rm -f suwako
+install: 
+       install -Dm0755 suwako ${PREFIX}/bin/suwako
+       install -Dm0644 suwako.1 ${PREFIX}/share/man/man1/suwako.1
+       install -Dm0644 suwako.conf.5 ${PREFIX}/share/man/man5/suwako.conf.5
+uninstall:
+       rm -f ${PREFIX}/bin/suwako
+       rm -f ${PREFIX}/share/man/man1/suwako.1
diff --git a/trunk/README.md b/trunk/README.md
new file mode 100644 (file)
index 0000000..6e84d8b
--- /dev/null
@@ -0,0 +1,50 @@
+SUWAKO(1) - FreeBSD General Commands Manual
+
+# NAME
+
+**suwako** - Command-line client for SimplyTranslate
+
+# SYNOPSIS
+
+**suwako**
+\[**-f**&nbsp;*from*]
+\[**-t**&nbsp;*to*]
+\[*input*]
+
+# DESCRIPTION
+
+Self-explanatory, besides, this was made as
+a rewrite from a shell script that had curl
+and awk for dependencies.
+It fully serves
+as a drop-in replacement.
+
+# USAGE
+
+**-f**
+
+> Input language to translate from.
+> Default is 'auto'
+
+**-t**
+
+> Target language to translate to
+
+&lt;input&gt;
+
+> Text to be translated
+
+# SEE ALSO
+
+suwako.conf(5)
+
+# AUTHORS
+
+Izuru Yakumo &lt;[yakumo.izuru@chaotic.ninja](mailto:yakumo.izuru@chaotic.ninja)&gt;
+
+# BUGS
+
+You cannot translate the string "version", this is
+a direct consequence of using flaggy.
+
+FreeBSD 13.2-RELEASE-p4 - December 16, 2023
diff --git a/trunk/cmd/suwako/main.go b/trunk/cmd/suwako/main.go
new file mode 100644 (file)
index 0000000..147baaf
--- /dev/null
@@ -0,0 +1,100 @@
+// $TheSupernovaDuo: suwako,v 1.5.5 2024/01/20 21:07:30 yakumo_izuru Exp $
+// Command line client for SimplyTranslate, a privacy friendly frontend to other translation engines
+package main
+
+import (
+       "encoding/json"
+       "fmt"
+       "log"
+       "net/http"
+       "net/url"
+       "os"
+
+       "github.com/integrii/flaggy"
+       "gopkg.in/ini.v1"
+       "marisa.chaotic.ninja/suwako"
+)
+
+var conf struct {
+       engine string
+       instance string
+}
+
+var (
+       input string
+       source string = "auto"
+       target string
+)
+
+type Translate struct {
+       Output string `json:"translated_text"`
+}
+
+func errCheck(err error) {
+       if err != nil {
+               log.Println("Something happened :(")
+               log.Fatal(err)
+       }
+}
+
+func iniLoad(file string) error {
+       cfg, err := ini.Load(file)
+       if err != nil {
+               return err
+       }
+       conf.engine = cfg.Section("suwako").Key("engine").String()
+       conf.instance = cfg.Section("suwako").Key("instance").String()
+
+       return nil
+}
+
+func flagParse() {
+       flaggy.SetName("suwako")
+       flaggy.SetDescription("Command line client for SimplyTranslate")
+       flaggy.SetVersion(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")
+
+       flaggy.Parse()
+}
+
+func main() {
+       // Flag parsing
+       flagParse()
+
+       // Load configuration file
+       config, err := os.UserConfigDir()
+       errCheck(err)
+       cfgfile := config + "/suwako/suwako.ini"
+       iniLoad(cfgfile)
+
+       // Verify command-line inputs
+       if len(target) == 0 {
+               log.Fatal("No target language")
+       }
+       
+       // Map variable to struct
+       var translate Translate
+
+       // Encode input just in case
+       var encInput = url.PathEscape(input)
+
+       // Construct the final path to query
+       var queryURL = conf.instance + "/api/translate/" + "?engine=" + conf.engine + "&from=" + source + "&to=" + target + "&text=" + encInput
+
+       // Shoot danmaku to path
+       resp, err := http.Get(queryURL)
+       errCheck(err)
+       defer resp.Body.Close()
+
+       // Decode JSON response, discard everything else, print to standard output
+       _ = json.NewDecoder(resp.Body).Decode(&translate)
+       errCheck(err)
+       if len(translate.Output) == 0 {
+               log.Fatal("There was no output, maybe the server was down?")
+       } else {
+               fmt.Printf("%v\n", translate.Output)
+       }
+}
diff --git a/trunk/doc.go b/trunk/doc.go
new file mode 100644 (file)
index 0000000..730eb37
--- /dev/null
@@ -0,0 +1,2 @@
+// package suwako is yet another client for SimplyTranslate https://simple-web.org/projects/simplytranslate.html written in Go.
+package suwako
diff --git a/trunk/go.mod b/trunk/go.mod
new file mode 100644 (file)
index 0000000..f7ceef2
--- /dev/null
@@ -0,0 +1,10 @@
+module marisa.chaotic.ninja/suwako
+
+go 1.18
+
+require (
+       github.com/integrii/flaggy v1.5.2
+       gopkg.in/ini.v1 v1.67.0
+)
+
+require github.com/stretchr/testify v1.8.4 // indirect
diff --git a/trunk/go.sum b/trunk/go.sum
new file mode 100644 (file)
index 0000000..684fb31
--- /dev/null
@@ -0,0 +1,12 @@
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
+gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/trunk/suwako.1 b/trunk/suwako.1
new file mode 100644 (file)
index 0000000..984e9dc
--- /dev/null
@@ -0,0 +1,34 @@
+.Dd $Mdocdate$
+.Dt SUWAKO 1
+.Os
+.Sh NAME
+.Nm suwako
+.Nd Command-line client for SimplyTranslate
+.Sh SYNOPSIS
+.Nm
+.Op Fl f Ar from
+.Op Fl t Ar to
+.Op Ar input
+.Sh DESCRIPTION
+Self-explanatory, besides, this was made as
+a rewrite from a shell script that had curl
+and awk for dependencies.
+It fully serves
+as a drop-in replacement.
+.Sh USAGE
+.Bl -tag -width 11n -compact
+.It Fl f
+Input language to translate from.
+Default is 'auto'
+.It Fl t
+Target language to translate to
+.It <input>
+Text to be translated
+.El
+.Sh SEE ALSO
+.Xr suwako.conf 5
+.Sh AUTHORS
+.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
+.Sh BUGS
+You cannot translate the string "version", this is
+a direct consequence of using flaggy.
diff --git a/trunk/suwako.conf.5 b/trunk/suwako.conf.5
new file mode 100644 (file)
index 0000000..39c0e98
--- /dev/null
@@ -0,0 +1,36 @@
+.Dd $Mdocdate$
+.Dt SUWAKO.CONF 5
+.Os
+.Sh NAME
+.Nm suwako.conf
+.Nd INI-style configuration file for
+.Xr suwako 1
+.Sh DESCRIPTION
+The
+.Nm
+file specifies the instance address,
+including the API path and the
+translation engine to be used on
+the
+.Xr suwako 1
+command.
+.Sh OPTIONS
+.Bl -tag -width 11n -compact
+.It instance
+Contains the HTTPS URI to the
+server's up to the
+.Sy /api/translate
+endpoint.
+.It engine
+For most use cases, the
+.Em google
+engine should be enough,
+though some endpoints
+support more translation
+engines.
+.El
+.Sh FILES
+.Pa ~/.suwako/suwako.conf
+path to this file
+.Sh AUTHORS
+.An Izuru Yakumo Aq Mt yakumo.izuru@chaotic.ninja
diff --git a/trunk/version.go b/trunk/version.go
new file mode 100644 (file)
index 0000000..144213d
--- /dev/null
@@ -0,0 +1,50 @@
+package suwako
+
+import (
+       "fmt"
+       "runtime/debug"
+       "strings"
+)
+
+const (
+       defaultVersion = "0.0.0"
+       defaultCommit  = "HEAD"
+       defaultBuild   = "0000-01-01:00:00+00:00"
+)
+
+var (
+       // Version is the tagged release version in the form <major>.<minor>.<patch>
+       // following semantic versioning and is overwritten by the build system.
+       Version = defaultVersion
+
+       // Commit is the commit sha of the build (normally from Git) and is overwritten
+       // by the build system.
+       Commit = defaultCommit
+
+       // Build is the date and time of the build as an RFC3339 formatted string
+       // and is overwritten by the build system.
+       Build = defaultBuild
+)
+
+// FullVersion display the full version and build
+func FullVersion() string {
+       var sb strings.Builder
+
+       isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
+
+       if !isDefault {
+               sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
+       }
+
+       if info, ok := debug.ReadBuildInfo(); ok {
+               if isDefault {
+                       sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
+               }
+               sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
+               if info.Main.Sum != "" {
+                       sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
+               }
+       }
+
+       return sb.String()
+}