diff options
-rw-r--r-- | exercises/variables/variables1.go (renamed from exercises/variables1.go) | 0 | ||||
-rw-r--r-- | go.mod | 4 | ||||
-rw-r--r-- | go.sum | 23 | ||||
-rw-r--r-- | info.toml | 6 | ||||
-rw-r--r-- | src/cmd/list.go | 27 | ||||
-rw-r--r-- | src/exercises/list.go | 45 | ||||
-rw-r--r-- | src/printer/list.go | 18 |
7 files changed, 123 insertions, 0 deletions
diff --git a/exercises/variables1.go b/exercises/variables/variables1.go index 50be731..50be731 100644 --- a/exercises/variables1.go +++ b/exercises/variables/variables1.go @@ -4,6 +4,8 @@ go 1.19 require ( github.com/fatih/color v1.13.0 + github.com/jedib0t/go-pretty/v6 v6.4.0 + github.com/pelletier/go-toml/v2 v2.0.5 github.com/spf13/cobra v1.6.1 ) @@ -11,6 +13,8 @@ require ( 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/spf13/pflag v1.0.5 // indirect golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect ) @@ -1,21 +1,44 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= 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/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-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= +github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= +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/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 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.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= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +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-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/info.toml b/info.toml new file mode 100644 index 0000000..c1956e4 --- /dev/null +++ b/info.toml @@ -0,0 +1,6 @@ +[[exercises]] +name = "variables1" +path = "exercises/variables/variables1.rs" +mode = "compile" +hint = """ +It is missing a symbol used to initialize values.""" diff --git a/src/cmd/list.go b/src/cmd/list.go new file mode 100644 index 0000000..103ea21 --- /dev/null +++ b/src/cmd/list.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "os" + + "github.com/fatih/color" + "github.com/mauricioabreu/golings/src/exercises" + "github.com/mauricioabreu/golings/src/printer" + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(cmdList) +} + +var cmdList = &cobra.Command{ + Use: "list", + Short: "List all exercises", + Run: func(cmd *cobra.Command, args []string) { + exs, err := exercises.List() + if err != nil { + color.Red(err.Error()) + os.Exit(1) + } + printer.PrintList(os.Stdout, exs) + }, +} diff --git a/src/exercises/list.go b/src/exercises/list.go new file mode 100644 index 0000000..3719527 --- /dev/null +++ b/src/exercises/list.go @@ -0,0 +1,45 @@ +package exercises + +import ( + "os" + + "github.com/pelletier/go-toml/v2" +) + +type State int + +const ( + Pending State = iota + 1 + Done +) + +func (s State) String() string { + return [...]string{"Pending", "Done"}[s-1] +} + +type Exercise struct { + Name string + Path string + Mode string + Hint string + State State +} + +type Info struct { + Exercises []Exercise +} + +func List() ([]Exercise, error) { + var info Info + + data, err := os.ReadFile("info.toml") + if err != nil { + return info.Exercises, err + } + + if err := toml.Unmarshal(data, &info); err != nil { + return info.Exercises, err + } + + return info.Exercises, nil +} diff --git a/src/printer/list.go b/src/printer/list.go new file mode 100644 index 0000000..bd65513 --- /dev/null +++ b/src/printer/list.go @@ -0,0 +1,18 @@ +package printer + +import ( + "io" + + "github.com/jedib0t/go-pretty/v6/table" + "github.com/mauricioabreu/golings/src/exercises" +) + +func PrintList(o io.Writer, exs []exercises.Exercise) { + t := table.NewWriter() + t.SetOutputMirror(o) + t.AppendHeader(table.Row{"Name", "Path"}) + for _, ex := range exs { + t.AppendRow(table.Row{ex.Name, ex.Path}) + } + t.Render() +} |