Skip to content

Commit

Permalink
Add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenSermeus committed Aug 10, 2024
1 parent fb548a4 commit 1d77009
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 55 deletions.
57 changes: 2 additions & 55 deletions anime-tui.go
Original file line number Diff line number Diff line change
@@ -1,62 +1,9 @@
package main

import (
"fmt"
"os"

stplatform "github.com/StevenSermeus/anime-tui/st_platform"
"github.com/StevenSermeus/anime-tui/tui"
"github.com/StevenSermeus/anime-tui/cmd"
)

func main() {
mav := &stplatform.Mavanimes{}
state := "menu"
quit := false
anime_state := stplatform.Anime{}
for !quit {
switch state {
case "menu":
state, quit = tui.Menu()
case "Recherche":
anime, isRetunring, isQuiting, err := tui.Search(mav)
if err != nil {
fmt.Println("Error searching anime:", err)
os.Exit(1)
}
if isQuiting {
quit = true
continue
}
if isRetunring {
state = "menu"
continue
}
anime_state = anime
state = "Episodes"
case "Nouveautés":
isRetunring, isQuiting, err := tui.Newest(mav)
if err != nil {
fmt.Println("Error getting newest anime:", err)
os.Exit(1)
}
if isRetunring {
state = "menu"
continue
}
quit = isQuiting
case "Episodes":
isRetunring, isQuiting, err := tui.Episodes(mav, anime_state)
if err != nil {
fmt.Println("Error getting episodes:", err)
os.Exit(1)
}
if isRetunring {
state = "Recherche"
continue
}
quit = isQuiting
}

}

cmd.Execute()
}
34 changes: 34 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "anime-tui",
Short: "A terminal user interface for anime",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("This is the root command")
},
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of anime-tui",
Run: func(cmd *cobra.Command, args []string) {
// Only change when the tag is changed
// When in othen branch than main put as -dev
fmt.Println("0.0.1-beta")
},
}

func Execute() {
rootCmd.AddCommand(versionCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.26.6
github.com/charmbracelet/lipgloss v0.12.1
github.com/spf13/cobra v1.8.1
)

require (
Expand All @@ -20,6 +21,7 @@ require (
github.com/charmbracelet/x/windows v0.1.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -31,6 +33,7 @@ require (
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXD
github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw=
github.com/charmbracelet/x/windows v0.1.0 h1:gTaxdvzDM5oMa/I2ZNF7wN78X/atWemG9Wph7Ika2k4=
github.com/charmbracelet/x/windows v0.1.0/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ=
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/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
Expand All @@ -52,8 +55,13 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
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/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
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/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down Expand Up @@ -105,3 +113,5 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
60 changes: 60 additions & 0 deletions tui/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package tui

import (
"fmt"
"os"

stplatform "github.com/StevenSermeus/anime-tui/st_platform"
)

func StartTui() {
mav := &stplatform.Mavanimes{}
state := "menu"
quit := false
anime_state := stplatform.Anime{}
for !quit {
switch state {
case "menu":
state, quit = Menu()
case "Recherche":
anime, isRetunring, isQuiting, err := Search(mav)
if err != nil {
fmt.Println("Error searching anime:", err)
os.Exit(1)
}
if isQuiting {
quit = true
continue
}
if isRetunring {
state = "menu"
continue
}
anime_state = anime
state = "Episodes"
case "Nouveautés":
isRetunring, isQuiting, err := Newest(mav)
if err != nil {
fmt.Println("Error getting newest anime:", err)
os.Exit(1)
}
if isRetunring {
state = "menu"
continue
}
quit = isQuiting
case "Episodes":
isRetunring, isQuiting, err := Episodes(mav, anime_state)
if err != nil {
fmt.Println("Error getting episodes:", err)
os.Exit(1)
}
if isRetunring {
state = "Recherche"
continue
}
quit = isQuiting
}

}
}

0 comments on commit 1d77009

Please sign in to comment.