Skip to content

Commit 26524a1

Browse files
authored
feat: integrate with cobra cli (#8)
* restructured the codebase to account for the cobra-cli library, the cmd/root.go src that invokes the TUI is now relegated to be summoned by a cobra command. This implies that the default behaviour of the program are the cobra commands. Signed-off-by: tobigiwa <giwaoluwatobi@gmail.com> * added the cobra library (github.com/spf13/cobra) and initialised cobra command (cobra-cli init). Included a file license and asciiArt text file. Signed-off-by: tobigiwa <giwaoluwatobi@gmail.com> * cobra launch command for bubbletea TUI. included the launch cobra commad to display the TUI bubbletea view. Modified cmd/root.go and included file license. Signed-off-by: tobigiwa <giwaoluwatobi@gmail.com> * copied LICENSE from branch "develop" i think cobra might have cleared it. Signed-off-by: tobigiwa <giwaoluwatobi@gmail.com> * resolves #6 Signed-off-by: tobigiwa <giwaoluwatobi@gmail.com> * Resolves #6 removed license from .go files Signed-off-by: tobigiwa <giwaoluwatobi@gmail.com> --------- Signed-off-by: tobigiwa <giwaoluwatobi@gmail.com>
1 parent c619e7d commit 26524a1

File tree

7 files changed

+93
-9
lines changed

7 files changed

+93
-9
lines changed

asciiArt.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
____ __ __ ____ ____ ____ ____ __ ____ ___ __ __
2+
( _ \ / \ / \(_ _)/ ___)(_ _)( _ \ / _\ ( _ \ ___ / __)( ) ( )
3+
) _ (( O )( O ) )( \___ \ )( ) // \ ) __/(___)( (__ / (_/\ )(
4+
(____/ \__/ \__/ (__) (____/ (__) (__\_)\_/\_/(__) \___)\____/(__)

cmd/launch.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
"github.com/wingkwong/bootstrap-cli/internal/ui"
6+
)
7+
8+
// launchCmd represents the launch command
9+
var launchCmd = &cobra.Command{
10+
Use: "launch",
11+
Short: "launches text user interface view",
12+
Long: "launches the TUI (text user interface) view for the application",
13+
Aliases: []string{"tui"},
14+
Run: func(cmd *cobra.Command, args []string) {
15+
16+
ui.Execute()
17+
},
18+
}
19+
20+
func init() {
21+
rootCmd.AddCommand(launchCmd)
22+
}

cmd/root.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,46 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

7-
tea "github.com/charmbracelet/bubbletea"
8-
"github.com/wingkwong/bootstrap-cli/internal/ui"
8+
"github.com/spf13/cobra"
99
)
1010

11-
func Execute() {
12-
p := tea.NewProgram(ui.New())
11+
// rootCmd represents the base command when called without any subcommands
12+
var rootCmd = &cobra.Command{
13+
Use: "bootstrap-cli",
14+
Short: "A minimalistic CLI to bootstrap projects with different frameworks",
15+
Long: GetAsciiArt() + "\nA minimalistic CLI to bootstrap projects with different frameworks.",
16+
}
1317

14-
if _, err := p.Run(); err != nil {
15-
fmt.Println("Error running bootstrap-cli:", err)
18+
func Execute() {
19+
err := rootCmd.Execute()
20+
if err != nil {
1621
os.Exit(1)
1722
}
1823
}
24+
25+
func init() {
26+
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
27+
}
28+
29+
func GetAsciiArt() string {
30+
31+
var (
32+
colorArr = [5]string{"\u001b[33m", "\u001b[33m", "\u001b[33m", "\u001b[31m", "\u001b[35m"}
33+
turnoff = "\u001b[0m\n"
34+
buf strings.Builder
35+
bytes []byte
36+
err error
37+
)
38+
39+
if bytes, err = os.ReadFile("asciiArt.txt"); err != nil {
40+
return "no file"
41+
}
42+
strSlice := strings.Split(string(bytes), "\n")
43+
for i, color := range colorArr {
44+
buf.WriteString(fmt.Sprintf("%s %s %s", color, strSlice[i], turnoff))
45+
}
46+
return buf.String()
47+
48+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/atotto/clipboard v0.1.4 // indirect
1313
github.com/aymanbagabas/go-osc52 v1.2.1 // indirect
1414
github.com/containerd/console v1.0.3 // indirect
15+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1516
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
1617
github.com/mattn/go-isatty v0.0.17 // indirect
1718
github.com/mattn/go-localereader v0.0.1 // indirect
@@ -22,6 +23,8 @@ require (
2223
github.com/muesli/termenv v0.14.0 // indirect
2324
github.com/rivo/uniseg v0.2.0 // indirect
2425
github.com/sahilm/fuzzy v0.1.0 // indirect
26+
github.com/spf13/cobra v1.8.0 // indirect
27+
github.com/spf13/pflag v1.0.5 // indirect
2528
golang.org/x/sync v0.1.0 // indirect
2629
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
2730
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ github.com/charmbracelet/lipgloss v0.6.0 h1:1StyZB9vBSOyuZxQUcUwGr17JmojPNm87ini
1313
github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk=
1414
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
1515
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
16+
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
17+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
18+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
1619
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
1720
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
1821
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
@@ -42,8 +45,13 @@ github.com/muesli/termenv v0.14.0/go.mod h1:kG/pF1E7fh949Xhe156crRUrHNyK221IuGO7
4245
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
4346
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
4447
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
48+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
4549
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
4650
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
51+
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
52+
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
53+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
54+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
4755
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
4856
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4957
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -57,3 +65,5 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
5765
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
5866
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
5967
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
68+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
69+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/ui/root.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ui
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
tea "github.com/charmbracelet/bubbletea"
8+
)
9+
10+
func Execute() {
11+
p := tea.NewProgram(New())
12+
13+
if _, err := p.Run(); err != nil {
14+
fmt.Println("Error running bootstrap-cli:", err)
15+
os.Exit(1)
16+
}
17+
}

main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package main
22

3-
import (
4-
"github.com/wingkwong/bootstrap-cli/cmd"
5-
)
3+
import "github.com/wingkwong/bootstrap-cli/cmd"
64

75
func main() {
86
cmd.Execute()

0 commit comments

Comments
 (0)