From 4a92d21a67bc00bc6706e5dac2d754462f4850ab Mon Sep 17 00:00:00 2001 From: surdeus Date: Thu, 3 Oct 2024 17:14:39 +0500 Subject: [PATCH] ... --- .gitignore | 1 + build | 3 +++ build.sh | 3 --- cmd/gore/main.go | 20 +++++++++++--------- enc/enc.go | 36 ++++++++++++++++++++++++++---------- 5 files changed, 41 insertions(+), 22 deletions(-) create mode 100755 build delete mode 100755 build.sh diff --git a/.gitignore b/.gitignore index f655bb0..6b1ca26 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /exe/ +/gore diff --git a/build b/build new file mode 100755 index 0000000..03da5e4 --- /dev/null +++ b/build @@ -0,0 +1,3 @@ +#!/bin/sh + +go build ./cmd/gore diff --git a/build.sh b/build.sh deleted file mode 100755 index 9fa60ed..0000000 --- a/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -go build -o ./exe/ ./cmd/gore diff --git a/cmd/gore/main.go b/cmd/gore/main.go index b219768..89cabf2 100644 --- a/cmd/gore/main.go +++ b/cmd/gore/main.go @@ -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:]) } - diff --git a/enc/enc.go b/enc/enc.go index ce8984d..fd654eb 100644 --- a/enc/enc.go +++ b/enc/enc.go @@ -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 } -