Skip to content

Commit 7fe6ed2

Browse files
committed
add basic instructions to go-ls
1 parent 20e9e35 commit 7fe6ed2

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

cli-files/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,49 @@ And within every dewdrop
6161
A world of struggle.
6262
```
6363

64+
### Steps (notes)
65+
66+
- make sure the working directory is go-ls: `cd go-ls`
67+
- create `go.mod`, `main.go`, `cmd/root.go`
68+
69+
```go
70+
// go.mod
71+
module vinery/cli-files/go-ls
72+
73+
go 1.18
74+
```
75+
76+
```go
77+
// main.go
78+
package main
79+
80+
import (
81+
"vinery/cli-files/go-ls/cmd"
82+
)
83+
84+
func main() {
85+
cmd.Execute()
86+
}
87+
```
88+
89+
```go
90+
// cmd/root.go
91+
package cmd
92+
93+
func Execute() {}
94+
```
95+
96+
- `go get -u github.com/spf13/cobra@latest`
97+
- 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`
98+
- implement basic ls with `os.ReadDir`
99+
- allow the command to take arguments with `cobra.ArbitraryArgs`
100+
- when passed an argument such as `go-ls assets`, read from the passed directory
101+
- ensure that this directory path can be relative: `go-ls ..` and `go-ls ../go-ls` should both work
102+
- handle the error (e.g. `Error: fdopendir go.mod: not a directory` when passing `go-ls` a file argument: `go-ls go.mod`)
103+
- update `go-ls` to match `ls` in terms of how it handles files (hint: `os.Stat`)
104+
- make `go-ls -h` include a helpful description
105+
- bonus: write some tests for `go-ls`
106+
64107
[go]: https://go.dev/
65108
[cat]: https://en.m.wikipedia.org/wiki/Cat_(Unix)
66109
[ls]: https://en.m.wikipedia.org/wiki/Ls

0 commit comments

Comments
 (0)