Skip to content

Commit

Permalink
feat(cli): use of cli
Browse files Browse the repository at this point in the history
  • Loading branch information
anhgelus committed May 31, 2023
1 parent 7cfac61 commit f06c5c7
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
package main

import (
"github.com/msmp-core/maze-generator-cli/Generators"
"os"
"regexp"
"strconv"
"strings"
)

func main() {
if len(os.Args) == 1 {
help()
return
}
cli := ""
for i, a := range os.Args {
if i == 0 {
continue
}
cli += a + " "
}
widthO := regexp.MustCompile(`-w [0-9]+`)
height0 := regexp.MustCompile(`-h [0-9]+`)
unWidth := widthO.FindString(cli)
unHeight := height0.FindString(cli)
if unHeight == "" || unWidth == "" {
help()
return
}
strWidth := strings.ReplaceAll(unWidth, "-w ", "")
strHeight := strings.ReplaceAll(unHeight, "-h ", "")

w, err := strconv.Atoi(strWidth)
if err != nil {
panic(err)
}
h, err := strconv.Atoi(strHeight)
if err != nil {
panic(err)
}
m, err := Generators.GenerateNewMaze(uint(w), uint(h), Generators.NewRandomisedKruskal)
if err != nil {
panic(err)
}
m.RenderWalls()
}

func help() {
println("------------------------------")
println("HELP OF THE MAZE GENERATOR CLI")
println("------------------------------")
println("-w uint -> Width of the maze")
println("-h uint -> Height of the maze")
}

0 comments on commit f06c5c7

Please sign in to comment.