Skip to content

Commit 16e8d40

Browse files
committed
typing wip
typing wip Signed-off-by: Tullio Sebastiani <[email protected]>
1 parent 7c7d880 commit 16e8d40

File tree

451 files changed

+213888
-1808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

451 files changed

+213888
-1808
lines changed

cmd/describe.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var describeCmd = &cobra.Command{
9+
Use: "describe",
10+
Short: "describes a scenario",
11+
Long: `Describes a scenario`,
12+
Args: cobra.ExactArgs(1),
13+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
14+
return []string{"mimmo", "memma"}, cobra.ShellCompDirectiveNoFileComp
15+
},
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
if jsonFlag {
18+
fmt.Println("{\"describe\":\"" + args[0] + "\"}")
19+
} else {
20+
fmt.Println("Listing scenarios " + args[0])
21+
}
22+
return nil
23+
},
24+
}
25+
26+
func init() {
27+
rootCmd.AddCommand(describeCmd)
28+
}

cmd/list.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/briandowns/spinner"
6+
"github.com/spf13/cobra"
7+
"time"
8+
)
9+
10+
var listCmd = &cobra.Command{
11+
Use: "list",
12+
Short: "List scenarios",
13+
Long: `List available krkn-hub scenarios`,
14+
Args: cobra.NoArgs,
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
s := spinner.New(spinner.CharSets[39], 100*time.Millisecond)
17+
s.Suffix = "fetching scenarios"
18+
s.Start()
19+
time.Sleep(4 * time.Second)
20+
s.Stop()
21+
if offlineFlag {
22+
fmt.Println("OFFLINE MODE")
23+
}
24+
if jsonFlag {
25+
fmt.Println("{\"hello\":\"list\"}")
26+
return nil
27+
} else {
28+
fmt.Println("Listing scenarios...")
29+
return nil
30+
}
31+
},
32+
}
33+
34+
func init() {
35+
rootCmd.AddCommand(listCmd)
36+
}

cmd/mix.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

cmd/root.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ import (
66
"os"
77
)
88

9+
var jsonFlag bool
10+
var offlineFlag bool
11+
var offlineRepoConfig string
912
var rootCmd = &cobra.Command{
10-
Use: "mixologist",
11-
Short: "Mixologist is your personal bartender.",
12-
Long: `Mixologist acts as a bartender who specializes in cocktail making.`,
13+
Use: "krknctl",
14+
Short: "krkn CLI",
15+
Long: `krkn Command Line Interface`,
1316
RunE: func(cmd *cobra.Command, args []string) error {
1417
return cmd.Help()
1518
},
1619
}
1720

1821
func Execute() {
22+
rootCmd.PersistentFlags().BoolVarP(&jsonFlag, "json", "j", false, "Output in JSON")
23+
rootCmd.PersistentFlags().BoolVarP(&offlineFlag, "offline", "o", false, "Offline mode")
24+
rootCmd.PersistentFlags().StringVarP(&offlineRepoConfig, "offline-repo-config", "r", "", "Offline repository config file")
25+
rootCmd.MarkFlagsRequiredTogether("offline", "offline-repo-config")
1926
if err := rootCmd.Execute(); err != nil {
2027
fmt.Println(err)
2128
os.Exit(1)

config/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package config
2+
3+
import (
4+
"encoding/json"
5+
"github.com/krkn-chaos/krknctl/internal/models"
6+
)
7+
8+
func LoadConfig() (models.Config, error) {
9+
var config models.Config
10+
err := json.Unmarshal(ConfigFile, &config)
11+
if err != nil {
12+
return config, err
13+
}
14+
return config, nil
15+
}

config/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"appName": "MyAppProd",
3+
"version": "1.0.0",
4+
"port": 8080,
5+
"debug": true
6+
}

config/config_embed.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !test
2+
3+
package config
4+
5+
import _ "embed"
6+
7+
//go:embed config.json
8+
var ConfigFile []byte

config/config_embed_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build test
2+
3+
package config
4+
5+
import (
6+
_ "embed"
7+
)
8+
9+
//go:embed config.json
10+
var ConfigFile []byte

config/config_test.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"appName": "MyAppTest",
3+
"version": "1.0.0",
4+
"port": 8080,
5+
"debug": true
6+
}

go.mod

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ module github.com/krkn-chaos/krknctl
33
go 1.23.1
44

55
require (
6+
github.com/briandowns/spinner v1.23.1
67
github.com/spf13/cobra v1.8.1
7-
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
8+
github.com/stretchr/testify v1.9.0
89
)
910

1011
require (
12+
github.com/davecgh/go-spew v1.1.1 // indirect
13+
github.com/fatih/color v1.7.0 // indirect
1114
github.com/inconshreveable/mousetrap v1.1.0 // indirect
15+
github.com/mattn/go-colorable v0.1.2 // indirect
16+
github.com/mattn/go-isatty v0.0.8 // indirect
17+
github.com/pmezard/go-difflib v1.0.0 // indirect
1218
github.com/spf13/pflag v1.0.5 // indirect
19+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
20+
golang.org/x/term v0.1.0 // indirect
21+
gopkg.in/yaml.v3 v3.0.1 // indirect
1322
)

0 commit comments

Comments
 (0)