Skip to content

Commit 99b013a

Browse files
committed
lost more readme steps
1 parent fffc1c2 commit 99b013a

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

cli-files/README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,46 @@ A world of struggle.
6464
### Steps (notes)
6565

6666
- create `go-ls` dir
67+
- make sure the working directory is go-ls: `cd go-ls`
6768
- create `go.mod`, `main.go`, `cmd/root.go`
69+
70+
```go
71+
// go.mod
72+
module vinery/cli-files/go-ls
73+
74+
go 1.18
75+
```
76+
77+
```go
78+
// main.go
79+
package main
80+
81+
import (
82+
"vinery/cli-files/go-ls/cmd"
83+
)
84+
85+
func main() {
86+
cmd.Execute()
87+
}
88+
```
89+
90+
```go
91+
// cmd/root.go
92+
package cmd
93+
94+
func Execute() {}
95+
```
96+
6897
- `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
98+
- follow cobra [user guide](https://github.com/spf13/cobra/blob/master/user_guide.md) to make a root command that prints hello in `cmd/root.go`
7099
- implement basic ls with `os.ReadDir`
71100
- allow the command to take arguments with `cobra.ArbitraryArgs`
72101
- when passed an argument such as `go-ls assets`, read from the passed directory
73-
- handle the error (e.g. `Error: fdopendir go.mod: not a directory` when passing `go-ls` a file argument)
102+
- ensure that this directory path can be relative: `go-ls ..` and `go-ls ../go-ls` should both work
103+
- handle the error (e.g. `Error: fdopendir go.mod: not a directory` when passing `go-ls` a file argument: `go-ls go.mod`)
74104
- update `go-ls` to match `ls` in terms of how it handles files (hint: `os.Stat`)
75105
- make `go-ls -h` include a helpful description
106+
- bonus: write some tests for `go-ls`
76107

77108
[go]: https://go.dev/
78109
[cat]: https://en.m.wikipedia.org/wiki/Cat_(Unix)

0 commit comments

Comments
 (0)