cmd

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "sosos",
	Short: "delay & notify tool",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		if versionFlag {
			fmt.Println("0.8.0")
			os.Exit(0)
		}

		config, err := etc.LoadConfigFromFile()
		if err != nil {
			fmt.Println(err)
		}

		var webhookUrl string
		if strings.Contains(argWebhook, "http") {
			webhookUrl = argWebhook
		} else {
			if webhook, ok := config.FindWebhook(argWebhook); ok {
				webhookUrl = webhook.Url
			} else {
				log.Fatal("There is no webhook called ", argWebhook, " in the config file")
			}
		}

		suspendMinutes := []int64{}
		for _, suspendMinuteStr := range strings.Split(viper.GetString("suspendMinutes"), ",") {
			suspendMinute, err := strconv.Atoi(suspendMinuteStr)
			if err != nil {
				errors.New("suspend-minutes: invalid argument")
			}
			suspendMinutes = append(suspendMinutes, int64(suspendMinute))
		}

		remindSeconds := []int64{}
		for _, remindSecondStr := range strings.Split(viper.GetString("remindSeconds"), ",") {
			remindSecond, err := strconv.Atoi(remindSecondStr)
			if err != nil {
				errors.New("remind-seconds: invalid argument")
			}
			remindSeconds = append(remindSeconds, int64(remindSecond))
		}

		scriptExtList := []string{}
		for _, scriptExt := range strings.Split(viper.GetString("scriptExt"), ",") {
			scriptExtList = append(scriptExtList, scriptExt)
		}

		executor := sosos.NewExecutor(args, &sosos.ExecutorOption{
			SleepSec:            sleepSec,
			Port:                port,
			WebhookUrl:          webhookUrl,
			InsecureFlag:        insecureFlag,
			NoResultFlag:        noResultFlag,
			NoCancelLinkFlag:    noCancelLinkFlag,
			NoScriptContentFlag: noScriptContentFlag,
			SuspendMinutes:      suspendMinutes,
			RemindSeconds:       remindSeconds,
			CustomMessage:       message,
			ScriptExtList:       scriptExtList,
		})
		if err := executor.Execute(); err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	},
	Args: MinimumNArgsWithoutVersionOption(1),
}

Functions

func Execute

func Execute()

func MinimumNArgsWithoutVersionOption

func MinimumNArgsWithoutVersionOption(n int) cobra.PositionalArgs

Types

This section is empty.

Jump to

Keyboard shortcuts

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