Skip to content

Commit 224ec2e

Browse files
authored
Replace shell scripts with a Go based CLI (spring1843#119)
1 parent 70ab652 commit 224ec2e

12 files changed

+143
-58
lines changed

.github/cmd/cmd/count_problems.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"path/filepath"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var countRehearsalsCommand = &cobra.Command{
13+
Use: "count-rehearsals",
14+
Short: "Counts the number of rehearsals",
15+
Long: "Iteratively counts the number of rehearsals for each section.",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
dir, err := os.Getwd()
18+
if err != nil {
19+
log.Fatalf("Error finding current directory: %s", err)
20+
}
21+
22+
count := 0
23+
for _, section := range sections {
24+
matches, err := filepath.Glob(filepath.Join(dir, section, "*_test.go"))
25+
if err != nil {
26+
log.Fatalf("Error while globbing: %s", err)
27+
}
28+
count += len(matches)
29+
}
30+
fmt.Println(count)
31+
},
32+
}

.github/cmd/cmd/export_md.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"path/filepath"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var exportMDCommand = &cobra.Command{
13+
Use: "export-md",
14+
Short: "Joins the entire project into one output",
15+
Long: "Iteratively finds every README.md and outputs them",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
dir, err := os.Getwd()
18+
if err != nil {
19+
log.Fatalf("Error finding current directory: %s", err)
20+
}
21+
22+
allFiles := []string{
23+
"README.md",
24+
"preface.md",
25+
"complexity.md",
26+
}
27+
for _, section := range sections {
28+
allFiles = append(allFiles, filepath.Join(section, "README.md"))
29+
}
30+
31+
for _, file := range allFiles {
32+
content, err := os.ReadFile(filepath.Join(dir, file))
33+
if err != nil {
34+
log.Fatalf("Error reading file: %s", err)
35+
}
36+
fmt.Println(string(content))
37+
}
38+
},
39+
}

.github/cmd/cmd/root.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var rootCmd = &cobra.Command{
10+
Use: "cmd",
11+
Short: "Utility to work with go-dsa",
12+
Long: `This is a CLI tool that is made to work with go-dsa.`,
13+
}
14+
15+
// Execute adds all child commands to the root command and sets flags appropriately.
16+
func Execute() {
17+
rootCmd.AddCommand(countRehearsalsCommand)
18+
rootCmd.AddCommand(exportMDCommand)
19+
20+
if err := rootCmd.Execute(); err != nil {
21+
os.Exit(1)
22+
}
23+
rootCmd.AddCommand()
24+
}

.github/cmd/cmd/sections.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cmd
2+
3+
var sections = []string{
4+
"array",
5+
"strings",
6+
"linkedlist",
7+
"stack",
8+
"queue",
9+
"hashtable",
10+
"tree",
11+
"heap",
12+
"recursion",
13+
"dnc",
14+
"bit",
15+
"backtracking",
16+
"graph",
17+
"greedy",
18+
"dp",
19+
}

.github/cmd/main.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/spring1843/go-dsa/.github/cmd/cmd"
4+
5+
func main() {
6+
cmd.Execute()
7+
}

.github/linters/.golangci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ issues:
3232
- wsl
3333
- dupl
3434
- dupword
35-
3635
linters:
3736
enable-all: true
3837
enable:
3938
- revive
4039
- misspell
40+
41+
linters-settings:
42+
forbidigo:
43+
forbid:
44+
- 'ioutil\.*'

.github/scripts/count-rehearsals.sh

-15
This file was deleted.

.github/scripts/export-md.sh

-19
This file was deleted.

.github/scripts/sections.sh

-22
This file was deleted.

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Welcome to **Data Structures and Algorithms in Go**! 🎉 This project is design
1212
* Executable and comes with 100% test coverage, ensuring correctness and quality
1313
* Completely free, community-editable, and continuously evolving
1414
* Ability to study and practice in your favorite IDE, editor, or web browser
15-
* Pure Go, no third-party libraries, Guaranteed forward compatibility
1615

1716
## 📚 Table of Contents
1817

go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
module github.com/spring1843/go-dsa
22

33
go 1.20
4+
5+
require github.com/spf13/cobra v1.7.0
6+
7+
require (
8+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9+
github.com/spf13/pflag v1.0.5 // indirect
10+
)

go.sum

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
2+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5+
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
6+
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
7+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
8+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)