From 4a458f66b0518b07cadc466577090991cc45595a Mon Sep 17 00:00:00 2001 From: Darius klein Date: Sat, 19 Jul 2025 20:58:05 +0200 Subject: [PATCH] Removed old code + refactor --- Dockerfile | 8 ++ commands/boom/boom.go | 22 --- commands/bubbleTeaTest/bubbleteaTest.go | 33 ----- commands/bubbleTeaTest/model.go | 89 ------------ commands/config/commands.go | 35 +++++ commands/config/config.go | 26 ---- commands/config/subcommands.go | 76 ----------- commands/config/subcommands/createConfig.go | 59 ++++++++ commands/config/subcommands/getConfig.go | 46 +++++++ commands/games/games.go | 28 ---- commands/games/subcommands.go | 127 ------------------ commands/template/template.go | 47 ------- commands/templateCommand/commands.go | 50 +++++++ .../templateCommand/subcommands/template.go | 39 ++++++ commands/welcome/welcome.go | 21 --- common/config.go | 5 + common/default.config.toml | 5 + common/embeds.go | 6 + {services => common}/getConfigPath.go | 4 +- {services => common}/readConfig.go | 7 +- config.toml | 22 +-- go.mod | 31 +---- go.sum | 63 ++------- main.go | 44 +++--- types/config.go | 23 ---- 25 files changed, 296 insertions(+), 620 deletions(-) create mode 100644 Dockerfile delete mode 100644 commands/boom/boom.go delete mode 100644 commands/bubbleTeaTest/bubbleteaTest.go delete mode 100644 commands/bubbleTeaTest/model.go create mode 100644 commands/config/commands.go delete mode 100644 commands/config/config.go delete mode 100644 commands/config/subcommands.go create mode 100644 commands/config/subcommands/createConfig.go create mode 100644 commands/config/subcommands/getConfig.go delete mode 100644 commands/games/games.go delete mode 100644 commands/games/subcommands.go delete mode 100644 commands/template/template.go create mode 100644 commands/templateCommand/commands.go create mode 100644 commands/templateCommand/subcommands/template.go delete mode 100644 commands/welcome/welcome.go create mode 100644 common/config.go create mode 100644 common/default.config.toml create mode 100644 common/embeds.go rename {services => common}/getConfigPath.go (86%) rename {services => common}/readConfig.go (71%) delete mode 100644 types/config.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f28e261 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM golang:1.24.5-bookworm +LABEL authors="darius" + +COPY . . + +RUN go build . + +ENTRYPOINT ["./kleinCommand"] \ No newline at end of file diff --git a/commands/boom/boom.go b/commands/boom/boom.go deleted file mode 100644 index bbf1b0f..0000000 --- a/commands/boom/boom.go +++ /dev/null @@ -1,22 +0,0 @@ -package boom - -import ( - "fmt" - "github.com/DariusKlein/kleinCommand/types" - "github.com/urfave/cli/v2" -) - -func Command(config types.Config) *cli.Command { - - return &cli.Command{ - Name: "boom", - Usage: "explode", - Aliases: []string{"b"}, - Action: action, - } -} - -func action(c *cli.Context) error { - fmt.Println("BOOM") - return nil -} diff --git a/commands/bubbleTeaTest/bubbleteaTest.go b/commands/bubbleTeaTest/bubbleteaTest.go deleted file mode 100644 index 85b9e74..0000000 --- a/commands/bubbleTeaTest/bubbleteaTest.go +++ /dev/null @@ -1,33 +0,0 @@ -package bubbleTeaTest - -import ( - "github.com/DariusKlein/kleinCommand/types" - tea "github.com/charmbracelet/bubbletea" - "github.com/urfave/cli/v2" -) - -func Command(config types.Config) *cli.Command { - return &cli.Command{ - Name: "BubbleTeaTest", - Usage: "USAGE OF COMMAND", - Action: action, - } -} - -func action(*cli.Context) error { - p := tea.NewProgram(initialModel()) - p.Run() - return nil -} - -func initialModel() model { - return model{ - // Our to-do list is a grocery list - choices: []string{"Buy carrots", "Buy celery", "Buy kohlrabi"}, - - // A map which indicates which choices are selected. We're using - // the map like a mathematical set. The keys refer to the indexes - // of the `choices` slice, above. - selected: make(map[int]struct{}), - } -} diff --git a/commands/bubbleTeaTest/model.go b/commands/bubbleTeaTest/model.go deleted file mode 100644 index 076d349..0000000 --- a/commands/bubbleTeaTest/model.go +++ /dev/null @@ -1,89 +0,0 @@ -package bubbleTeaTest - -import ( - "fmt" - tea "github.com/charmbracelet/bubbletea" -) - -type model struct { - choices []string // items on the to-do list - cursor int // which to-do list item our cursor is pointing at - selected map[int]struct{} // which to-do items are selected -} - -func (m model) Init() tea.Cmd { - // Just return `nil`, which means "no I/O right now, please." - return nil -} - -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - switch msg := msg.(type) { - - // Is it a key press? - case tea.KeyMsg: - - // Cool, what was the actual key pressed? - switch msg.String() { - - // These keys should exit the program. - case "ctrl+c", "q": - return m, tea.Quit - - // The "up" and "k" keys move the cursor up - case "up", "k": - if m.cursor > 0 { - m.cursor-- - } - - // The "down" and "j" keys move the cursor down - case "down", "j": - if m.cursor < len(m.choices)-1 { - m.cursor++ - } - - // The "enter" key and the spacebar (a literal space) toggle - // the selected state for the item that the cursor is pointing at. - case "enter", " ": - _, ok := m.selected[m.cursor] - if ok { - delete(m.selected, m.cursor) - } else { - m.selected[m.cursor] = struct{}{} - } - } - } - - // Return the updated model to the Bubble Tea runtime for processing. - // Note that we're not returning a command. - return m, nil -} - -func (m model) View() string { - // The header - s := "What should we buy at the market?\n\n" - - // Iterate over our choices - for i, choice := range m.choices { - - // Is the cursor pointing at this choice? - cursor := " " // no cursor - if m.cursor == i { - cursor = ">" // cursor! - } - - // Is this choice selected? - checked := " " // not selected - if _, ok := m.selected[i]; ok { - checked = "x" // selected! - } - - // Render the row - s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice) - } - - // The footer - s += "\nPress q to quit.\n" - - // Send the UI for rendering - return s -} diff --git a/commands/config/commands.go b/commands/config/commands.go new file mode 100644 index 0000000..38c7a90 --- /dev/null +++ b/commands/config/commands.go @@ -0,0 +1,35 @@ +package config + +import ( + "context" + "github.com/DariusKlein/kleinCommand/commands/config/subcommands" + "github.com/urfave/cli/v3" +) + +// Category config +func Category() *cli.Command { + return &cli.Command{ + Name: "config", + Usage: "command to interact with config", + Action: Action, + Commands: commands(), + HideHelpCommand: true, + } +} + +// commands for Config Category +func commands() []*cli.Command { + return []*cli.Command{ + subcommands.CreateConfig(), + subcommands.GetConfig(), + } +} + +// Action show help command if no sub commands are given for Config +func Action(context context.Context, c *cli.Command) error { + err := cli.ShowSubcommandHelp(c) + if err != nil { + return err + } + return nil +} diff --git a/commands/config/config.go b/commands/config/config.go deleted file mode 100644 index 2ea3b30..0000000 --- a/commands/config/config.go +++ /dev/null @@ -1,26 +0,0 @@ -package config - -import ( - "github.com/DariusKlein/kleinCommand/types" - "github.com/urfave/cli/v2" -) - -func Command(config types.Config) *cli.Command { - return &cli.Command{ - Name: "config", - Usage: "manage config file", - Aliases: []string{"cf"}, - Action: action, - Category: "\nManagement", - Subcommands: subcommands(), - HideHelpCommand: true, - } -} - -func action(c *cli.Context) error { - err := cli.ShowSubcommandHelp(c) - if err != nil { - return err - } - return nil -} diff --git a/commands/config/subcommands.go b/commands/config/subcommands.go deleted file mode 100644 index f04a0f9..0000000 --- a/commands/config/subcommands.go +++ /dev/null @@ -1,76 +0,0 @@ -package config - -import ( - "context" - "encoding/base64" - "errors" - "fmt" - "github.com/DariusKlein/kleinCommand/services" - "github.com/google/go-github/github" - "github.com/urfave/cli/v2" - "os" -) - -func subcommands() []*cli.Command { - return []*cli.Command{ - { - Name: "create", - Usage: "Generates a new configuration file", - Action: creatAction, - Flags: []cli.Flag{ - &cli.BoolFlag{ - Name: "force", - Aliases: []string{"f"}, - Usage: "force overwrite", - }, - }, - }, - { - Name: "get", - Usage: "prints configuration file to stdout", - Action: printAction, - }, - } -} - -func creatAction(c *cli.Context) error { - path, configPath, err := services.GetConfigPath() - if err != nil { - fmt.Println(err) - } - fmt.Println("Creating configuration file") - if err = os.MkdirAll(path, 0770); err != nil { - return err - } - - if _, err = os.Stat(configPath); errors.Is(err, os.ErrNotExist) || c.Bool("force") { - - client := github.NewClient(nil) - defaultConfig, _, _, _ := client.Repositories.GetContents(context.Background(), "DariusKlein", "kleinCommand", "config.toml", nil) - - configString, _ := base64.StdEncoding.DecodeString(*defaultConfig.Content) - - err = os.WriteFile(configPath, configString, 0644) - if err != nil { - return err - } - fmt.Println("Created: " + configPath) - } else { - fmt.Println("Configuration file already exists") - } - return nil -} - -func printAction(c *cli.Context) error { - _, configPath, err := services.GetConfigPath() - if err != nil { - fmt.Println(err) - } - - file, err := os.ReadFile(configPath) - if err != nil { - return err - } - fmt.Println(string(file)) - return nil -} diff --git a/commands/config/subcommands/createConfig.go b/commands/config/subcommands/createConfig.go new file mode 100644 index 0000000..8f89fbd --- /dev/null +++ b/commands/config/subcommands/createConfig.go @@ -0,0 +1,59 @@ +package subcommands + +import ( + "context" + "errors" + "fmt" + "github.com/DariusKlein/kleinCommand/common" + "github.com/urfave/cli/v3" + "log" + "os" +) + +var force bool + +// CreateConfig Command +func CreateConfig() *cli.Command { + return &cli.Command{ + Name: "create", + Usage: "Generates a new configuration file", + Action: createConfigAction, + Flags: createConfigFlags(), + } +} + +// createConfigFlags Register cli flags +func createConfigFlags() []cli.Flag { + return []cli.Flag{ + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "force overwrite", + Destination: &force, + }, + } +} + +// createConfigAction create config file +func createConfigAction(context context.Context, c *cli.Command) error { + path, configPath, err := common.GetConfigPath() + if err != nil { + return err + } + log.Println("Creating configuration file") + if err = os.MkdirAll(path, 0770); err != nil { + return err + } + + if _, err = os.Stat(configPath); errors.Is(err, os.ErrNotExist) || force { + + err = os.WriteFile(configPath, common.DefaultConfig, 0644) + if err != nil { + return err + } + fmt.Println("Created: " + configPath) + } else { + fmt.Println("Configuration file already exists") + } + return nil +} diff --git a/commands/config/subcommands/getConfig.go b/commands/config/subcommands/getConfig.go new file mode 100644 index 0000000..26307d9 --- /dev/null +++ b/commands/config/subcommands/getConfig.go @@ -0,0 +1,46 @@ +package subcommands + +import ( + "context" + "fmt" + "github.com/DariusKlein/kleinCommand/common" + "github.com/urfave/cli/v3" + "os" +) + +// GetConfig Command +func GetConfig() *cli.Command { + return &cli.Command{ + Name: "get", + Usage: "read configuration file", + Action: getConfigAction, + Flags: getConfigFlags(), + } +} + +// getConfigFlags Register cli flags +func getConfigFlags() []cli.Flag { + return []cli.Flag{ + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Usage: "force overwrite", + Destination: &force, + }, + } +} + +// getConfigAction logic for GetConfig +func getConfigAction(context context.Context, c *cli.Command) error { + _, configPath, err := common.GetConfigPath() + if err != nil { + fmt.Println(err) + } + + file, err := os.ReadFile(configPath) + if err != nil { + return err + } + fmt.Println(string(file)) + return nil +} diff --git a/commands/games/games.go b/commands/games/games.go deleted file mode 100644 index 1422746..0000000 --- a/commands/games/games.go +++ /dev/null @@ -1,28 +0,0 @@ -package games - -import ( - "github.com/DariusKlein/kleinCommand/types" - "github.com/urfave/cli/v2" -) - -var config types.Config - -func Command(conf types.Config) *cli.Command { - config = conf - return &cli.Command{ - Name: "games", - Usage: "manage game servers", - Aliases: []string{"gs"}, - Action: action, - Subcommands: subcommands(), - HideHelpCommand: true, - } -} - -func action(c *cli.Context) error { - err := cli.ShowSubcommandHelp(c) - if err != nil { - return err - } - return nil -} diff --git a/commands/games/subcommands.go b/commands/games/subcommands.go deleted file mode 100644 index 0e963b1..0000000 --- a/commands/games/subcommands.go +++ /dev/null @@ -1,127 +0,0 @@ -package games - -import ( - "fmt" - "github.com/BurntSushi/toml" - "github.com/DariusKlein/kleinCommand/services" - "github.com/DariusKlein/kleinCommand/types" - "github.com/urfave/cli/v2" - "os" - "os/exec" - "strconv" - "strings" -) - -func subcommands() []*cli.Command { - return []*cli.Command{ - { - Name: "register", - Usage: "Register game server", - Action: registerAction, - Flags: registerFlags(), - }, - { - Name: "list", - Usage: "List of game servers", - Aliases: []string{"l"}, - Action: listAction, - Flags: []cli.Flag{}, - }, - { - Name: "status", - Usage: "Get status of game servers", - Aliases: []string{"s"}, - Action: statusAction, - Flags: []cli.Flag{}, - }, - } -} - -func registerAction(c *cli.Context) error { - - for _, games := range config.CustomCommands.Games { - if games.Name == c.String("name") { - return fmt.Errorf("game '%s' already exists", games.Name) - } - } - - config.CustomCommands.Games = append(config.CustomCommands.Games, types.Games{ - Name: c.String("name"), - StatusCommand: c.String("status"), - StartCommand: c.String("start_command"), - StopCommand: c.String("stop_command"), - }) - - configString, err := toml.Marshal(config) - if err != nil { - return err - } - - _, configPath, err := services.GetConfigPath() - if err != nil { - fmt.Println(err) - } - - err = os.WriteFile(configPath, configString, 0644) - if err != nil { - return err - } - return nil -} - -func registerFlags() []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "name", - Aliases: []string{"n"}, - Usage: "Game server name", - Required: true, - }, - &cli.StringFlag{ - Name: "status_command", - Aliases: []string{"status"}, - Usage: "Game server status command", - Required: true, - }, - &cli.StringFlag{ - Name: "start_command", - Aliases: []string{"start"}, - Usage: "Game server start command", - Required: true, - }, - &cli.StringFlag{ - Name: "stop_command", - Aliases: []string{"stop"}, - Usage: "Game server stop command", - Required: true, - }, - } -} - -func listAction(c *cli.Context) error { - fmt.Println("List of game servers") - for i, game := range config.CustomCommands.Games { - fmt.Println( - strconv.Itoa(i+1) + ") \n" + - "\tName: " + game.Name + - "\n\tStatus command: " + game.StatusCommand + - "\n\tStart command: " + game.StartCommand + - "\n\tStop command: " + game.StopCommand) - } - return nil -} - -func statusAction(c *cli.Context) error { - fmt.Println("List of game servers") - for _, game := range config.CustomCommands.Games { - command := strings.Fields(game.StatusCommand) - cmd := exec.Command(command[0], command[1:]...) - stdout, err := cmd.Output() - if err != nil { - return err - } - fmt.Println(game.Name + ": " + string(stdout)) - } - - return nil -} diff --git a/commands/template/template.go b/commands/template/template.go deleted file mode 100644 index 6cb7305..0000000 --- a/commands/template/template.go +++ /dev/null @@ -1,47 +0,0 @@ -package template - -import ( - "fmt" - "github.com/DariusKlein/kleinCommand/types" - "github.com/urfave/cli/v2" -) - -func Command(config types.Config) *cli.Command { - - return &cli.Command{ - Name: "NAME", - Usage: "USAGE OF COMMAND", - Aliases: []string{"T"}, - Action: action, - Flags: flags(), - Category: "\nTEMPLATE", - Subcommands: subcommands(), - HideHelpCommand: true, - } -} - -func action(c *cli.Context) error { - fmt.Println("TEMPLATE RESPONSE") - return nil -} - -func flags() []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "test", - Aliases: []string{"t"}, - }, - } -} - -func subcommands() []*cli.Command { - return []*cli.Command{ - { - Name: "NAME", - Usage: "USAGE OF COMMAND", - Aliases: []string{"T"}, - Action: action, - Flags: []cli.Flag{}, - }, - } -} diff --git a/commands/templateCommand/commands.go b/commands/templateCommand/commands.go new file mode 100644 index 0000000..d26409b --- /dev/null +++ b/commands/templateCommand/commands.go @@ -0,0 +1,50 @@ +package templateCommand + +import ( + "context" + "github.com/DariusKlein/kleinCommand/commands/templateCommand/subcommands" + "github.com/urfave/cli/v3" +) + +// Category CATEGORY NAME +func Category() *cli.Command { + return &cli.Command{ + Name: "template", + Usage: "template commands", + Aliases: []string{"template"}, + Action: Action, + Commands: commands(), + HideHelpCommand: true, + } +} + +// commands for CATEGORY NAME Category +func commands() []*cli.Command { + return []*cli.Command{ + //commands or sub-category here + subCategory(), + } +} + +// action show help command if no sub commands are given for Category +func Action(context context.Context, c *cli.Command) error { + err := cli.ShowSubcommandHelp(c) + if err != nil { + return err + } + return nil +} + +// PLACEHOLDER sub-category of CATEGORY NAME Category +func subCategory() *cli.Command { + return &cli.Command{ + Name: "sub-category-template", + Usage: "commands for sub-category-template", + Action: Action, + Commands: []*cli.Command{ + //commands or sub-category here + subcommands.Template(), + }, + HideHelpCommand: true, + } +} diff --git a/commands/templateCommand/subcommands/template.go b/commands/templateCommand/subcommands/template.go new file mode 100644 index 0000000..607d34a --- /dev/null +++ b/commands/templateCommand/subcommands/template.go @@ -0,0 +1,39 @@ +package subcommands + +import ( + "context" + "github.com/urfave/cli/v3" +) + +var templateVar int + +// Template Command +func Template() *cli.Command { + return &cli.Command{ + Name: "template command", + Usage: "template command usage", + Action: templateAction, + Flags: templateFlags(), + ArgsUsage: "args usage", + } +} + +// templateFlags Register cli flags +func templateFlags() []cli.Flag { + return []cli.Flag{ + &cli.IntFlag{ + Name: "template", + Aliases: []string{"t"}, + Usage: "usage", + Value: 1000, + DefaultText: "default text", + Required: false, + Destination: &templateVar, + }, + } +} + +// templateAction logic for Template +func templateAction(context context.Context, c *cli.Command) error { + return nil +} diff --git a/commands/welcome/welcome.go b/commands/welcome/welcome.go deleted file mode 100644 index 6e492d4..0000000 --- a/commands/welcome/welcome.go +++ /dev/null @@ -1,21 +0,0 @@ -package welcome - -import ( - "fmt" - "github.com/DariusKlein/kleinCommand/types" - "github.com/urfave/cli/v2" -) - -func Command(config types.Config) *cli.Command { - - return &cli.Command{ - Name: "welcome", - Usage: "Explains cli tool", - Action: action, - } -} - -func action(*cli.Context) error { - fmt.Println("Welcome, \n you can use -h, --help for help.") - return nil -} diff --git a/common/config.go b/common/config.go new file mode 100644 index 0000000..0c985eb --- /dev/null +++ b/common/config.go @@ -0,0 +1,5 @@ +package common + +type Config struct { + environment string `toml:"environment"` +} diff --git a/common/default.config.toml b/common/default.config.toml new file mode 100644 index 0000000..a028bd6 --- /dev/null +++ b/common/default.config.toml @@ -0,0 +1,5 @@ +# Example config for kleinCommand + +# Settings for kleinCommand +[settings] +environment="" \ No newline at end of file diff --git a/common/embeds.go b/common/embeds.go new file mode 100644 index 0000000..f49d834 --- /dev/null +++ b/common/embeds.go @@ -0,0 +1,6 @@ +package common + +import _ "embed" + +//go:embed default.config.toml +var DefaultConfig []byte diff --git a/services/getConfigPath.go b/common/getConfigPath.go similarity index 86% rename from services/getConfigPath.go rename to common/getConfigPath.go index f722cab..d7f4ea1 100644 --- a/services/getConfigPath.go +++ b/common/getConfigPath.go @@ -1,4 +1,4 @@ -package services +package common import ( "errors" @@ -19,7 +19,7 @@ func GetConfigPath() (path string, configPath string, err error) { return "", "", errors.New("unsupported platform") } - configPath = filepath.Join(path, "/config.toml") + configPath = filepath.Join(path, "/kleinCommand.toml") return path, configPath, nil } diff --git a/services/readConfig.go b/common/readConfig.go similarity index 71% rename from services/readConfig.go rename to common/readConfig.go index 3f6a915..3fa4775 100644 --- a/services/readConfig.go +++ b/common/readConfig.go @@ -1,15 +1,14 @@ -package services +package common import ( "fmt" "github.com/BurntSushi/toml" - "github.com/DariusKlein/kleinCommand/types" "os" ) -var config types.Config +var config Config -func ReadConfig() (types.Config, error) { +func ReadConfig() (Config, error) { _, configPath, err := GetConfigPath() if err != nil { fmt.Println(err) diff --git a/config.toml b/config.toml index 44a9b21..a028bd6 100644 --- a/config.toml +++ b/config.toml @@ -2,24 +2,4 @@ # Settings for kleinCommand [settings] -server_name = "klein server" - -# Variable overrides -[variables] -string1="example" -int1=1 - -# Custom commands -[custom_commands] -# Generate commands with kleinCommand or configure here -[[custom_commands.games]] -name="example" -status_command="docker ps --format '{{.Names}}'" -start_command="echo start" -stop_command="echo stop" - -[[custom_commands.games]] -name="test" -status_command='curl -s -o NUL -w "%{http_code}" https://api.portfolio.dariusklein.nl/check' -start_command="echo start" -stop_command="echo stop" \ No newline at end of file +environment="" \ No newline at end of file diff --git a/go.mod b/go.mod index e5ec1c3..1199187 100644 --- a/go.mod +++ b/go.mod @@ -1,31 +1,10 @@ module github.com/DariusKlein/kleinCommand -go 1.22 +go 1.24 + +toolchain go1.24.4 require ( - github.com/charmbracelet/bubbletea v0.26.3 - github.com/google/go-github v17.0.0+incompatible - github.com/urfave/cli/v2 v2.27.2 -) - -require ( - github.com/BurntSushi/toml v1.4.0 // indirect - github.com/charmbracelet/x/ansi v0.1.1 // indirect - github.com/charmbracelet/x/input v0.1.0 // indirect - github.com/charmbracelet/x/term v0.1.1 // indirect - github.com/charmbracelet/x/windows v0.1.0 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect - github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect - github.com/google/go-querystring v1.1.0 // indirect - github.com/mattn/go-localereader v0.0.1 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect - github.com/muesli/cancelreader v0.2.2 // indirect - github.com/rivo/uniseg v0.4.7 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.3.8 // indirect + github.com/BurntSushi/toml v1.5.0 + github.com/urfave/cli/v3 v3.3.8 ) diff --git a/go.sum b/go.sum index 2cc9be3..41c226c 100644 --- a/go.sum +++ b/go.sum @@ -1,51 +1,12 @@ -github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= -github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/charmbracelet/bubbletea v0.26.3 h1:iXyGvI+FfOWqkB2V07m1DF3xxQijxjY2j8PqiXYqasg= -github.com/charmbracelet/bubbletea v0.26.3/go.mod h1:bpZHfDHTYJC5g+FBK+ptJRCQotRC+Dhh3AoMxa/2+3Q= -github.com/charmbracelet/x/ansi v0.1.1 h1:CGAduulr6egay/YVbGc8Hsu8deMg1xZ/bkaXTPi1JDk= -github.com/charmbracelet/x/ansi v0.1.1/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= -github.com/charmbracelet/x/input v0.1.0 h1:TEsGSfZYQyOtp+STIjyBq6tpRaorH0qpwZUj8DavAhQ= -github.com/charmbracelet/x/input v0.1.0/go.mod h1:ZZwaBxPF7IG8gWWzPUVqHEtWhc1+HXJPNuerJGRGZ28= -github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXDjF6yI= -github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw= -github.com/charmbracelet/x/windows v0.1.0 h1:gTaxdvzDM5oMa/I2ZNF7wN78X/atWemG9Wph7Ika2k4= -github.com/charmbracelet/x/windows v0.1.0/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ= -github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= -github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= -github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= -github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= -github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= -github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= -github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= -github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= -github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= -github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= -github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= -github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= -github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= -github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= -github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= -github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk= -golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= -golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= +github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/urfave/cli/v3 v3.3.8 h1:BzolUExliMdet9NlJ/u4m5vHSotJ3PzEqSAZ1oPMa/E= +github.com/urfave/cli/v3 v3.3.8/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 9ebbc89..aecf44c 100644 --- a/main.go +++ b/main.go @@ -1,45 +1,41 @@ package main import ( - "github.com/DariusKlein/kleinCommand/commands/boom" - "github.com/DariusKlein/kleinCommand/commands/bubbleTeaTest" - "github.com/DariusKlein/kleinCommand/commands/config" - "github.com/DariusKlein/kleinCommand/commands/games" - "github.com/DariusKlein/kleinCommand/commands/template" - "github.com/DariusKlein/kleinCommand/commands/welcome" - "github.com/DariusKlein/kleinCommand/services" - "github.com/urfave/cli/v2" + "context" + config "github.com/DariusKlein/kleinCommand/commands/config" + "github.com/DariusKlein/kleinCommand/commands/templateCommand" + "github.com/DariusKlein/kleinCommand/common" + "github.com/urfave/cli/v3" "log" + "net/mail" "os" ) -func main() { - Config, _ := services.ReadConfig() +var Config common.Config - app := &cli.App{ +func main() { + Config, _ = common.ReadConfig() + + app := &cli.Command{ Name: "KleinCommand", - Usage: "manage your home server", + Usage: "CLI tool for internal use", UsageText: "kleinCommand [category] [command] [arguments...]", - Version: "v0.0.1", + Version: "v0.1.0", HideVersion: true, - Authors: []*cli.Author{ - { - Name: "Darius", - Email: "darius.klein@dariusklein.nl", + Authors: []any{ + mail.Address{ + Name: "Darius", + Address: "darius.klein@dariusklein.nl", }, }, DefaultCommand: "help", Commands: []*cli.Command{ - template.Command(Config), - welcome.Command(Config), - boom.Command(Config), - bubbleTeaTest.Command(Config), - config.Command(Config), - games.Command(Config), + config.Category(), + templateCommand.Category(), }, } - if err := app.Run(os.Args); err != nil { + if err := app.Run(context.Background(), os.Args); err != nil { log.Fatal(err) } } diff --git a/types/config.go b/types/config.go deleted file mode 100644 index 9c15723..0000000 --- a/types/config.go +++ /dev/null @@ -1,23 +0,0 @@ -package types - -type Config struct { - Settings Settings `toml:"settings"` - Variables Variables `toml:"variables"` - CustomCommands CustomCommands `toml:"custom_commands"` -} -type Settings struct { - ServerName string `toml:"server_name"` -} -type Variables struct { - String1 string `toml:"string1"` - Int1 int `toml:"int1"` -} -type Games struct { - Name string `toml:"name"` - StatusCommand string `toml:"status_command"` - StartCommand string `toml:"start_command"` - StopCommand string `toml:"stop_command"` -} -type CustomCommands struct { - Games []Games `toml:"games"` -}