Skip to content

Commit

Permalink
Adjusts flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mvrpl committed Aug 1, 2023
1 parent 136bee8 commit d1b7215
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ require (
github.com/goodsign/monday v1.0.1
github.com/showwin/speedtest-go v1.6.3
github.com/syndtr/goleveldb v1.0.0
github.com/urfave/cli/v2 v2.25.7
github.com/wcharczuk/go-chart v2.0.1+incompatible
golang.org/x/text v0.11.0
)

require (
github.com/blend/go-sdk v1.20220411.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/image v0.9.0 // indirect
)
42 changes: 38 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package main

import (
"encoding/json"
"strings"
"errors"
"os"
"time"

"github.com/goodsign/monday"
"github.com/showwin/speedtest-go/speedtest"
"github.com/syndtr/goleveldb/leveldb"
"github.com/urfave/cli/v2"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func main() {
func RunSpeedTest() {
var speedtestClient = speedtest.New()

user, _ := speedtestClient.FetchUserInfo()
Expand Down Expand Up @@ -52,8 +56,38 @@ func main() {
if err != nil {
panic(err)
}
}

func main() {
app := cli.NewApp()
app.Name = "SpeedTest"

app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "test",
Value: false,
},
&cli.BoolFlag{
Name: "report",
Value: false,
},
}

db.Close()
app.Action = func(c *cli.Context) error {
if c.IsSet("test") && c.IsSet("report") {
panic(errors.New("not valid two flags"))
}

if c.Bool("test") {
RunSpeedTest()
} else if c.Bool("report") {
caser := cases.Title(language.BrazilianPortuguese)
GenReport(caser.String(monday.Format(time.Now(), "January/2006", monday.LocalePtBR)))
} else {
panic(errors.New("need one flag"))
}
return nil
}

GenReport(strings.Title(monday.Format(time.Now(), "January/2006", monday.LocalePtBR)))
app.Run(os.Args)
}

0 comments on commit d1b7215

Please sign in to comment.