[nb] Sync
This commit is contained in:
		
							
								
								
									
										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) | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user