Skip to content

Commit 160a1e0

Browse files
committed
basic docs for go-cat
1 parent 8dad866 commit 160a1e0

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

cli-files/README.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,23 @@ If you smash through this, here's some fun/tricky extensions:
148148

149149
### go-cat
150150

151-
- make sure GOPATH bin setup is correct: https://sourabhbajaj.com/mac-setup/Go/
152-
- install cobra-cli: https://github.com/spf13/cobra-cli/blob/main/README.md
153-
- make `go-cat` dir, cd in, `go mod init go-cat`
154-
- `cobra-cli init .`
155-
- look at all the files
156-
- `go install . && go-cat`
157-
- set up a command that takes an argument, opens the file and prints it out (`os.ReadFile`, `os.Stdout.Write`)
158-
- handle the error if you pass a directory like cat does
151+
This one we're going to make in a different, so we can see how to use tools to initialise go projects more quickly.
152+
153+
We'll use the [cobra-cli](https://github.com/spf13/cobra-cli/blob/main/README.md) to initialise a new project. There's a guide on that page to installing it, but it's likely `go install github.com/spf13/cobra-cli@latest`.
154+
155+
Then `cd` to the `cli-files` directory.
156+
157+
Make a `go-cat` directory, `cd` into it, and run `go mod init go-cat` ([documentation here](https://pkg.go.dev/cmd/go#hdr-Initialize_new_module_in_current_directory)).
158+
159+
Then run `cobra-cli init .`. [This command](https://github.com/spf13/cobra-cli/blob/main/README.md) will create your initial application code for you.
160+
161+
Take a look at all the files it has created. See how they differ or are similar to what you did in the `go-ls` example.
162+
163+
Let's try it out: `go install . && go-cat`. It will do nothing, but it's a start.
164+
165+
Now it's over to you: set up a command that takes a path to a file as an argument, then opens that file and prints it out. You'll need the built-in go functions `os.ReadFile` and `os.Stdout.Write`, as well as more from the `os` package.
166+
167+
Bonus task: handle the error if you pass it a directory rather than a file, like cat does.
159168

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

0 commit comments

Comments
 (0)