Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisableExec flag #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions bubbler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ type BubbleType int

type Bubbler struct {
Translator
data []string
data []string
DisableExec bool
}

func NewBubbler(t Translator) *Bubbler {
return &Bubbler{
Translator: t,
data: []string{},
Translator: t,
data: []string{},
DisableExec: false,
}
}

func NewBubblerWithDisabledExec(t Translator) *Bubbler {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported identifier "NewBubblerWithDisabledExec" should have comment

Suggested change
func NewBubblerWithDisabledExec(t Translator) *Bubbler {
// NewBubblerWithDisabledExec ...
func NewBubblerWithDisabledExec(t Translator) *Bubbler {

return &Bubbler{
Translator: t,
data: []string{},
DisableExec: true,
}
}

Expand All @@ -26,7 +36,10 @@ func (b *Bubbler) String() string {
}

func (b *Bubbler) Bubble(s string) (string, error) {
f := fizzer{b}
f := fizzer{
Bubbler: b,
DisableExec: b.DisableExec,
}
ctx := plush.NewContextWith(map[string]interface{}{
"exec": f.Exec(os.Stdout),
"create_table": f.CreateTable,
Expand Down
4 changes: 2 additions & 2 deletions bubbler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Test_Exec(t *testing.T) {
r := require.New(t)

b := NewBubbler(nil)
f := fizzer{b}
f := fizzer{Bubbler: b, DisableExec: false}
bb := &bytes.Buffer{}
c := f.Exec(bb)
c("echo hello")
Expand All @@ -23,7 +23,7 @@ func Test_ExecQuoted(t *testing.T) {
r := require.New(t)

b := NewBubbler(nil)
f := fizzer{b}
f := fizzer{Bubbler: b, DisableExec: false}
bb := &bytes.Buffer{}
c := f.Exec(bb)
// without proper splitting we would get "'a b c'"
Expand Down
8 changes: 7 additions & 1 deletion fizz.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
type Options map[string]interface{}

type fizzer struct {
Bubbler *Bubbler
Bubbler *Bubbler
DisableExec bool
}

func (f fizzer) add(s string, err error) error {
Expand All @@ -29,6 +30,11 @@ func (f fizzer) add(s string, err error) error {
}

func (f fizzer) Exec(out io.Writer) func(string) error {
if f.DisableExec {
return func(s string) error {
return nil
}
}
return func(s string) error {
args, err := shellquote.Split(s)
if err != nil {
Expand Down