mirror of
https://github.com/restic/restic.git
synced 2026-05-24 19:15:30 +00:00
reduce usages of globalOptions variable
This commit is contained in:
@@ -28,7 +28,7 @@ type CommandReader struct {
|
||||
alreadyClosedReadErr error
|
||||
}
|
||||
|
||||
func NewCommandReader(ctx context.Context, args []string, logOutput io.Writer) (*CommandReader, error) {
|
||||
func NewCommandReader(ctx context.Context, args []string, errorOutput func(msg string, args ...interface{})) (*CommandReader, error) {
|
||||
if len(args) == 0 {
|
||||
return nil, fmt.Errorf("no command was specified as argument")
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func NewCommandReader(ctx context.Context, args []string, logOutput io.Writer) (
|
||||
go func() {
|
||||
sc := bufio.NewScanner(stderr)
|
||||
for sc.Scan() {
|
||||
_, _ = fmt.Fprintf(logOutput, "subprocess %v: %v\n", command.Args[0], sc.Text())
|
||||
errorOutput("subprocess %v: %v", command.Args[0], sc.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCommandReaderSuccess(t *testing.T) {
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"true"}, io.Discard)
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"true"}, func(msg string, args ...interface{}) {})
|
||||
test.OK(t, err)
|
||||
|
||||
_, err = io.Copy(io.Discard, reader)
|
||||
@@ -22,7 +22,7 @@ func TestCommandReaderSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCommandReaderFail(t *testing.T) {
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"false"}, io.Discard)
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"false"}, func(msg string, args ...interface{}) {})
|
||||
test.OK(t, err)
|
||||
|
||||
_, err = io.Copy(io.Discard, reader)
|
||||
@@ -30,17 +30,17 @@ func TestCommandReaderFail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCommandReaderInvalid(t *testing.T) {
|
||||
_, err := fs.NewCommandReader(context.TODO(), []string{"w54fy098hj7fy5twijouytfrj098y645wr"}, io.Discard)
|
||||
_, err := fs.NewCommandReader(context.TODO(), []string{"w54fy098hj7fy5twijouytfrj098y645wr"}, func(msg string, args ...interface{}) {})
|
||||
test.Assert(t, err != nil, "missing error")
|
||||
}
|
||||
|
||||
func TestCommandReaderEmptyArgs(t *testing.T) {
|
||||
_, err := fs.NewCommandReader(context.TODO(), []string{}, io.Discard)
|
||||
_, err := fs.NewCommandReader(context.TODO(), []string{}, func(msg string, args ...interface{}) {})
|
||||
test.Assert(t, err != nil, "missing error")
|
||||
}
|
||||
|
||||
func TestCommandReaderOutput(t *testing.T) {
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"echo", "hello world"}, io.Discard)
|
||||
reader, err := fs.NewCommandReader(context.TODO(), []string{"echo", "hello world"}, func(msg string, args ...interface{}) {})
|
||||
test.OK(t, err)
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
Reference in New Issue
Block a user