add project first skeleton

This commit is contained in:
2025-11-28 20:12:45 +02:00
parent 9d8918558d
commit f1ed3c977a
8 changed files with 109 additions and 8 deletions

17
cmd/root.go Normal file
View File

@@ -0,0 +1,17 @@
package cmd
import (
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "tsctl",
Short: "Tool for managing TriggerSmith",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
func Execute() error {
return rootCmd.Execute()
}

41
cmd/serve.go Normal file
View File

@@ -0,0 +1,41 @@
package cmd
import (
"log/slog"
"git.oblat.lv/alex/triggerssmith/internal/config"
"github.com/spf13/cobra"
)
var opts = struct {
ConfigPath *string
Debug *bool
}{}
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start the server",
Run: func(cmd *cobra.Command, args []string) {
if *opts.Debug {
slog.SetDefault(slog.New(slog.NewTextHandler(cmd.OutOrStdout(), &slog.HandlerOptions{Level: slog.LevelDebug})))
} else {
slog.SetDefault(slog.New(slog.NewTextHandler(cmd.OutOrStdout(), &slog.HandlerOptions{Level: slog.LevelInfo})))
}
slog.Debug("Starting server")
slog.Debug("Reading configuration", slog.String("path", *opts.ConfigPath))
config, err := config.LoadConfig(*opts.ConfigPath)
if err != nil {
slog.Error("Failed to load configuration", slog.String("path", *opts.ConfigPath), slog.String("error", err.Error()))
return
}
slog.Debug("Configuration loaded", slog.Any("config", config))
slog.Info("Server started", slog.Int("port", config.Server.Port), slog.String("address", config.Server.Addr))
},
}
func init() {
opts.Debug = serveCmd.Flags().BoolP("debug", "d", false, "Enable debug logs")
opts.ConfigPath = serveCmd.Flags().StringP("config", "c", "config.yaml", "Path to configuration file")
rootCmd.AddCommand(serveCmd)
}

View File

@@ -1,7 +0,0 @@
package tsctl
import "fmt"
func main() {
fmt.Println("tsctl main function")
}