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

fix(enter): block --verbose for exec subcommand #394

Merged
merged 2 commits into from
Jun 30, 2024
Merged
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
16 changes: 15 additions & 1 deletion internals/cli/cmd_enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,28 @@ func init() {
type enterFlags int

const (
// If set, disable all logs unless --verbose is passed.
enterSilenceLogging enterFlags = 1 << iota
// If set, do not allow the usage of --verbose option with subcommand.
enterProhibitVerbose
// If set, do not run the pebble daemon.
enterNoServiceManager
// If set, keep the pebble daemon running, even after the subcommand
// execution has finished.
enterKeepServiceManager
// If set, default services (with startup: enabled) must be started before
// executing the subcommand.
enterRequireServiceAutostart
// If set, do not start the default services (with startup: enabled).
// Behaviour similar to "--hold".
enterProhibitServiceAutostart
)

func commandEnterFlags(commander flags.Commander) (enterFlags enterFlags, supported bool) {
supported = true
switch commander.(type) {
case *cmdExec:
enterFlags = enterSilenceLogging
enterFlags = enterSilenceLogging | enterProhibitVerbose
case *cmdHelp:
enterFlags = enterNoServiceManager
case *cmdLs, *cmdPlan, *cmdServices, *cmdVersion:
Expand Down Expand Up @@ -153,6 +163,10 @@ func (cmd *cmdEnter) Execute(args []string) error {
return fmt.Errorf("enter: cannot provide --run before %q subcommand", parser.Active.Name)
}

if enterFlags&enterProhibitVerbose != 0 && cmd.Verbose {
return fmt.Errorf("enter: cannot provide -v/--verbose before %q subcommand", parser.Active.Name)
}

if enterFlags&enterNoServiceManager != 0 {
if err := commander.Execute(extraArgs); err != nil {
cmd.parser.Command.Active = parser.Command.Active
Expand Down
10 changes: 10 additions & 0 deletions internals/cli/cmd_enter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ func (s *PebbleSuite) TestEnterServicesNoRun(c *C) {
c.Check(exitCode, Equals, 1)
}

func (s *PebbleSuite) TestEnterExecNoVerbose(c *C) {
restore := fakeArgs("pebble", "enter", "--verbose", "exec", "date")
defer restore()

exitCode := cli.PebbleMain()
c.Check(s.Stderr(), Equals, "error: enter: cannot provide -v/--verbose before \"exec\" subcommand\n")
c.Check(s.Stdout(), Equals, "")
c.Check(exitCode, Equals, 1)
}

func (s *PebbleSuite) TestEnterExecListDir(c *C) {
files := []string{"foo", "bar", "baz"}
for _, file := range files {
Expand Down
Loading