Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tsebastiani committed Oct 4, 2024
1 parent 7c7d880 commit 223ce8a
Show file tree
Hide file tree
Showing 409 changed files with 193,785 additions and 1,808 deletions.
28 changes: 28 additions & 0 deletions cmd/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
)

var describeCmd = &cobra.Command{
Use: "describe",
Short: "describes a scenario",
Long: `Describes a scenario`,
Args: cobra.ExactArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"mimmo", "memma"}, cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
if jsonFlag {
fmt.Println("{\"describe\":\"" + args[0] + "\"}")
} else {
fmt.Println("Listing scenarios " + args[0])
}
return nil
},
}

func init() {
rootCmd.AddCommand(describeCmd)
}
36 changes: 36 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"fmt"
"github.com/briandowns/spinner"
"github.com/spf13/cobra"
"time"
)

var listCmd = &cobra.Command{
Use: "list",
Short: "List scenarios",
Long: `List available krkn-hub scenarios`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
s := spinner.New(spinner.CharSets[39], 100*time.Millisecond)
s.Suffix = "fetching scenarios"
s.Start()
time.Sleep(4 * time.Second)
s.Stop()
if offlineFlag {
fmt.Println("OFFLINE MODE")
}
if jsonFlag {
fmt.Println("{\"hello\":\"list\"}")
return nil
} else {
fmt.Println("Listing scenarios...")
return nil
}
},
}

func init() {
rootCmd.AddCommand(listCmd)
}
29 changes: 0 additions & 29 deletions cmd/mix.go

This file was deleted.

13 changes: 10 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ import (
"os"
)

var jsonFlag bool
var offlineFlag bool
var offlineRepoConfig string
var rootCmd = &cobra.Command{
Use: "mixologist",
Short: "Mixologist is your personal bartender.",
Long: `Mixologist acts as a bartender who specializes in cocktail making.`,
Use: "krknctl",
Short: "krkn CLI",
Long: `krkn Command Line Interface`,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}

func Execute() {
rootCmd.PersistentFlags().BoolVarP(&jsonFlag, "json", "j", false, "Output in JSON")
rootCmd.PersistentFlags().BoolVarP(&offlineFlag, "offline", "o", false, "Offline mode")
rootCmd.PersistentFlags().StringVarP(&offlineRepoConfig, "offline-repo-config", "r", "", "Offline repository config file")
rootCmd.MarkFlagsRequiredTogether("offline", "offline-repo-config")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
15 changes: 15 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package config

import (
"encoding/json"
"github.com/krkn-chaos/krknctl/internal/models"
)

func LoadConfig() (models.Config, error) {
var config models.Config
err := json.Unmarshal(ConfigFile, &config)
if err != nil {
return config, err
}
return config, nil
}
6 changes: 6 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"appName": "MyAppProd",
"version": "1.0.0",
"port": 8080,
"debug": true
}
8 changes: 8 additions & 0 deletions config/config_embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !test

package config

import _ "embed"

//go:embed config.json
var ConfigFile []byte
10 changes: 10 additions & 0 deletions config/config_embed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build test

package config

import (
_ "embed"
)

//go:embed config.json
var ConfigFile []byte
6 changes: 6 additions & 0 deletions config/config_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"appName": "MyAppTest",
"version": "1.0.0",
"port": 8080,
"debug": true
}
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ module github.com/krkn-chaos/krknctl
go 1.23.1

require (
github.com/briandowns/spinner v1.23.1
github.com/spf13/cobra v1.8.1
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
)

require (
github.com/fatih/color v1.7.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/term v0.1.0 // indirect
)
15 changes: 13 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
github.com/briandowns/spinner v1.23.1 h1:t5fDPmScwUjozhDj4FA46p5acZWIPXYE30qW2Ptu650=
github.com/briandowns/spinner v1.23.1/go.mod h1:LaZeM4wm2Ywy6vO571mvhQNRcWfRUnXOs0RcKV0wYKM=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 3 additions & 0 deletions internal/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package internal

const Repository = ""
8 changes: 8 additions & 0 deletions internal/models/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package models

type Config struct {
AppName string `json:"appName"`
Version string `json:"version"`
Port int `json:"port"`
Debug bool `json:"debug"`
}
8 changes: 8 additions & 0 deletions internal/models/scenario.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package models

type Scenario struct {
Name string `json:"name"`
Description string `json:"description"`
Digest string `json:"digest"`
LastModified string `json:"last_modified"`
}
9 changes: 9 additions & 0 deletions internal/providers/quay_scenario_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package providers

import "github.com/krkn-chaos/krknctl/internal/models"

type QuayScenarioProvider struct{}

func (p QuayScenarioProvider) GetScenarios() (*[]models.Scenario, error) {

}
7 changes: 7 additions & 0 deletions internal/providers/scenario_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package providers

import "github.com/krkn-chaos/krknctl/internal/models"

type ScenarioProvider interface {
GetScenarios() (*[]models.Scenario, error)
}
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package main

import "github.com/krkn-chaos/krknctl/cmd"
import (
"fmt"
"github.com/krkn-chaos/krknctl/cmd"
krknctl_config "github.com/krkn-chaos/krknctl/config"
"log"
)

func main() {
config, err := krknctl_config.LoadConfig()
if err != nil {
log.Fatalf("Errore nel caricamento della configurazione: %v", err)
}
fmt.Print("config: " + config.AppName)
cmd.Execute()
}
29 changes: 29 additions & 0 deletions vendor/github.com/briandowns/spinner/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions vendor/github.com/briandowns/spinner/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 223ce8a

Please sign in to comment.