File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -63,9 +63,11 @@ A world of struggle.
63
63
64
64
### Steps (notes)
65
65
66
- - Setup cobra with https://github.com/spf13/cobra/blob/master/user_guide.md
67
- - install in cli-files ` go get -u github.com/spf13/cobra@latest `
68
- - ` cmd ` directory, ` root.go `
66
+ - create ` go-ls ` dir
67
+ - create ` go.mod ` , ` main.go ` , ` cmd/root.go `
68
+ - ` go get -u github.com/spf13/cobra@latest `
69
+ - follow [ user guide] ( https://github.com/spf13/cobra/blob/master/user_guide.md ) to ` main.go ` and ` root.go ` with a root command that prints hello
70
+ - implement basic ls with ` os.ReadDir `
69
71
70
72
[ go ] : https://go.dev/
71
73
[ cat ] : https://en.m.wikipedia.org/wiki/Cat_(Unix)
Original file line number Diff line number Diff line change @@ -10,8 +10,15 @@ import (
10
10
var rootCmd = & cobra.Command {
11
11
Use : "go-ls" ,
12
12
Short : "go-ls is a re-implementation of the ls command" ,
13
- Run : func (cmd * cobra.Command , args []string ) {
14
- fmt .Println ("Hello, world!" )
13
+ RunE : func (cmd * cobra.Command , args []string ) error {
14
+ files , err := os .ReadDir ("." )
15
+ if err != nil {
16
+ return err
17
+ }
18
+ for _ , file := range files {
19
+ fmt .Println (file .Name ())
20
+ }
21
+ return nil
15
22
},
16
23
}
17
24
You can’t perform that action at this time.
0 commit comments