Skip to content

Commit

Permalink
improve flags implementation and usage text
Browse files Browse the repository at this point in the history
- tests
  • Loading branch information
simonleung8 committed Sep 2, 2015
1 parent a5e8bfe commit 93ce96b
Show file tree
Hide file tree
Showing 15 changed files with 1,012 additions and 39 deletions.
Binary file added cli-plugin-recorder
Binary file not shown.
7 changes: 4 additions & 3 deletions data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
)

//go:generate counterfeiter -o data_fakes/fake_data.go . CmdSetData
type CmdSetData interface {
GetCmdSet(string) []string
SaveCmdSet(string, []string)
Expand Down Expand Up @@ -97,12 +98,14 @@ func (c *cmdSetData) SaveCmdSet(cmdsetName string, cmdset []string) {
fp := getFilePath()
_, err := os.Stat(fp)
if err != nil && !os.IsExist(err) {
err = nil
f, err = os.Create(fp)
} else {
f, err = os.OpenFile(fp, os.O_RDWR|os.O_APPEND, 0660)
}

if err != nil {
quitWithError("Error writing to file: ", err)
quitWithError("Error opening file: ", err)
}
defer f.Close()

Expand All @@ -124,8 +127,6 @@ func (c *cmdSetData) ClearCmdSets() {
fmt.Println("Error removing file: ", err)
os.Exit(1)
}

fmt.Println("All record command sets has be removed")
}

func (c *cmdSetData) DeleteCmdSet(cmdsetName string) {
Expand Down
199 changes: 199 additions & 0 deletions data/data_fakes/fake_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// This file was generated by counterfeiter
package data_fakes

import (
"sync"

"github.com/simonleung8/cli-plugin-recorder/data"
)

type FakeCmdSetData struct {
GetCmdSetStub func(string) []string
getCmdSetMutex sync.RWMutex
getCmdSetArgsForCall []struct {
arg1 string
}
getCmdSetReturns struct {
result1 []string
}
SaveCmdSetStub func(string, []string)
saveCmdSetMutex sync.RWMutex
saveCmdSetArgsForCall []struct {
arg1 string
arg2 []string
}
DeleteCmdSetStub func(string)
deleteCmdSetMutex sync.RWMutex
deleteCmdSetArgsForCall []struct {
arg1 string
}
IsCmdExistStub func(t string) bool
isCmdExistMutex sync.RWMutex
isCmdExistArgsForCall []struct {
t string
}
isCmdExistReturns struct {
result1 bool
}
ListCmdSetNamesStub func() []string
listCmdSetNamesMutex sync.RWMutex
listCmdSetNamesArgsForCall []struct{}
listCmdSetNamesReturns struct {
result1 []string
}
ClearCmdSetsStub func()
clearCmdSetsMutex sync.RWMutex
clearCmdSetsArgsForCall []struct{}
}

func (fake *FakeCmdSetData) GetCmdSet(arg1 string) []string {
fake.getCmdSetMutex.Lock()
fake.getCmdSetArgsForCall = append(fake.getCmdSetArgsForCall, struct {
arg1 string
}{arg1})
fake.getCmdSetMutex.Unlock()
if fake.GetCmdSetStub != nil {
return fake.GetCmdSetStub(arg1)
} else {
return fake.getCmdSetReturns.result1
}
}

func (fake *FakeCmdSetData) GetCmdSetCallCount() int {
fake.getCmdSetMutex.RLock()
defer fake.getCmdSetMutex.RUnlock()
return len(fake.getCmdSetArgsForCall)
}

func (fake *FakeCmdSetData) GetCmdSetArgsForCall(i int) string {
fake.getCmdSetMutex.RLock()
defer fake.getCmdSetMutex.RUnlock()
return fake.getCmdSetArgsForCall[i].arg1
}

func (fake *FakeCmdSetData) GetCmdSetReturns(result1 []string) {
fake.GetCmdSetStub = nil
fake.getCmdSetReturns = struct {
result1 []string
}{result1}
}

func (fake *FakeCmdSetData) SaveCmdSet(arg1 string, arg2 []string) {
fake.saveCmdSetMutex.Lock()
fake.saveCmdSetArgsForCall = append(fake.saveCmdSetArgsForCall, struct {
arg1 string
arg2 []string
}{arg1, arg2})
fake.saveCmdSetMutex.Unlock()
if fake.SaveCmdSetStub != nil {
fake.SaveCmdSetStub(arg1, arg2)
}
}

func (fake *FakeCmdSetData) SaveCmdSetCallCount() int {
fake.saveCmdSetMutex.RLock()
defer fake.saveCmdSetMutex.RUnlock()
return len(fake.saveCmdSetArgsForCall)
}

func (fake *FakeCmdSetData) SaveCmdSetArgsForCall(i int) (string, []string) {
fake.saveCmdSetMutex.RLock()
defer fake.saveCmdSetMutex.RUnlock()
return fake.saveCmdSetArgsForCall[i].arg1, fake.saveCmdSetArgsForCall[i].arg2
}

func (fake *FakeCmdSetData) DeleteCmdSet(arg1 string) {
fake.deleteCmdSetMutex.Lock()
fake.deleteCmdSetArgsForCall = append(fake.deleteCmdSetArgsForCall, struct {
arg1 string
}{arg1})
fake.deleteCmdSetMutex.Unlock()
if fake.DeleteCmdSetStub != nil {
fake.DeleteCmdSetStub(arg1)
}
}

func (fake *FakeCmdSetData) DeleteCmdSetCallCount() int {
fake.deleteCmdSetMutex.RLock()
defer fake.deleteCmdSetMutex.RUnlock()
return len(fake.deleteCmdSetArgsForCall)
}

func (fake *FakeCmdSetData) DeleteCmdSetArgsForCall(i int) string {
fake.deleteCmdSetMutex.RLock()
defer fake.deleteCmdSetMutex.RUnlock()
return fake.deleteCmdSetArgsForCall[i].arg1
}

func (fake *FakeCmdSetData) IsCmdExist(t string) bool {
fake.isCmdExistMutex.Lock()
fake.isCmdExistArgsForCall = append(fake.isCmdExistArgsForCall, struct {
t string
}{t})
fake.isCmdExistMutex.Unlock()
if fake.IsCmdExistStub != nil {
return fake.IsCmdExistStub(t)
} else {
return fake.isCmdExistReturns.result1
}
}

func (fake *FakeCmdSetData) IsCmdExistCallCount() int {
fake.isCmdExistMutex.RLock()
defer fake.isCmdExistMutex.RUnlock()
return len(fake.isCmdExistArgsForCall)
}

func (fake *FakeCmdSetData) IsCmdExistArgsForCall(i int) string {
fake.isCmdExistMutex.RLock()
defer fake.isCmdExistMutex.RUnlock()
return fake.isCmdExistArgsForCall[i].t
}

func (fake *FakeCmdSetData) IsCmdExistReturns(result1 bool) {
fake.IsCmdExistStub = nil
fake.isCmdExistReturns = struct {
result1 bool
}{result1}
}

func (fake *FakeCmdSetData) ListCmdSetNames() []string {
fake.listCmdSetNamesMutex.Lock()
fake.listCmdSetNamesArgsForCall = append(fake.listCmdSetNamesArgsForCall, struct{}{})
fake.listCmdSetNamesMutex.Unlock()
if fake.ListCmdSetNamesStub != nil {
return fake.ListCmdSetNamesStub()
} else {
return fake.listCmdSetNamesReturns.result1
}
}

func (fake *FakeCmdSetData) ListCmdSetNamesCallCount() int {
fake.listCmdSetNamesMutex.RLock()
defer fake.listCmdSetNamesMutex.RUnlock()
return len(fake.listCmdSetNamesArgsForCall)
}

func (fake *FakeCmdSetData) ListCmdSetNamesReturns(result1 []string) {
fake.ListCmdSetNamesStub = nil
fake.listCmdSetNamesReturns = struct {
result1 []string
}{result1}
}

func (fake *FakeCmdSetData) ClearCmdSets() {
fake.clearCmdSetsMutex.Lock()
fake.clearCmdSetsArgsForCall = append(fake.clearCmdSetsArgsForCall, struct{}{})
fake.clearCmdSetsMutex.Unlock()
if fake.ClearCmdSetsStub != nil {
fake.ClearCmdSetsStub()
}
}

func (fake *FakeCmdSetData) ClearCmdSetsCallCount() int {
fake.clearCmdSetsMutex.RLock()
defer fake.clearCmdSetsMutex.RUnlock()
return len(fake.clearCmdSetsArgsForCall)
}

var _ data.CmdSetData = new(FakeCmdSetData)
13 changes: 13 additions & 0 deletions data/data_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package data_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestData(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Data Suite")
}
Loading

0 comments on commit 93ce96b

Please sign in to comment.