2024-07-09 14:13:20 +03:00
|
|
|
package enc
|
|
|
|
|
2024-10-03 15:14:39 +03:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"surdeus.su/core/cli/mtool"
|
|
|
|
)
|
2024-07-09 14:13:20 +03:00
|
|
|
|
|
|
|
type EncodeOptions struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewEncodeTool(
|
|
|
|
name string,
|
2024-10-03 15:14:39 +03:00
|
|
|
encFn func(io.Writer) io.Writer,
|
2024-07-09 14:13:20 +03:00
|
|
|
) *mtool.Tool {
|
2024-10-03 15:14:39 +03:00
|
|
|
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
|
2024-07-09 14:13:20 +03:00
|
|
|
|
2024-10-03 15:14:39 +03:00
|
|
|
if len(args) > 0 {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
input = &buf
|
|
|
|
for _, arg := range args {
|
|
|
|
buf.Write([]byte(arg))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
input = os.Stdin
|
|
|
|
}
|
2024-07-09 14:13:20 +03:00
|
|
|
|
|
|
|
encOutput := encFn(output)
|
|
|
|
io.Copy(encOutput, input)
|
|
|
|
})
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|