Skip to content

Commit 9ec6861

Browse files
committed
feat: initial commit
0 parents  commit 9ec6861

File tree

8 files changed

+373
-0
lines changed

8 files changed

+373
-0
lines changed

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
weave
2+
build/
3+
4+
# IDE specific files
5+
.idea/
6+
.vscode/
7+
*.swp
8+
9+
# Dependency directories
10+
vendor/
11+
12+
# Logs
13+
*.log
14+
15+
# OS generated files
16+
.DS_Store
17+
Thumbs.db
18+
19+
# GoLand specific files
20+
*.iml

Makefile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/make -f
2+
3+
GO_VERSION=1.22
4+
GO_SYSTEM_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2)
5+
REQUIRE_GO_VERSION = $(GO_VERSION)
6+
7+
BUILDDIR ?= $(CURDIR)/build
8+
BUILD_TARGETS = build
9+
10+
check_version:
11+
ifneq ($(GO_SYSTEM_VERSION), $(REQUIRE_GO_VERSION))
12+
@echo "ERROR: Go version ${REQUIRE_GO_VERSION} is required for Weave."
13+
exit 1
14+
endif
15+
16+
17+
build: BUILD_ARGS=-o $(BUILDDIR)/
18+
19+
$(BUILD_TARGETS): check_version go.sum $(BUILDDIR)/
20+
ifeq ($(OS),Windows_NT)
21+
exit 1
22+
else
23+
go $@ -mod=readonly .
24+
endif
25+
26+
$(BUILDDIR)/:
27+
mkdir -p $(BUILDDIR)/

cmd/root.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
6+
tea "github.com/charmbracelet/bubbletea"
7+
"github.com/spf13/cobra"
8+
"github.com/spf13/viper"
9+
10+
"github.com/initia-labs/weave/tea/radio"
11+
)
12+
13+
var choices = []string{
14+
"Run a L1 Node",
15+
"Launch a New Minitia",
16+
"Run OPinit Bots",
17+
"Run a Relayer",
18+
}
19+
20+
func Execute() error {
21+
rootCmd := &cobra.Command{
22+
Version: "v1.0.0",
23+
Use: "weave",
24+
Long: "Weave is a CLI for managing Initia deployments.",
25+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
26+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
27+
return err
28+
}
29+
viper.AutomaticEnv()
30+
viper.SetEnvPrefix("weave")
31+
32+
return nil
33+
},
34+
RunE: func(cmd *cobra.Command, args []string) error {
35+
if err := tea.NewProgram(radio.NewRadioModel(choices)).Start(); err != nil {
36+
return err
37+
}
38+
return nil
39+
},
40+
}
41+
42+
return rootCmd.ExecuteContext(context.Background())
43+
}

go.mod

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module github.com/initia-labs/weave
2+
3+
go 1.22.6
4+
5+
require (
6+
github.com/charmbracelet/bubbletea v1.1.0
7+
github.com/spf13/cobra v1.8.1
8+
github.com/spf13/viper v1.19.0
9+
github.com/stretchr/testify v1.9.0
10+
)
11+
12+
require (
13+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
14+
github.com/charmbracelet/lipgloss v0.13.0 // indirect
15+
github.com/charmbracelet/x/ansi v0.2.3 // indirect
16+
github.com/charmbracelet/x/term v0.2.0 // indirect
17+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
18+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
19+
github.com/fsnotify/fsnotify v1.7.0 // indirect
20+
github.com/hashicorp/hcl v1.0.0 // indirect
21+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
22+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
23+
github.com/magiconair/properties v1.8.7 // indirect
24+
github.com/mattn/go-isatty v0.0.20 // indirect
25+
github.com/mattn/go-localereader v0.0.1 // indirect
26+
github.com/mattn/go-runewidth v0.0.15 // indirect
27+
github.com/mitchellh/mapstructure v1.5.0 // indirect
28+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
29+
github.com/muesli/cancelreader v0.2.2 // indirect
30+
github.com/muesli/termenv v0.15.2 // indirect
31+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
32+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
33+
github.com/rivo/uniseg v0.4.7 // indirect
34+
github.com/sagikazarmark/locafero v0.4.0 // indirect
35+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
36+
github.com/sourcegraph/conc v0.3.0 // indirect
37+
github.com/spf13/afero v1.11.0 // indirect
38+
github.com/spf13/cast v1.6.0 // indirect
39+
github.com/spf13/pflag v1.0.5 // indirect
40+
github.com/subosito/gotenv v1.6.0 // indirect
41+
go.uber.org/atomic v1.9.0 // indirect
42+
go.uber.org/multierr v1.9.0 // indirect
43+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
44+
golang.org/x/sync v0.8.0 // indirect
45+
golang.org/x/sys v0.24.0 // indirect
46+
golang.org/x/text v0.14.0 // indirect
47+
gopkg.in/ini.v1 v1.67.0 // indirect
48+
gopkg.in/yaml.v3 v3.0.1 // indirect
49+
)

go.sum

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
2+
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
3+
github.com/charmbracelet/bubbletea v1.1.0 h1:FjAl9eAL3HBCHenhz/ZPjkKdScmaS5SK69JAK2YJK9c=
4+
github.com/charmbracelet/bubbletea v1.1.0/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4=
5+
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
6+
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
7+
github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY=
8+
github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
9+
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
10+
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
11+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
12+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
15+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
17+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
18+
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
19+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
20+
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
21+
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
22+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
23+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
24+
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
25+
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
26+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
27+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
28+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
29+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
30+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
31+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
32+
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
33+
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
34+
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
35+
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
36+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
37+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
38+
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
39+
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
40+
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
41+
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
42+
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
43+
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
44+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
45+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
46+
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
47+
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
48+
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
49+
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
50+
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
51+
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
52+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
53+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
54+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
55+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
56+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
57+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
58+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
59+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
60+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
61+
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
62+
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
63+
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
64+
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
65+
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
66+
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
67+
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
68+
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
69+
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
70+
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
71+
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
72+
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
73+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
74+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
75+
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
76+
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
77+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
78+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
79+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
80+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
81+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
82+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
83+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
84+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
85+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
86+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
87+
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
88+
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
89+
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
90+
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
91+
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
92+
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
93+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
94+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
95+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
96+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
97+
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
98+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
99+
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
100+
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
101+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
102+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
103+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
104+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
105+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
106+
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
107+
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
108+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
109+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
110+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"log"
5+
6+
"github.com/initia-labs/weave/cmd"
7+
)
8+
9+
func main() {
10+
if err := cmd.Execute(); err != nil {
11+
log.Fatal(err)
12+
}
13+
}

tea/radio/radio.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package radio
2+
3+
import (
4+
"strings"
5+
6+
tea "github.com/charmbracelet/bubbletea"
7+
)
8+
9+
var _ tea.Model = &Model{}
10+
11+
type Model struct {
12+
availableChoices []string
13+
14+
cursor int
15+
choice string
16+
}
17+
18+
func NewRadioModel(availableChoices []string) *Model {
19+
return &Model{
20+
availableChoices: availableChoices,
21+
cursor: 0,
22+
choice: "",
23+
}
24+
}
25+
26+
func (m Model) Init() tea.Cmd {
27+
return nil
28+
}
29+
30+
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
31+
switch msg := msg.(type) {
32+
case tea.KeyMsg:
33+
switch msg.String() {
34+
case "ctrl+c", "q", "esc":
35+
return m, tea.Quit
36+
37+
case "enter":
38+
m.choice = m.availableChoices[m.cursor]
39+
return m, tea.Quit
40+
41+
case "down", "j":
42+
m.cursor++
43+
if m.cursor >= len(m.availableChoices) {
44+
m.cursor = 0
45+
}
46+
47+
case "up", "k":
48+
m.cursor--
49+
if m.cursor < 0 {
50+
m.cursor = len(m.availableChoices) - 1
51+
}
52+
}
53+
}
54+
55+
return m, nil
56+
}
57+
58+
func (m Model) View() string {
59+
s := strings.Builder{}
60+
s.WriteString("Which action would you like to do?\n\n")
61+
62+
for i := 0; i < len(m.availableChoices); i++ {
63+
if m.cursor == i {
64+
s.WriteString("(•) ")
65+
} else {
66+
s.WriteString("( ) ")
67+
}
68+
s.WriteString(m.availableChoices[i])
69+
s.WriteString("\n")
70+
}
71+
s.WriteString("\n(press q to quit)\n")
72+
73+
return s.String()
74+
}

tea/radio/radio_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package radio
2+
3+
import (
4+
"testing"
5+
6+
tea "github.com/charmbracelet/bubbletea"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestRadioModel(t *testing.T) {
11+
choices := []string{"Choice 1", "Choice 2", "Choice 3"}
12+
model := NewRadioModel(choices)
13+
14+
// Test initial state
15+
assert.Equal(t, 0, model.cursor)
16+
assert.Equal(t, "", model.choice)
17+
18+
// Simulate pressing "down" key
19+
updatedModel, _ := model.Update(tea.KeyMsg{Type: tea.KeyDown})
20+
result := updatedModel.View()
21+
assert.Equal(t, "Which action would you like to do?\n\n( ) Choice 1\n(•) Choice 2\n( ) Choice 3\n\n(press q to quit)\n", result)
22+
23+
// Simulate pressing "down" key again
24+
updatedModel, _ = updatedModel.Update(tea.KeyMsg{Type: tea.KeyDown})
25+
result = updatedModel.View()
26+
assert.Equal(t, "Which action would you like to do?\n\n( ) Choice 1\n( ) Choice 2\n(•) Choice 3\n\n(press q to quit)\n", result)
27+
28+
// Simulate pressing "down" key again (should wrap around)
29+
updatedModel, _ = updatedModel.Update(tea.KeyMsg{Type: tea.KeyDown})
30+
result = updatedModel.View()
31+
assert.Equal(t, "Which action would you like to do?\n\n(•) Choice 1\n( ) Choice 2\n( ) Choice 3\n\n(press q to quit)\n", result)
32+
33+
// Simulate pressing "up" key
34+
updatedModel, _ = updatedModel.Update(tea.KeyMsg{Type: tea.KeyUp})
35+
result = updatedModel.View()
36+
assert.Equal(t, "Which action would you like to do?\n\n( ) Choice 1\n( ) Choice 2\n(•) Choice 3\n\n(press q to quit)\n", result)
37+
}

0 commit comments

Comments
 (0)