Skip to content

Commit

Permalink
Developer Testing Commands (#150)
Browse files Browse the repository at this point in the history
* Clean up spinner finalization.

* Add dev:win and dev:fail commands
  • Loading branch information
grayside authored and febbraro committed Mar 2, 2018
1 parent b8f97f8 commit 572c415
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Here are a few conventions:
return cmd.Failure(message)
```

## Developer Testing Commands

You can use `rig dev:win` or `rig dev:fail` as no-op commands to observe the
effects of a success or failure without external dependencies on the local
environment or side effects from "real" commands doing their job.

## Development Environment Setup

### Developing with Docker
Expand Down
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func main() {
app.Commands = append(app.Commands, (&commands.Remove{}).Commands()...)
app.Commands = append(app.Commands, (&commands.Project{}).Commands()...)
app.Commands = append(app.Commands, (&commands.Doctor{}).Commands()...)
app.Commands = append(app.Commands, (&commands.Dev{}).Commands()...)

app.Run(os.Args)
}
6 changes: 5 additions & 1 deletion commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func (cmd *BaseCommand) Success(message string) error {
if message != "" {
cmd.out.Info(message)
util.NotifySuccess(cmd.context, message)
} else {
// If there is an active spinner wrap it up. This is not placed before the
// logging above so commands can rely on cmd.Success to set the last spinner
// status in lieu of an extraneous log entry.
cmd.out.NoSpin()
}

return nil
Expand All @@ -54,7 +59,6 @@ func (cmd *BaseCommand) Failure(message string, errorName string, exitCode int)
// If the spinner is running, output something to get closure and shut it down.
if cmd.out.Spinning {
cmd.out.Error(message)
fmt.Println()
}

// Handle error messaging.
Expand Down
50 changes: 50 additions & 0 deletions commands/dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package commands

import (
"time"

"github.com/urfave/cli"
)

// Dev is the command for setting docker config to talk to a Docker Machine
type Dev struct {
BaseCommand
}

// Commands returns the operations supported by this command
func (cmd *Dev) Commands() []cli.Command {
return []cli.Command{
{
Name: "dev:win",
Usage: "A no-op command that will always succeed.",
Before: cmd.Before,
Action: cmd.RunSucceed,
Hidden: true,
},
{
Name: "dev:fail",
Usage: "A no-op command that will always fail.",
Before: cmd.Before,
Action: cmd.RunFail,
Hidden: true,
},
}
}

// RunSucceed executes the `rig dev:succeed` command
func (cmd *Dev) RunSucceed(c *cli.Context) error {
cmd.out.Spin("Think positive...")
time.Sleep(3 * time.Second)
cmd.out.Info("We've got it.")
return cmd.Success("Positively successful!")
}

// RunFail executes the `rig dev:fail` command
func (cmd *Dev) RunFail(c *cli.Context) error {
cmd.out.Spin("Abandon all hope...")
time.Sleep(3 * time.Second)
cmd.out.Warning("Hope slipping...")
cmd.out.Spin("Is the sky painted black?")
time.Sleep(3 * time.Second)
return cmd.Failure("Hope abandoned :(", "ABANDON-HOPE", 418)
}
2 changes: 2 additions & 0 deletions util/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func PrintDebugHelp(message, errorName string, exitCode int) {
codeMessage = "environmental"
case 13:
codeMessage = "external/upstream command"
case 418:
codeMessage = "rig developer test command"
default:
codeMessage = "general"
}
Expand Down

0 comments on commit 572c415

Please sign in to comment.