39 lines
783 B
Go
39 lines
783 B
Go
|
// 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)
|
||
|
|
||
|
}
|
||
|
|
||
|
|