Skip to content

Commit

Permalink
feat(cmd/sleep/random_verbose): Add slu sleep random-verbose mainly…
Browse files Browse the repository at this point in the history
… for my Kubernetes training
  • Loading branch information
ondrejsika committed Jun 28, 2023
1 parent 05c3394 commit 5e3e809
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ import (
_ "github.com/sikalabs/slu/cmd/sleep"
_ "github.com/sikalabs/slu/cmd/sleep/forever"
_ "github.com/sikalabs/slu/cmd/sleep/random"
_ "github.com/sikalabs/slu/cmd/sleep/random_verbose"
_ "github.com/sikalabs/slu/cmd/sqlite"
_ "github.com/sikalabs/slu/cmd/sqlite/read"
_ "github.com/sikalabs/slu/cmd/ssh"
Expand Down
6 changes: 6 additions & 0 deletions cmd/install_bin/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ var Tools = []Tool{
UrlTemplate: "https://github.com/hadolint/hadolint/releases/download/{{.Version}}/hadolint-{{.Os|capitalize}}-{{.Arch}}",
GetArchFunc: hadolintGetArchFunc,
},
{
Name: "kubelogin",
GetVersionFunc: func() string { return github_utils.GetLatestRelease("hadolint", "hadolint") },
UrlTemplate: "https://github.com/hadolint/hadolint/releases/download/{{.Version}}/hadolint-{{.Os|capitalize}}-{{.Arch}}",
GetArchFunc: hadolintGetArchFunc,
},
}

func hashicorpUrlTemplate(name string) string {
Expand Down
47 changes: 47 additions & 0 deletions cmd/sleep/random_verbose/random_verbose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package random_verbose

import (
"fmt"
"math/rand"
"time"

sleep_cmd "github.com/sikalabs/slu/cmd/sleep"
"github.com/spf13/cobra"
)

var FlagMinTime int
var FlagMaxTime int

var Cmd = &cobra.Command{
Use: "random-verbose",
Short: "Sleep random time with verbose output",
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
rand.Seed(time.Now().UnixNano())

sleepTimeInSeconds := rand.Intn(FlagMaxTime-FlagMinTime) + FlagMinTime

fmt.Printf("Sleep %d seconds\n", sleepTimeInSeconds)
for i := 0; i < sleepTimeInSeconds; i++ {
time.Sleep(time.Second)
fmt.Printf("... %d/%d seconds\n", i, sleepTimeInSeconds)
}
fmt.Println("Done.")
},
}

func init() {
sleep_cmd.Cmd.AddCommand(Cmd)
Cmd.Flags().IntVar(
&FlagMinTime,
"min",
0,
"Minimum sleep time (in seconds)",
)
Cmd.Flags().IntVar(
&FlagMaxTime,
"max",
10, // 10s
"Maximum sleep time (in seconds)",
)
}

0 comments on commit 5e3e809

Please sign in to comment.