cmd

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:     "will-it-blend",
	Version: "0.3.2",
	Short:   "will-it-blend is a tool for automating the creation of CLI command based Twitch.tv predictions",
	Long: `will-it-blend is a tool for automating the creation of CLI command based Twitch.tv predictions.

It will resolve the prediction based on the return code of the specified command.`,
	Example: "will-it-blend \"ls -a\"",
	Args:    cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		command := args[0]

		if token == "" {
			token = pkg.StartServer(port)
		}

		userId := pkg.GetUserId(token)

		prediction := pkg.CreatePrediction(token, title, userId, successMessage, failureMessage, duration)

		fmt.Printf("Prediction running. Command will run after %d seconds \n", duration)

		time.Sleep(time.Duration(duration) * time.Second)

		loopCount := 0
		loopSleep := 5
		loopMax := 90 / loopSleep
		finished := false

		for loopCount < loopMax {
			time.Sleep(time.Duration(loopSleep) * time.Second)
			finished = pkg.IsPredictionFinished(token, userId, prediction.PredictionId)
			loopCount = loopCount + 1
			if finished {
				loopCount = math.MaxInt
			}
		}

		if !finished {
			fmt.Println("Prediction did not lock as expected")
			os.Exit(1)
		}

		commandSuccess := runCommand(command)

		winningOutcomeId := prediction.SuccessOutcomeId
		if !commandSuccess {
			winningOutcomeId = prediction.FailureOutcomeId
		}

		pkg.ResolvePrediction(token, userId, prediction.PredictionId, winningOutcomeId)

		fmt.Println("Prediction Resolved")

	},
}

Functions

func Init

func Init()

Types

This section is empty.

Jump to

Keyboard shortcuts

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