X Tutup
Skip to content

Commit a9ab2a9

Browse files
author
vilmibm
committed
move Edit to opts for testing
1 parent 62f54f0 commit a9ab2a9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/cmd/gist/edit/edit.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"net/http"
99
"net/url"
10-
"os"
1110
"sort"
1211
"strings"
1312

@@ -28,6 +27,8 @@ type EditOptions struct {
2827
HttpClient func() (*http.Client, error)
2928
Config func() (config.Config, error)
3029

30+
Edit func(string, string, string, *iostreams.IOStreams) (string, error)
31+
3132
Selector string
3233
Filename string
3334
}
@@ -37,6 +38,13 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
3738
IO: f.IOStreams,
3839
HttpClient: f.HttpClient,
3940
Config: f.Config,
41+
Edit: func(editorCmd, filename, defaultContent string, io *iostreams.IOStreams) (string, error) {
42+
return surveyext.Edit(
43+
editorCmd,
44+
"*."+filename,
45+
defaultContent,
46+
io.In, io.Out, io.ErrOut, nil)
47+
},
4048
}
4149

4250
cmd := &cobra.Command{
@@ -115,12 +123,7 @@ func editRun(opts *EditOptions) error {
115123
if err != nil {
116124
return err
117125
}
118-
text, err := surveyext.Edit(
119-
editorCommand,
120-
"*."+filename,
121-
gist.Files[filename].Content,
122-
// TODO: consider using iostreams here
123-
os.Stdin, os.Stdout, os.Stderr, nil)
126+
text, err := opts.Edit(editorCommand, filename, gist.Files[filename].Content, opts.IO)
124127

125128
if err != nil {
126129
return err

0 commit comments

Comments
 (0)
X Tutup