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 }