gore/enc/enc.go
2024-10-03 17:14:39 +05:00

43 lines
598 B
Go

package enc
import (
"bytes"
"io"
"os"
"surdeus.su/core/cli/mtool"
)
type EncodeOptions struct {
}
func NewEncodeTool(
name string,
encFn func(io.Writer) io.Writer,
) *mtool.Tool {
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
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)
})
return ret
}