diff --git a/Output/README.md b/Output/README.md new file mode 100644 index 0000000..5313da1 --- /dev/null +++ b/Output/README.md @@ -0,0 +1,4 @@ +# test-test + +## TLDR; +A test program generated by bubblewand diff --git a/Output/cmd/root.go b/Output/cmd/root.go new file mode 100644 index 0000000..e23dbb5 --- /dev/null +++ b/Output/cmd/root.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "specCon18/test-test/tui" +) + +var rootCmd = &cobra.Command{ + Use: "test-test", + Short: "test-test, A test program generated by bubblewand", + Run: func(cmd *cobra.Command, args []string) { + if err := tui.Run(); err != nil { + fmt.Println("Error:", err) + os.Exit(1) + } + }, +} + +func Execute() { + cobra.CheckErr(rootCmd.Execute()) +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/Output/cmd/version.go b/Output/cmd/version.go new file mode 100644 index 0000000..298f5bc --- /dev/null +++ b/Output/cmd/version.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the version number of test-test", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("test-test ~ 0.0.6") + }, +} diff --git a/Output/config/config.go b/Output/config/config.go new file mode 100644 index 0000000..318ba30 --- /dev/null +++ b/Output/config/config.go @@ -0,0 +1,19 @@ +package config + +import ( + "fmt" + "github.com/spf13/viper" +) + +func Init() { + viper.SetConfigName("config") // config.yaml + viper.SetConfigType("yaml") + viper.AddConfigPath(".") + + err := viper.ReadInConfig() + if err != nil { + fmt.Println("No config file found; using defaults.") + } + + viper.SetDefault("app.theme", "dark") +} diff --git a/Output/flake.nix b/Output/flake.nix new file mode 100644 index 0000000..055bc51 --- /dev/null +++ b/Output/flake.nix @@ -0,0 +1,75 @@ +# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.22) +{ + # A helpful description of your flake + description = "A test program generated by bubblewand"; + + # Flake inputs + inputs = { + flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*"; + + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*"; + }; + + # Flake outputs that other flakes can use + outputs = + { + self, + flake-schemas, + nixpkgs, + }: + let + # Helpers for producing system-specific outputs + supportedSystems = [ "x86_64-linux" ]; + forEachSupportedSystem = + f: + nixpkgs.lib.genAttrs supportedSystems ( + system: + f { + inherit (nixpkgs) lib; + pkgs = import nixpkgs { inherit system; }; + } + ); + in + { + # Schemas tell Nix about the structure of your flake's outputs + schemas = flake-schemas.schemas; + packages = forEachSupportedSystem ( + { pkgs, lib }: + { + default = pkgs.callPackage ( + { buildGoModule }: + buildGoModule { + pname = "test-test"; + version = "0.0.6"; + src = builtins.path { + name = "source"; + path = ./.; + }; + vendorHash = ""; + } + ) { }; + } + ); + # Development environments + devShells = forEachSupportedSystem ( + { pkgs, ... }: + { + default = pkgs.mkShell { + # Pinned packages available in the environment + packages = with pkgs; [ + just + gcc + go_1_23 + nixpkgs-fmt + gopls + cobra-cli + ]; + env = { + CGO_ENABLED = "1"; + CC = "gcc"; + }; + }; + } + ); + }; +} diff --git a/Output/go.mod b/Output/go.mod new file mode 100644 index 0000000..9fffe36 --- /dev/null +++ b/Output/go.mod @@ -0,0 +1,45 @@ +module specCon18/test-test + +go 1.21 + +require ( + github.com/charmbracelet/bubbletea v0.25.0 + github.com/spf13/cobra v1.7.0 + github.com/spf13/viper v1.17.0 +) + +require ( + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-localereader v0.0.1 // indirect + github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect + github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/reflow v0.3.0 // indirect + github.com/muesli/termenv v0.15.2 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/rivo/uniseg v0.2.0 // indirect + github.com/sagikazarmark/locafero v0.3.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.10.0 // indirect + github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/term v0.6.0 // indirect + golang.org/x/text v0.13.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/Output/internal/logger/logger.go b/Output/internal/logger/logger.go new file mode 100644 index 0000000..1af9776 --- /dev/null +++ b/Output/internal/logger/logger.go @@ -0,0 +1,19 @@ +package logger + +import ( + "os" + + "github.com/charmbracelet/log" +) + +var Log *log.Logger + +func init() { + Log = log.NewWithOptions(os.Stderr, log.Options{ + ReportCaller: false, + ReportTimestamp: true, + Prefix: "test-test", + Level: log.InfoLevel, + }) +} + diff --git a/Output/justfile b/Output/justfile new file mode 100644 index 0000000..96813e3 --- /dev/null +++ b/Output/justfile @@ -0,0 +1,31 @@ + +# Set the shell +set shell := ["bash", "-cu"] + +# Build the Go project +build: + go build -o bin/app . + +# Run the Go project +run: + go run . + +# Run tests +test: + go test ./... + +# Clean build artifacts +clean: + rm -rf bin + +# Format the code +fmt: + go fmt ./... + +# Tidy up go.mod/go.sum +tidy: + go mod tidy + +# Init Go module (optional first step) +init: + go mod init diff --git a/Output/main.go b/Output/main.go new file mode 100644 index 0000000..45141f0 --- /dev/null +++ b/Output/main.go @@ -0,0 +1,7 @@ +package main + +import "specCon18/test-test/cmd" + +func main() { + cmd.Execute() +} diff --git a/Output/tui/model.go b/Output/tui/model.go new file mode 100644 index 0000000..806f35b --- /dev/null +++ b/Output/tui/model.go @@ -0,0 +1,11 @@ +package tui + +import tea "github.com/charmbracelet/bubbletea" + +type model struct { + count int +} + +func (m model) Init() tea.Cmd { + return nil +} diff --git a/Output/tui/run.go b/Output/tui/run.go new file mode 100644 index 0000000..9007620 --- /dev/null +++ b/Output/tui/run.go @@ -0,0 +1,10 @@ +package tui + +import tea "github.com/charmbracelet/bubbletea" + +func Run() error { + p := tea.NewProgram(model{}) + _, err := p.Run() + return err +} + diff --git a/Output/tui/update.go b/Output/tui/update.go new file mode 100644 index 0000000..47983bf --- /dev/null +++ b/Output/tui/update.go @@ -0,0 +1,18 @@ +package tui + +import tea "github.com/charmbracelet/bubbletea" + +func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.KeyMsg: + switch msg.String() { + case "q", "ctrl+c": + return m, tea.Quit + case "up": + m.count++ + case "down": + m.count-- + } + } + return m, nil +} diff --git a/Output/tui/view.go b/Output/tui/view.go new file mode 100644 index 0000000..e988945 --- /dev/null +++ b/Output/tui/view.go @@ -0,0 +1,7 @@ +package tui + +import "fmt" + +func (m model) View() string { + return "Counter: " + fmt.Sprintf("%d", m.count) + "\n[↑/↓ to change, q to quit]" +} diff --git a/cmd/root.go b/cmd/root.go index 1417c2c..4e1df97 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,10 +1,10 @@ package cmd import ( - "log" - "github.com/spf13/cobra" - "specCon18/bubblewand/render" + "specCon18/bubblewand/internal/render" + "specCon18/bubblewand/internal/logger" + ) // CLI flag variables @@ -13,7 +13,7 @@ var ( packageName string programVersion string programDesc string - outputDir string // NEW: output directory flag + outputDir string ) // rootCmd renders templates using CLI flags @@ -31,7 +31,7 @@ var rootCmd = &cobra.Command{ // Render templates to the specified output directory if err := render.RenderTemplates(data, outputDir); err != nil { - log.Fatalf("rendering failed: %v", err) + logger.Log.Fatalf("rendering failed: %v",err) } }, } diff --git a/cmd/tui.go b/cmd/tui.go index d76d488..51c1aff 100644 --- a/cmd/tui.go +++ b/cmd/tui.go @@ -1,11 +1,10 @@ package cmd import ( - "log" - "github.com/charmbracelet/huh" "github.com/spf13/cobra" - "specCon18/bubblewand/render" + "specCon18/bubblewand/internal/render" + "specCon18/bubblewand/internal/logger" ) // tuiCmd renders templates interactively via a form @@ -28,12 +27,12 @@ var tuiCmd = &cobra.Command{ // Run the form and exit on cancel if err := form.Run(); err != nil { - log.Fatalf("form cancelled or failed: %v", err) + logger.Log.Fatalf("form cancelled or failed: %v", err) } // Render templates with user input if err := render.RenderTemplates(data, data.OutputDir); err != nil { - log.Fatalf("rendering failed: %v", err) + logger.Log.Fatalf("rendering failed: %v", err) } }, } diff --git a/go.mod b/go.mod index f9478ce..dcb6dad 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,10 @@ module specCon18/bubblewand + go 1.23.11 require ( github.com/charmbracelet/huh v0.7.0 + github.com/charmbracelet/log v0.4.2 github.com/spf13/cobra v1.9.1 ) @@ -20,6 +22,7 @@ require ( github.com/charmbracelet/x/term v0.2.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect + github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -32,6 +35,7 @@ require ( github.com/rivo/uniseg v0.4.7 // indirect github.com/spf13/pflag v1.0.6 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/sync v0.12.0 // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/text v0.23.0 // indirect diff --git a/go.sum b/go.sum index 1ba451c..a562845 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/charmbracelet/huh v0.7.0 h1:W8S1uyGETgj9Tuda3/JdVkc3x7DBLZYPZc4c+/rnR github.com/charmbracelet/huh v0.7.0/go.mod h1:UGC3DZHlgOKHvHC07a5vHag41zzhpPFj34U92sOmyuk= github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= +github.com/charmbracelet/log v0.4.2 h1:hYt8Qj6a8yLnvR+h7MwsJv/XvmBJXiueUcI3cIxsyig= +github.com/charmbracelet/log v0.4.2/go.mod h1:qifHGX/tc7eluv2R6pWIpyHDDrrb/AG71Pf2ysQu5nw= github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k= @@ -39,10 +41,14 @@ github.com/charmbracelet/x/xpty v0.1.2/go.mod h1:XK2Z0id5rtLWcpeNiMYBccNNBrP2IJn github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= +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/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= 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/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= +github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= @@ -61,6 +67,8 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= +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/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= @@ -69,6 +77,8 @@ github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +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/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= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= @@ -82,4 +92,5 @@ golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +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/internal/logger/logger.go b/internal/logger/logger.go new file mode 100644 index 0000000..1d09dcc --- /dev/null +++ b/internal/logger/logger.go @@ -0,0 +1,19 @@ +package logger + +import ( + "os" + + "github.com/charmbracelet/log" +) + +var Log *log.Logger + +func init() { + Log = log.NewWithOptions(os.Stderr, log.Options{ + ReportCaller: false, + ReportTimestamp: true, + Prefix: "bubblewand", + Level: log.InfoLevel, + }) +} + diff --git a/render/render.go b/internal/render/render.go similarity index 89% rename from render/render.go rename to internal/render/render.go index d76dd72..df1840f 100644 --- a/render/render.go +++ b/internal/render/render.go @@ -1,11 +1,12 @@ package render import ( - "log" + "fmt" "os" "path/filepath" "strings" "text/template" + "specCon18/bubblewand/internal/logger" ) // ProgramData holds user-supplied template values @@ -50,8 +51,9 @@ func RenderTemplates(data ProgramData, outputDir string) error { return err } defer outFile.Close() - - log.Printf("Rendering %s → %s\n", path, outputPath) + + logString := fmt.Sprintf("Rendering %s → %s\n", path, outputPath) + logger.Log.Info(logString) return tmpl.Execute(outFile, data) }) } diff --git a/templates/internal/logger/logger.go.tmpl b/templates/internal/logger/logger.go.tmpl new file mode 100644 index 0000000..1ab0a5d --- /dev/null +++ b/templates/internal/logger/logger.go.tmpl @@ -0,0 +1,19 @@ +package logger + +import ( + "os" + + "github.com/charmbracelet/log" +) + +var Log *log.Logger + +func init() { + Log = log.NewWithOptions(os.Stderr, log.Options{ + ReportCaller: false, + ReportTimestamp: true, + Prefix: "{{.PackageName}}", + Level: log.InfoLevel, + }) +} +