[nb] Sync
This commit is contained in:
parent
f9c2c88398
commit
3551467ef9
38
cmd/leetcode/main.go
Normal file
38
cmd/leetcode/main.go
Normal 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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user