Skip to content

Commit

Permalink
Merge branch 'cmdOutputCapture'
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Leung committed Jun 1, 2015
2 parents 4a108fd + 8dc345b commit 203c213
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 116 deletions.
46 changes: 23 additions & 23 deletions cf/terminal/fakes/fake_output_capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@
package fakes

import (
. "github.com/cloudfoundry/cli/cf/terminal"
"sync"

"github.com/cloudfoundry/cli/cf/terminal"
)

type FakeOutputCapture struct {
GetOutputAndResetStub func() []string
getOutputAndResetMutex sync.RWMutex
getOutputAndResetArgsForCall []struct{}
getOutputAndResetReturns struct {
result1 []string
SetOutputBucketStub func(*[]string)
setOutputBucketMutex sync.RWMutex
setOutputBucketArgsForCall []struct {
arg1 *[]string
}
}

func (fake *FakeOutputCapture) GetOutputAndReset() []string {
fake.getOutputAndResetMutex.Lock()
defer fake.getOutputAndResetMutex.Unlock()
fake.getOutputAndResetArgsForCall = append(fake.getOutputAndResetArgsForCall, struct{}{})
if fake.GetOutputAndResetStub != nil {
return fake.GetOutputAndResetStub()
} else {
return fake.getOutputAndResetReturns.result1
func (fake *FakeOutputCapture) SetOutputBucket(arg1 *[]string) {
fake.setOutputBucketMutex.Lock()
fake.setOutputBucketArgsForCall = append(fake.setOutputBucketArgsForCall, struct {
arg1 *[]string
}{arg1})
fake.setOutputBucketMutex.Unlock()
if fake.SetOutputBucketStub != nil {
fake.SetOutputBucketStub(arg1)
}
}

func (fake *FakeOutputCapture) GetOutputAndResetCallCount() int {
fake.getOutputAndResetMutex.RLock()
defer fake.getOutputAndResetMutex.RUnlock()
return len(fake.getOutputAndResetArgsForCall)
func (fake *FakeOutputCapture) SetOutputBucketCallCount() int {
fake.setOutputBucketMutex.RLock()
defer fake.setOutputBucketMutex.RUnlock()
return len(fake.setOutputBucketArgsForCall)
}

func (fake *FakeOutputCapture) GetOutputAndResetReturns(result1 []string) {
fake.getOutputAndResetReturns = struct {
result1 []string
}{result1}
func (fake *FakeOutputCapture) SetOutputBucketArgsForCall(i int) *[]string {
fake.setOutputBucketMutex.RLock()
defer fake.setOutputBucketMutex.RUnlock()
return fake.setOutputBucketArgsForCall[i].arg1
}

var _ OutputCapture = new(FakeOutputCapture)
var _ terminal.OutputCapture = new(FakeOutputCapture)
3 changes: 0 additions & 3 deletions cf/terminal/fakes/fake_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ type FakePrinter struct {
}
}

func (fake *FakePrinter) DisableTerminalOutput(bool) {
}

func (fake *FakePrinter) Print(a ...interface{}) (n int, err error) {
fake.printMutex.Lock()
defer fake.printMutex.Unlock()
Expand Down
35 changes: 19 additions & 16 deletions cf/terminal/tee_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ type Printer interface {
ForcePrint(a ...interface{}) (n int, err error)
ForcePrintf(format string, a ...interface{}) (n int, err error)
ForcePrintln(a ...interface{}) (n int, err error)
DisableTerminalOutput(bool)
}

type OutputCapture interface {
GetOutputAndReset() []string
SetOutputBucket(*[]string)
}

type TerminalOutputSwitch interface {
Expand All @@ -24,24 +23,20 @@ type TerminalOutputSwitch interface {

type TeePrinter struct {
disableTerminalOutput bool
output []string
outputBucket *[]string
}

func NewTeePrinter() *TeePrinter {
return &TeePrinter{
output: []string{},
}
return &TeePrinter{}
}

func (t *TeePrinter) GetOutputAndReset() []string {
currentOutput := t.output
t.output = []string{}
return currentOutput
func (t *TeePrinter) SetOutputBucket(bucket *[]string) {
t.outputBucket = bucket
}

func (t *TeePrinter) Print(values ...interface{}) (n int, err error) {
str := fmt.Sprint(values...)
t.output = append(t.output, Decolorize(str))
t.saveOutputToBucket(str)
if !t.disableTerminalOutput {
return fmt.Print(str)
}
Expand All @@ -50,7 +45,7 @@ func (t *TeePrinter) Print(values ...interface{}) (n int, err error) {

func (t *TeePrinter) Printf(format string, a ...interface{}) (n int, err error) {
str := fmt.Sprintf(format, a...)
t.output = append(t.output, Decolorize(str))
t.saveOutputToBucket(str)
if !t.disableTerminalOutput {
return fmt.Print(str)
}
Expand All @@ -59,7 +54,7 @@ func (t *TeePrinter) Printf(format string, a ...interface{}) (n int, err error)

func (t *TeePrinter) Println(values ...interface{}) (n int, err error) {
str := fmt.Sprint(values...)
t.output = append(t.output, Decolorize(str))
t.saveOutputToBucket(str)
if !t.disableTerminalOutput {
return fmt.Println(str)
}
Expand All @@ -68,22 +63,30 @@ func (t *TeePrinter) Println(values ...interface{}) (n int, err error) {

func (t *TeePrinter) ForcePrint(values ...interface{}) (n int, err error) {
str := fmt.Sprint(values...)
t.output = append(t.output, Decolorize(str))
t.saveOutputToBucket(str)
return fmt.Print(str)
}

func (t *TeePrinter) ForcePrintf(format string, a ...interface{}) (n int, err error) {
str := fmt.Sprintf(format, a...)
t.output = append(t.output, Decolorize(str))
t.saveOutputToBucket(str)
return fmt.Print(str)
}

func (t *TeePrinter) ForcePrintln(values ...interface{}) (n int, err error) {
str := fmt.Sprint(values...)
t.output = append(t.output, Decolorize(str))
t.saveOutputToBucket(str)
return fmt.Println(str)
}

func (t *TeePrinter) DisableTerminalOutput(disable bool) {
t.disableTerminalOutput = disable
}

func (t *TeePrinter) saveOutputToBucket(output string) {
if t.outputBucket == nil {
return
}

*t.outputBucket = append(*t.outputBucket, Decolorize(output))
}
Loading

0 comments on commit 203c213

Please sign in to comment.