Skip to content

Commit 3db465d

Browse files
Update some outdated docs in README (#194)
1 parent dc5a014 commit 3db465d

9 files changed

Lines changed: 16 additions & 11 deletions

File tree

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ To add a subcommand underneath the command you've just created, it's again `cli.
125125

126126
```go
127127
// Best to abstract it into a function
128-
func buildSubcommand(ctx context.Context) (*cli.Command, error) {
128+
func buildSubcommand() (*cli.Command, error) {
129129
return cli.New(
130130
"sub", // Name of the sub command e.g. 'clone' for 'git clone'
131131
cli.Short("A sub command"),
@@ -143,7 +143,7 @@ ctx := context.Background()
143143
cmd, err := cli.New(
144144
"name", // The name of your command
145145
// ...
146-
cli.SubCommands(buildSubcommand(ctx)),
146+
cli.SubCommands(buildSubcommand),
147147
)
148148
```
149149

@@ -167,7 +167,7 @@ func buildCmd() (*cli.Command, error) {
167167
var opts options
168168
return cli.New(
169169
// ...
170-
// Signature is cli.Flag(*T, name, shorthand, default, description)
170+
// Signature is cli.Flag(*T, name, shorthand, description)
171171
cli.Flag(&options.name, "name", 'n', "The name of something"),
172172
cli.Flag(&options.force, "force", cli.NoShortHand, "Force delete without confirmation"),
173173
cli.Flag(&options.size, "size", 's', "Size of something"),
@@ -177,6 +177,9 @@ func buildCmd() (*cli.Command, error) {
177177
}
178178
```
179179

180+
> [!TIP]
181+
> Default values can be provided with the [cli.FlagDefault](https://pkg.go.dev/go.followtheprocess.codes/cli#FlagDefault) Option
182+
180183
The types are all inferred automatically! No more `BoolSliceVarP`
181184

182185
The types you can use for flags currently are:
@@ -232,7 +235,7 @@ cli.New(
232235
)
233236
```
234237

235-
This will return a `[]string` containing all the positional arguments to your command (not flags, they've already been parsed elsewhere!)
238+
This will return a `[]string` containing all the positional arguments to your command (not flags, they've already been parsed out!)
236239

237240
Or, if you want to get smarter 🧠 `cli` allows you to define *type safe* representations of your arguments, with or without default values! This follows a similar
238241
idea to [Flags](#flags)
@@ -294,7 +297,8 @@ The types you can currently use for positional args are:
294297
- `net.IP`
295298

296299
> [!WARNING]
297-
> Slice types are not supported (yet), for those you need to use the `cmd.Args()` method to get the arguments manually. I'm working on this!
300+
> Slice types are not supported (yet), for those you need to use the `cmd.Args()` method to get the arguments manually. I plan to address this but it can be tricky
301+
> as slice types will eat up the remainder of the arguments so I need to figure out a good DevEx for this as it could lead to confusing outcomes
298302
299303
## Core Principles
300304

docs/img/cancel.gif

1.3 KB
Loading

docs/img/demo.png

39.6 KB
Loading

docs/img/namedargs.gif

492 Bytes
Loading

docs/img/quickstart.gif

3.02 KB
Loading

docs/img/subcommands.gif

3.29 KB
Loading

examples/cover/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func main() {
2222
cli.Example("Do a thing", "demo thing --count"),
2323
cli.Flag(&count, "count", 'c', "Count the thing"),
2424
cli.Run(func(ctx context.Context, cmd *cli.Command) error {
25+
// Here ^^^ is the context from below, cli passes it in for you
2526
fmt.Fprintln(cmd.Stdout(), "Hello from demo, my arguments were: ", cmd.Args())
2627
return nil
2728
}),

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ require (
1515

1616
require (
1717
go.yaml.in/yaml/v4 v4.0.0-rc.3 // indirect
18-
golang.org/x/sys v0.38.0 // indirect
19-
golang.org/x/term v0.37.0 // indirect
18+
golang.org/x/sys v0.39.0 // indirect
19+
golang.org/x/term v0.38.0 // indirect
2020
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ go.followtheprocess.codes/test v1.1.0 h1:1v2JyMd3STr7dIXzcHEhct2qvS8/mTtGYbSyhpR
66
go.followtheprocess.codes/test v1.1.0/go.mod h1:BHZi5SZahJw01xcuc7EgrlyzX7zJLXAWy11rOR9geVw=
77
go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go=
88
go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
9-
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
10-
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
11-
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
12-
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
9+
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
10+
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
11+
golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
12+
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
1313
golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
1414
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=

0 commit comments

Comments
 (0)