This commit is contained in:
Andrey Parhomenko 2024-10-03 17:14:39 +05:00
parent 606232cfd3
commit 4a92d21a67
5 changed files with 41 additions and 22 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/exe/ /exe/
/gore

3
build Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
go build ./cmd/gore

View file

@ -1,3 +0,0 @@
#!/bin/sh
go build -o ./exe/ ./cmd/gore

View file

@ -1,20 +1,23 @@
package main package main
import "surdeus.su/core/cli/mtool" import (
import "surdeus.su/util/gore/enc" "encoding/base64"
import "encoding/hex" "encoding/hex"
import "encoding/base64" "io"
import "os" "os"
import "io"
"surdeus.su/core/cli/mtool"
"surdeus.su/util/gore/enc"
)
var root = mtool.T("gore").Subs( var root = mtool.T("gore").Subs(
mtool.T("encode-to").Subs( mtool.T("encode").Subs(
enc.NewEncodeTool( enc.NewEncodeTool(
"hex", "hex",
hex.NewEncoder, hex.NewEncoder,
), ),
enc.NewEncodeTool( enc.NewEncodeTool(
"base64", "b64",
func(w io.Writer) io.Writer { func(w io.Writer) io.Writer {
return base64.NewEncoder( return base64.NewEncoder(
base64.StdEncoding, base64.StdEncoding,
@ -28,4 +31,3 @@ var root = mtool.T("gore").Subs(
func main() { func main() {
root.Run(os.Args[1:]) root.Run(os.Args[1:])
} }

View file

@ -1,8 +1,12 @@
package enc package enc
import "surdeus.su/core/cli/mtool" import (
import "io" "bytes"
import "os" "io"
"os"
"surdeus.su/core/cli/mtool"
)
type EncodeOptions struct { type EncodeOptions struct {
} }
@ -12,11 +16,24 @@ func NewEncodeTool(
encFn func(io.Writer) io.Writer, encFn func(io.Writer) io.Writer,
) *mtool.Tool { ) *mtool.Tool {
ret := mtool.T(name).Func(func(flags *mtool.Flags) { ret := mtool.T(name).Func(func(flags *mtool.Flags) {
//var opts EncodeOptions args := flags.Parse()
_ = flags.Parse() var (
input io.Reader
output io.Writer
)
input := os.Stdin input = os.Stdin
output := os.Stdout output = os.Stdout
if len(args) > 0 {
var buf bytes.Buffer
input = &buf
for _, arg := range args {
buf.Write([]byte(arg))
}
} else {
input = os.Stdin
}
encOutput := encFn(output) encOutput := encFn(output)
io.Copy(encOutput, input) io.Copy(encOutput, input)
@ -24,4 +41,3 @@ func NewEncodeTool(
return ret return ret
} }