diff --git a/cmd/open.go b/cmd/open.go index 35dd7b8..ec95a5b 100644 --- a/cmd/open.go +++ b/cmd/open.go @@ -20,8 +20,8 @@ func init() { Short: "Open SFTP connections to Trellis servers", Args: cobra.RangeArgs(1, 2), PreRun: func(cmd *cobra.Command, args []string) { - ui := lib.NewUiFromCobraCommand(cmd) - opener.SetUi(ui) + io := lib.NewIoFromCobraCommand(cmd) + opener.SetIo(io) }, RunE: func(cmd *cobra.Command, args []string) error { maybeSite := "" diff --git a/cyberduck/opener.go b/cyberduck/opener.go index 55faf2a..e0f8848 100644 --- a/cyberduck/opener.go +++ b/cyberduck/opener.go @@ -54,24 +54,24 @@ const cyberduckBookmarkJ2 = ` ` type Opener struct { - ui *lib.Ui + io *lib.Io } func NewOpener() *Opener { return &Opener{ - ui: lib.NewUi(), + io: lib.NewIo(), } } -func (o *Opener) SetUi(ui *lib.Ui) { - o.ui = ui +func (o *Opener) SetIo(io *lib.Io) { + o.io = io } func (o *Opener) Open(path string, environment string, siteName string, isAdmin bool) error { playbook := lib.NewAdHocPlaybook(map[string]string{ "cyberduck_open.yml": strings.TrimSpace(cyberduckOpenYml) + "\n", "cyberduck_bookmark.j2": strings.TrimSpace(cyberduckBookmarkJ2) + "\n", - }, path, o.ui) + }, path, o.io) playbookArgs := []string{ "-e", "dest=" + fmt.Sprintf("%s/cyberduck-%d.duck", path, time.Now().UnixNano()), diff --git a/lib/ad_hoc_playbook.go b/lib/ad_hoc_playbook.go index 35cd53a..392529f 100644 --- a/lib/ad_hoc_playbook.go +++ b/lib/ad_hoc_playbook.go @@ -9,14 +9,14 @@ import ( type AdHocPlaybook struct { files map[string]string root string - ui *Ui + io *Io } -func NewAdHocPlaybook(files map[string]string, root string, ui *Ui) *AdHocPlaybook { +func NewAdHocPlaybook(files map[string]string, root string, io *Io) *AdHocPlaybook { return &AdHocPlaybook{ files: files, root: root, - ui: ui, + io: io, } } @@ -31,7 +31,7 @@ func (p *AdHocPlaybook) Run(name string, args []string) (err error) { return err } - playbook := NewPlaybook(p.root, p.ui) + playbook := NewPlaybook(p.root, p.io) return playbook.Run(name, args) } diff --git a/lib/ui.go b/lib/io.go similarity index 63% rename from lib/ui.go rename to lib/io.go index 8ea503c..f7551af 100644 --- a/lib/ui.go +++ b/lib/io.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" ) -type Ui struct { +type Io struct { // inReader is a reader defined by the user that replaces stdin inReader io.Reader // outWriter is a writer defined by the user that replaces stdout @@ -16,16 +16,16 @@ type Ui struct { errWriter io.Writer } -func NewUi() *Ui { - return &Ui{ +func NewIo() *Io { + return &Io{ inReader: os.Stdin, outWriter: os.Stdout, errWriter: os.Stderr, } } -func NewUiFromCobraCommand(cmd *cobra.Command) *Ui { - return &Ui{ +func NewIoFromCobraCommand(cmd *cobra.Command) *Io { + return &Io{ inReader: cmd.InOrStdin(), outWriter: cmd.OutOrStdout(), errWriter: cmd.ErrOrStderr(), @@ -34,42 +34,42 @@ func NewUiFromCobraCommand(cmd *cobra.Command) *Ui { // SetOut sets the destination for usage messages. // If newOut is nil, os.Stdout is used. -func (u *Ui) SetOut(newOut io.Writer) { - u.outWriter = newOut +func (i *Io) SetOut(newOut io.Writer) { + i.outWriter = newOut } // SetErr sets the destination for error messages. // If newErr is nil, os.Stderr is used. -func (u *Ui) SetErr(newErr io.Writer) { - u.errWriter = newErr +func (i *Io) SetErr(newErr io.Writer) { + i.errWriter = newErr } // SetIn sets the source for input data // If newIn is nil, os.Stdin is used. -func (u *Ui) SetIn(newIn io.Reader) { - u.inReader = newIn +func (i *Io) SetIn(newIn io.Reader) { + i.inReader = newIn } // OutOrStdout returns output to stdout. -func (u *Ui) OutOrStdout() io.Writer { - if u.outWriter != nil { - return u.outWriter +func (i *Io) OutOrStdout() io.Writer { + if i.outWriter != nil { + return i.outWriter } return os.Stdout } // ErrOrStderr returns output to stderr -func (u *Ui) ErrOrStderr() io.Writer { - if u.errWriter != nil { - return u.errWriter +func (i *Io) ErrOrStderr() io.Writer { + if i.errWriter != nil { + return i.errWriter } return os.Stderr } // InOrStdin returns input to stdin -func (u *Ui) InOrStdin() io.Reader { - if u.inReader != nil { - return u.inReader +func (i *Io) InOrStdin() io.Reader { + if i.inReader != nil { + return i.inReader } return os.Stdin } diff --git a/lib/playbook.go b/lib/playbook.go index 99c4ba4..b2b61d3 100644 --- a/lib/playbook.go +++ b/lib/playbook.go @@ -9,13 +9,13 @@ import ( type Playbook struct { root string - ui *Ui + io *Io } -func NewPlaybook(root string, ui *Ui) *Playbook { +func NewPlaybook(root string, io *Io) *Playbook { return &Playbook{ root: root, - ui: ui, + io: io, } } @@ -26,13 +26,13 @@ func (p *Playbook) Run(name string, args []string) error { command.Dir = p.root - command.Stdin = p.ui.InOrStdin() - command.Stdout = p.ui.OutOrStdout() - command.Stderr = p.ui.ErrOrStderr() + command.Stdin = p.io.InOrStdin() + command.Stdout = p.io.OutOrStdout() + command.Stderr = p.io.ErrOrStderr() command.Env = append(os.Environ(), "ANSIBLE_RETRY_FILES_ENABLED=false") - if _, err := fmt.Fprintf(p.ui.OutOrStdout(), "Running command => ansible-playbook %s\n\n", strings.Join(commandArgs, " ")); err != nil { + if _, err := fmt.Fprintf(p.io.OutOrStdout(), "Running command => ansible-playbook %s\n\n", strings.Join(commandArgs, " ")); err != nil { return err }