Skip to content

Commit

Permalink
Show help for "local execute" (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-hu authored and Zachary Scott committed Oct 30, 2018
1 parent 3f6c506 commit 6437fd1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type buildOptions struct {
cl *client.Client
log *logger.Logger
args []string
help func() error
}

// These options are purely here to retain a mock of the structure of the flags used by `build`.
Expand Down Expand Up @@ -60,6 +61,7 @@ func newLocalExecuteCommand(config *settings.Config) *cobra.Command {
opts.args = args
opts.log = logger.NewLogger(config.Debug)
opts.cl = client.NewClient(config.Host, config.Endpoint, config.Token)
opts.help = cmd.Help
},
RunE: func(_ *cobra.Command, _ []string) error {
return runExecute(opts)
Expand Down Expand Up @@ -246,6 +248,12 @@ func ensureDockerIsAvailable() error {
}

func runExecute(opts buildOptions) error {
for _, f := range opts.args {
if f == "--help" || f == "-h" {
return opts.help()
}
}

if err := validateConfigVersion(opts.args); err != nil {
return err
}
Expand Down
58 changes: 58 additions & 0 deletions cmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,62 @@ var _ = Describe("build", func() {
Expect(err).To(HaveOccurred())
})
})

Describe("local execute", func() {
It("provides a help documentation when provided with a --help flag", func() {
called := false
mockHelp := func() error {
called = true
return nil
}
mockOptions := buildOptions{
args: []string{"--help"},
help: mockHelp,
}
runExecute(mockOptions)
Expect(called).To(BeTrue())
})

It("provides a help documentation when provided with a --help flag mixed with other flags", func() {
called := false
mockHelp := func() error {
called = true
return nil
}
mockOptions := buildOptions{
args: []string{"--skip-checkout", "--help"},
help: mockHelp,
}
runExecute(mockOptions)
Expect(called).To(BeTrue())
})

It("provides a help documentation when provided with a -h flag", func() {
called := false
mockHelp := func() error {
called = true
return nil
}
mockOptions := buildOptions{
args: []string{"-h"},
help: mockHelp,
}
runExecute(mockOptions)
Expect(called).To(BeTrue())
})

It("provides a help documentation when provided with a -h flag mixed with other flags", func() {
called := false
mockHelp := func() error {
called = true
return nil
}
mockOptions := buildOptions{
args: []string{"--skip-checkout", "-h"},
help: mockHelp,
}
runExecute(mockOptions)
Expect(called).To(BeTrue())
})
})
})

0 comments on commit 6437fd1

Please sign in to comment.