diff --git a/Gopkg.lock b/Gopkg.lock index 6dda64e..372748e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -7,6 +7,12 @@ revision = "aabad6e819789e569bd6aabf444c935aa9ba1e44" version = "v0.5.0" +[[projects]] + branch = "master" + name = "github.com/deckarep/gosx-notifier" + packages = ["."] + revision = "61a88900fb062ed8c63828adf4d7b58463b61f78" + [[projects]] name = "github.com/fatih/color" packages = ["."] @@ -25,6 +31,12 @@ packages = ["."] revision = "ae77be60afb1dcacde03767a8c37337fad28ac14" +[[projects]] + branch = "master" + name = "github.com/martinlindhe/notify" + packages = ["."] + revision = "369b9400397a805575ad39e97cc4e7d493ea4335" + [[projects]] name = "github.com/mattn/go-colorable" packages = ["."] @@ -37,6 +49,12 @@ revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" version = "v0.0.3" +[[projects]] + branch = "master" + name = "github.com/nu7hatch/gouuid" + packages = ["."] + revision = "179d4d0c4d8d407a32af483c2354df1d2c91e6c3" + [[projects]] name = "github.com/urfave/cli" packages = ["."] @@ -49,6 +67,12 @@ packages = ["unix"] revision = "92ac112afc6efd90284acda2b046fc0e351228f6" +[[projects]] + branch = "v1" + name = "gopkg.in/toast.v1" + packages = ["."] + revision = "b700e246b8b6d3e13554091e540e1019e26389f1" + [[projects]] branch = "v2" name = "gopkg.in/yaml.v2" @@ -58,6 +82,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "9866632c6655f2b13c5a6567e87d824685c882e40fc4a1a7513bdf9d4710045a" + inputs-digest = "86055c933d04a9f46045c437c0e163af6622e85cf0ea6625c54c4222b52e62ab" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 58d6728..28e3f4d 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -48,3 +48,8 @@ [[constraint]] name = "gopkg.in/yaml.v2" branch = "v2" + +[[constraint]] + name = "github.com/martinlindhe/notify" + branch = "master" + diff --git a/cmd/main.go b/cmd/main.go index 71bb08a..cd61de4 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -8,6 +8,7 @@ import ( "github.com/urfave/cli" ) +// GoReleaser will override with the latest tag on build var version = "master" // It all starts here @@ -30,6 +31,11 @@ func main() { Usage: "Show verbose output. Learning Mode!", EnvVar: "RIG_VERBOSE", }, + cli.BoolFlag{ + Name: "quiet", + Usage: "Disable all desktop notifications", + EnvVar: "RIG_NOTIFY_QUIET", + }, } app.Before = func(c *cli.Context) error { diff --git a/commands/command.go b/commands/command.go index 21cc4fc..96c2b3f 100644 --- a/commands/command.go +++ b/commands/command.go @@ -18,6 +18,7 @@ type BaseCommand struct { RigCommand out *util.RigLogger machine Machine + context *cli.Context } // Before configure the function to run before all commands to setup core services. @@ -27,6 +28,12 @@ func (cmd *BaseCommand) Before(c *cli.Context) error { util.LoggerInit(c.GlobalBool("verbose")) cmd.out = util.Logger() cmd.machine = Machine{Name: c.GlobalString("name"), out: util.Logger()} + + util.NotifyInit(fmt.Sprintf("Outrigger (rig) %s", c.App.Version)) + + // Hold onto Context so that we can use it later without having to pass it around everywhere + cmd.context = c + return nil } @@ -34,12 +41,14 @@ func (cmd *BaseCommand) Before(c *cli.Context) error { func (cmd *BaseCommand) Success(message string) error { if message != "" { cmd.out.Info.Println(message) + util.NotifySuccess(cmd.context, message) } return nil } // Error encapsulates the functionality for reporting command failure func (cmd *BaseCommand) Error(message string, errorName string, exitCode int) error { + util.NotifyError(cmd.context, message) return cli.NewExitError(fmt.Sprintf("ERROR: %s [%s] (%d)", message, errorName, exitCode), exitCode) } diff --git a/docker-compose.yml b/docker-compose.yml index 6219014..6f93656 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '2.1' services: - # Install project dependencies. + # Run the release process. goreleaser: extends: base environment: @@ -27,7 +27,8 @@ services: # Install project dependencies. install: extends: base - command: dep ensure + entrypoint: [ "dep", "ensure" ] + command: "" # Update project dependencies. # Will update all if no arguments are provided. To update a particular package use: diff --git a/util/logo.png b/util/logo.png new file mode 100644 index 0000000..03fa237 Binary files /dev/null and b/util/logo.png differ diff --git a/util/notify.go b/util/notify.go new file mode 100644 index 0000000..fbc2af2 --- /dev/null +++ b/util/notify.go @@ -0,0 +1,57 @@ +package util + +/** + * urfave/cli Notify "Extension" + * + * This sub-package of rig is intended for potential separation into a + * standalone package or PR to the main framework. As such, it should not have + * any built-in assumptions or identifiers about Rig, nor depend on anything in + * the rig codebase. + */ + +import ( + "fmt" + + "github.com/martinlindhe/notify" + "github.com/urfave/cli" +) + +var config *NotifyConfig + +// NotifyConfig holds configuration for notification support +type NotifyConfig struct { + // The label for the app to be displayed in notifications. + Label string + + // Relative path to notification logo. + Icon string +} + +// NotifyInit initializes notification config +func NotifyInit(label string) error { + config = &NotifyConfig{ + Icon: "util/logo.png", + Label: label, + } + return nil +} + +// NotifySuccess send a notification for a successful command run +func NotifySuccess(ctx *cli.Context, message string) { + if shouldNotify(ctx) { + notify.Notify(config.Label, fmt.Sprintf("Success: %s", ctx.Command.Name), message, config.Icon) + } +} + +// NotifyError send a notification for a failed command run +func NotifyError(ctx *cli.Context, message string) error { + if shouldNotify(ctx) { + notify.Notify(config.Label, fmt.Sprintf("Error: %s", ctx.Command.Name), message, config.Icon) + } + return nil +} + +// shouldNotify returns a boolean if notifications are enabled +func shouldNotify(ctx *cli.Context) bool { + return !ctx.GlobalBool("quiet") +}