[nb] Sync

This commit is contained in:
Aerex 2022-02-20 21:55:27 -06:00
parent f9c2c88398
commit 3551467ef9
17 changed files with 38 additions and 0 deletions

38
cmd/leetcode/main.go Normal file
View File

@ -0,0 +1,38 @@
// package is like namespace. Every file has one
package main
// HINT: To import just file you can the format import "<package-name">
import (
"github.com/spf13/cobra"
"io/ioutil"
"log"
"fmt"
)
// Like in C/C++/Java there is a main function
func main() {
var listExer = &cobra.Command {
Use: "leetcode",
Short: "list all exercises",
Long: "leetcode ls",
Run: func(cmd *cobra.Command, args []string) {
leet_code_dir := "/home/aerex/.nb/leetcode/exercises"
files, err := ioutil.ReadDir(leet_code_dir)
if err != nil {
log.Fatal(err)
}
for _, file := range files {
fmt.Println(file.Name())
}
},
}
var rootCmd = &cobra.Command{
Use: "leetcode <command>",
}
rootCmd.AddCommand(listExer)
}