Removed old code + refactor

This commit is contained in:
Darius klein 2025-07-19 20:58:05 +02:00
parent 3c77e23020
commit 4a458f66b0
25 changed files with 296 additions and 620 deletions

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM golang:1.24.5-bookworm
LABEL authors="darius"
COPY . .
RUN go build .
ENTRYPOINT ["./kleinCommand"]

View File

@ -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
}

View File

@ -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{}),
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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{},
},
}
}

View File

@ -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,
}
}

View File

@ -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
}

View File

@ -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
}

5
common/config.go Normal file
View File

@ -0,0 +1,5 @@
package common
type Config struct {
environment string `toml:"environment"`
}

View File

@ -0,0 +1,5 @@
# Example config for kleinCommand
# Settings for kleinCommand
[settings]
environment=""

6
common/embeds.go Normal file
View File

@ -0,0 +1,6 @@
package common
import _ "embed"
//go:embed default.config.toml
var DefaultConfig []byte

View File

@ -1,4 +1,4 @@
package services package common
import ( import (
"errors" "errors"
@ -19,7 +19,7 @@ func GetConfigPath() (path string, configPath string, err error) {
return "", "", errors.New("unsupported platform") return "", "", errors.New("unsupported platform")
} }
configPath = filepath.Join(path, "/config.toml") configPath = filepath.Join(path, "/kleinCommand.toml")
return path, configPath, nil return path, configPath, nil
} }

View File

@ -1,15 +1,14 @@
package services package common
import ( import (
"fmt" "fmt"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/DariusKlein/kleinCommand/types"
"os" "os"
) )
var config types.Config var config Config
func ReadConfig() (types.Config, error) { func ReadConfig() (Config, error) {
_, configPath, err := GetConfigPath() _, configPath, err := GetConfigPath()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -2,24 +2,4 @@
# Settings for kleinCommand # Settings for kleinCommand
[settings] [settings]
server_name = "klein server" environment=""
# 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"

31
go.mod
View File

@ -1,31 +1,10 @@
module github.com/DariusKlein/kleinCommand module github.com/DariusKlein/kleinCommand
go 1.22 go 1.24
toolchain go1.24.4
require ( require (
github.com/charmbracelet/bubbletea v0.26.3 github.com/BurntSushi/toml v1.5.0
github.com/google/go-github v17.0.0+incompatible github.com/urfave/cli/v3 v3.3.8
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
) )

63
go.sum
View File

@ -1,51 +1,12 @@
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/charmbracelet/bubbletea v0.26.3 h1:iXyGvI+FfOWqkB2V07m1DF3xxQijxjY2j8PqiXYqasg= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/charmbracelet/bubbletea v0.26.3/go.mod h1:bpZHfDHTYJC5g+FBK+ptJRCQotRC+Dhh3AoMxa/2+3Q= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/charmbracelet/x/ansi v0.1.1 h1:CGAduulr6egay/YVbGc8Hsu8deMg1xZ/bkaXTPi1JDk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/charmbracelet/x/ansi v0.1.1/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/charmbracelet/x/input v0.1.0 h1:TEsGSfZYQyOtp+STIjyBq6tpRaorH0qpwZUj8DavAhQ= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/charmbracelet/x/input v0.1.0/go.mod h1:ZZwaBxPF7IG8gWWzPUVqHEtWhc1+HXJPNuerJGRGZ28= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXDjF6yI= github.com/urfave/cli/v3 v3.3.8 h1:BzolUExliMdet9NlJ/u4m5vHSotJ3PzEqSAZ1oPMa/E=
github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw= github.com/urfave/cli/v3 v3.3.8/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
github.com/charmbracelet/x/windows v0.1.0 h1:gTaxdvzDM5oMa/I2ZNF7wN78X/atWemG9Wph7Ika2k4= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
github.com/charmbracelet/x/windows v0.1.0/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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=

44
main.go
View File

@ -1,45 +1,41 @@
package main package main
import ( import (
"github.com/DariusKlein/kleinCommand/commands/boom" "context"
"github.com/DariusKlein/kleinCommand/commands/bubbleTeaTest" config "github.com/DariusKlein/kleinCommand/commands/config"
"github.com/DariusKlein/kleinCommand/commands/config" "github.com/DariusKlein/kleinCommand/commands/templateCommand"
"github.com/DariusKlein/kleinCommand/commands/games" "github.com/DariusKlein/kleinCommand/common"
"github.com/DariusKlein/kleinCommand/commands/template" "github.com/urfave/cli/v3"
"github.com/DariusKlein/kleinCommand/commands/welcome"
"github.com/DariusKlein/kleinCommand/services"
"github.com/urfave/cli/v2"
"log" "log"
"net/mail"
"os" "os"
) )
func main() { var Config common.Config
Config, _ := services.ReadConfig()
app := &cli.App{ func main() {
Config, _ = common.ReadConfig()
app := &cli.Command{
Name: "KleinCommand", Name: "KleinCommand",
Usage: "manage your home server", Usage: "CLI tool for internal use",
UsageText: "kleinCommand [category] [command] [arguments...]", UsageText: "kleinCommand [category] [command] [arguments...]",
Version: "v0.0.1", Version: "v0.1.0",
HideVersion: true, HideVersion: true,
Authors: []*cli.Author{ Authors: []any{
{ mail.Address{
Name: "Darius", Name: "Darius",
Email: "darius.klein@dariusklein.nl", Address: "darius.klein@dariusklein.nl",
}, },
}, },
DefaultCommand: "help", DefaultCommand: "help",
Commands: []*cli.Command{ Commands: []*cli.Command{
template.Command(Config), config.Category(),
welcome.Command(Config), templateCommand.Category(),
boom.Command(Config),
bubbleTeaTest.Command(Config),
config.Command(Config),
games.Command(Config),
}, },
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(context.Background(), os.Args); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }

View File

@ -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"`
}