Skip to content

Commit d25f11e

Browse files
committed
Split utils package into smaller packages
1 parent f754311 commit d25f11e

File tree

19 files changed

+423
-579
lines changed

19 files changed

+423
-579
lines changed

cli/input.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

cli/output.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

commands/docs.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"os"
55
"path/filepath"
66

7-
"github.com/code-game-project/codegame-cli/cli"
8-
"github.com/code-game-project/codegame-cli/util"
7+
"github.com/Bananenpro/cli"
8+
"github.com/code-game-project/codegame-cli/util/cggenevents"
9+
"github.com/code-game-project/codegame-cli/util/exec"
910
"github.com/gomarkdown/markdown"
1011
"github.com/gomarkdown/markdown/html"
1112
"github.com/gomarkdown/markdown/parser"
@@ -19,33 +20,26 @@ var docsStyle string
1920

2021
func Docs() error {
2122
if pflag.NArg() == 1 {
22-
cli.Begin("Opening documentation...")
23-
err := util.OpenBrowser("https://docs.code-game.org")
23+
cli.Print("Opening documentation...")
24+
err := exec.OpenBrowser("https://docs.code-game.org")
2425
if err != nil {
2526
cli.Error(err.Error())
2627
}
27-
cli.Finish()
2828
return err
2929
}
3030

31-
cli.Begin("Generating markdown documentation...")
32-
3331
url := baseURL(pflag.Arg(1))
3432

35-
cgeVersion, err := util.GetCGEVersion(url)
33+
cgeVersion, err := cggenevents.GetCGEVersion(url)
3634
if err != nil {
3735
return err
3836
}
3937

40-
err = util.CGGenEvents(os.TempDir(), url, cgeVersion, "markdown")
38+
err = cggenevents.CGGenEvents(os.TempDir(), url, cgeVersion, "markdown")
4139
if err != nil {
4240
return err
4341
}
4442

45-
cli.Finish()
46-
47-
cli.Begin("Converting documentation to HTML...")
48-
4943
md, err := os.ReadFile(filepath.Join(os.TempDir(), "event_docs.md"))
5044
if err != nil {
5145
return cli.Error(err.Error())
@@ -69,16 +63,12 @@ func Docs() error {
6963
return cli.Error(err.Error())
7064
}
7165

72-
cli.Finish()
66+
cli.Print("Opening documentation...")
7367

74-
cli.Begin("Opening documentation...")
75-
76-
err = util.OpenBrowser(filepath.Join(os.TempDir(), "event_docs.html"))
68+
err = exec.OpenBrowser(filepath.Join(os.TempDir(), "event_docs.html"))
7769
if err != nil {
7870
cli.Error(err.Error())
7971
}
8072

81-
cli.Finish()
82-
8373
return nil
8474
}

commands/info.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"strings"
1010
"unicode/utf8"
1111

12-
"github.com/code-game-project/codegame-cli/cli"
13-
"github.com/code-game-project/codegame-cli/util"
12+
"github.com/Bananenpro/cli"
13+
"github.com/code-game-project/codegame-cli/util/external"
1414
"github.com/mattn/go-colorable"
1515
"github.com/ogier/pflag"
1616
)
@@ -45,7 +45,7 @@ func Info() error {
4545

4646
printInfo(info)
4747

48-
cli.Info("\nTo view the documentation of this game run:\n%s docs %s", os.Args[0], url)
48+
cli.PrintColor(cli.Yellow, "\nTo view the documentation of this game run:\n%s docs %s", os.Args[0], url)
4949
return nil
5050
}
5151

@@ -78,7 +78,7 @@ func fetchInfo(url string) (gameInfo, error) {
7878
if err != nil || res.StatusCode != http.StatusOK {
7979
return gameInfo{}, cli.Error("Couldn't access %s.", url)
8080
}
81-
if !util.HasContentType(res.Header, "application/json") {
81+
if !external.HasContentType(res.Header, "application/json") {
8282
return gameInfo{}, cli.Error("%s doesn't return JSON.", url)
8383
}
8484
defer res.Body.Close()

0 commit comments

Comments
 (0)