aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurĂ­cio Antunes <mauricio.abreua@gmail.com>2022-11-03 21:45:06 -0300
committerMaurĂ­cio Antunes <mauricio.abreua@gmail.com>2022-11-03 21:45:06 -0300
commit87af0e880a89b05b0f0e06e31a6ff99065eb14ff (patch)
tree9b36df44b6f9a5ebe7db0b120c16e4b9211e924b
parent01234441088f9e37e37fe2c9ecc6b0b0f943d3ee (diff)
feat: add verify command
-rw-r--r--go.mod9
-rw-r--r--go.sum19
-rw-r--r--golings/cmd/list.go4
-rw-r--r--golings/cmd/verify.go54
-rw-r--r--golings/exercises/verify.go21
-rw-r--r--golings/ui/list.go (renamed from golings/printer/list.go)2
6 files changed, 100 insertions, 9 deletions
diff --git a/go.mod b/go.mod
index bafce0a..b0a4539 100644
--- a/go.mod
+++ b/go.mod
@@ -8,6 +8,7 @@ require (
github.com/onsi/ginkgo/v2 v2.4.0
github.com/onsi/gomega v1.23.0
github.com/pelletier/go-toml/v2 v2.0.5
+ github.com/schollz/progressbar/v3 v3.12.0
github.com/spf13/cobra v1.6.1
)
@@ -16,12 +17,14 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
- github.com/mattn/go-isatty v0.0.14 // indirect
- github.com/mattn/go-runewidth v0.0.13 // indirect
- github.com/rivo/uniseg v0.2.0 // indirect
+ github.com/mattn/go-isatty v0.0.16 // indirect
+ github.com/mattn/go-runewidth v0.0.14 // indirect
+ github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
+ github.com/rivo/uniseg v0.4.2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
+ golang.org/x/term v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
diff --git a/go.sum b/go.sum
index 0c98965..9d0a773 100644
--- a/go.sum
+++ b/go.sum
@@ -13,13 +13,18 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.4.0 h1:YlI/2zYDrweA4MThiYMKtGRfT+2qZOO65ulej8GTcVI=
github.com/jedib0t/go-pretty/v6 v6.4.0/go.mod h1:MgmISkTWDSFu0xOqiZ0mKNntMQ2mDgOcwOkwBEkMDJI=
+github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
-github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
-github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
+github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
+github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
+github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
+github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
+github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
+github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo=
github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=
@@ -29,15 +34,19 @@ github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaF
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
+github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8=
+github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/schollz/progressbar/v3 v3.12.0 h1:BVFNM+V/l20JUYkJ5fO/CnOYPV3Et3tON8FmJepkdq4=
+github.com/schollz/progressbar/v3 v3.12.0/go.mod h1:g7QSuwyGpqCjVQPFZXA31MSxtrhka9Y9LMdF+XT77/Y=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
@@ -47,9 +56,13 @@ golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw=
+golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
diff --git a/golings/cmd/list.go b/golings/cmd/list.go
index c79e0e4..53669c7 100644
--- a/golings/cmd/list.go
+++ b/golings/cmd/list.go
@@ -5,7 +5,7 @@ import (
"github.com/fatih/color"
"github.com/mauricioabreu/golings/golings/exercises"
- "github.com/mauricioabreu/golings/golings/printer"
+ "github.com/mauricioabreu/golings/golings/ui"
"github.com/spf13/cobra"
)
@@ -22,6 +22,6 @@ var cmdList = &cobra.Command{
color.Red(err.Error())
os.Exit(1)
}
- printer.PrintList(os.Stdout, exs)
+ ui.PrintList(os.Stdout, exs)
},
}
diff --git a/golings/cmd/verify.go b/golings/cmd/verify.go
new file mode 100644
index 0000000..c2a8f3a
--- /dev/null
+++ b/golings/cmd/verify.go
@@ -0,0 +1,54 @@
+package cmd
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/fatih/color"
+ "github.com/mauricioabreu/golings/golings/exercises"
+ "github.com/schollz/progressbar/v3"
+ "github.com/spf13/cobra"
+)
+
+func init() {
+ rootCmd.AddCommand(cmdVerify)
+}
+
+var cmdVerify = &cobra.Command{
+ Use: "verify",
+ Short: "Verify all exercises",
+ Run: func(cmd *cobra.Command, args []string) {
+ verified, err := exercises.Verify()
+ if err != nil {
+ color.Red(err.Error())
+ os.Exit(1)
+ }
+
+ bar := progressbar.NewOptions(
+ 3,
+ progressbar.OptionSetWidth(50),
+ progressbar.OptionEnableColorCodes(true),
+ progressbar.OptionSetPredictTime(false),
+ progressbar.OptionSetElapsedTime(false),
+ progressbar.OptionSetDescription("[cyan][reset] Progress:"),
+ progressbar.OptionSetTheme(progressbar.Theme{
+ Saucer: "[yellow]=[reset]",
+ SaucerHead: "[yellow]>[reset]",
+ SaucerPadding: " ",
+ BarStart: "[",
+ BarEnd: "]",
+ }),
+ )
+
+ for v := range verified {
+ bar.Describe(fmt.Sprintf("Running %s", v.Exercise.Name))
+ bar.Add(1)
+ if v.Err != "" {
+ fmt.Print("\n\n")
+ color.Cyan("Failed to compile the exercise %s\n", v.Exercise.Path)
+ color.Red("Check the error: %s", v.Err)
+ break
+ }
+ }
+ },
+}
diff --git a/golings/exercises/verify.go b/golings/exercises/verify.go
new file mode 100644
index 0000000..01997a7
--- /dev/null
+++ b/golings/exercises/verify.go
@@ -0,0 +1,21 @@
+package exercises
+
+// Verify checks if all the exercises compile and pass the tests
+func Verify() (<-chan Result, error) {
+ verified := make(chan Result)
+
+ exs, err := List()
+ if err != nil {
+ return verified, err
+ }
+
+ go func() {
+ for _, ex := range exs {
+ result, _ := Run(ex.Name)
+ verified <- result
+ }
+ close(verified)
+ }()
+
+ return verified, nil
+}
diff --git a/golings/printer/list.go b/golings/ui/list.go
index ac5046a..adb5821 100644
--- a/golings/printer/list.go
+++ b/golings/ui/list.go
@@ -1,4 +1,4 @@
-package printer
+package ui
import (
"io"