cmd

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2020 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "slackstatus \"your message here\"",
	Short: "Post a formatted status message to Slack",
	Long: `Post a formatted status message to a Slack channel with a given
username. An optional footer info can be provided.
You can set one of the predifined colors DANGER, WARNING or GOOD or use any hex color value.

You need to set up an incoming webhook for your Slack at https://my.slack.com/services/new/incoming-webhook/ first.
	`,
	Run: func(cmd *cobra.Command, args []string) {

		message := getPipedInput()
		if len(args) > 0 {
			message = args[0]
		}

		if len(message) == 0 {
			cmd.Help()
			log.Fatal("You need to provide a message as argument or pipe a message")
		}

		var slackmsg = slackstatus.Message{
			WebhookURL:       viper.GetString("webhook"),
			Username:         viper.GetString("user"),
			Channel:          viper.GetString("channel"),
			IconEmoji:        viper.GetString("iconemoji"),
			Footer:           viper.GetString("footer"),
			RetryRatelimited: viper.GetBool("retry"),
			RetryBackground:  false,
		}

		if err := slackmsg.Send(message, viper.GetString("color")); err != nil {
			log.Fatal(err)
		}

	},
}

Functions

func Execute

func Execute()

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL