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

View file

@ -1,22 +1,39 @@
package enc
import "surdeus.su/core/cli/mtool"
import "io"
import "os"
import (
"bytes"
"io"
"os"
"surdeus.su/core/cli/mtool"
)
type EncodeOptions struct {
}
func NewEncodeTool(
name string,
encFn func (io.Writer) io.Writer,
encFn func(io.Writer) io.Writer,
) *mtool.Tool {
ret := mtool.T(name).Func(func(flags *mtool.Flags){
//var opts EncodeOptions
_ = flags.Parse()
ret := mtool.T(name).Func(func(flags *mtool.Flags) {
args := flags.Parse()
var (
input io.Reader
output io.Writer
)
input := os.Stdin
output := os.Stdout
input = os.Stdin
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)
io.Copy(encOutput, input)
@ -24,4 +41,3 @@ func NewEncodeTool(
return ret
}