diff --git a/README.md b/README.md index 2a544d1..1188e95 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ To add a subcommand underneath the command you've just created, it's again `cli. ```go // Best to abstract it into a function -func buildSubcommand(ctx context.Context) (*cli.Command, error) { +func buildSubcommand() (*cli.Command, error) { return cli.New( "sub", // Name of the sub command e.g. 'clone' for 'git clone' cli.Short("A sub command"), @@ -143,7 +143,7 @@ ctx := context.Background() cmd, err := cli.New( "name", // The name of your command // ... - cli.SubCommands(buildSubcommand(ctx)), + cli.SubCommands(buildSubcommand), ) ``` @@ -167,7 +167,7 @@ func buildCmd() (*cli.Command, error) { var opts options return cli.New( // ... - // Signature is cli.Flag(*T, name, shorthand, default, description) + // Signature is cli.Flag(*T, name, shorthand, description) cli.Flag(&options.name, "name", 'n', "The name of something"), cli.Flag(&options.force, "force", cli.NoShortHand, "Force delete without confirmation"), cli.Flag(&options.size, "size", 's', "Size of something"), @@ -177,6 +177,9 @@ func buildCmd() (*cli.Command, error) { } ``` +> [!TIP] +> Default values can be provided with the [cli.FlagDefault](https://pkg.go.dev/go.followtheprocess.codes/cli#FlagDefault) Option + The types are all inferred automatically! No more `BoolSliceVarP` ✨ The types you can use for flags currently are: @@ -232,7 +235,7 @@ cli.New( ) ``` -This will return a `[]string` containing all the positional arguments to your command (not flags, they've already been parsed elsewhere!) +This will return a `[]string` containing all the positional arguments to your command (not flags, they've already been parsed out!) 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 idea to [Flags](#flags) @@ -294,7 +297,8 @@ The types you can currently use for positional args are: - `net.IP` > [!WARNING] -> 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! +> 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 +> 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 ## Core Principles diff --git a/docs/img/cancel.gif b/docs/img/cancel.gif index 15888a3..ed687f5 100644 Binary files a/docs/img/cancel.gif and b/docs/img/cancel.gif differ diff --git a/docs/img/demo.png b/docs/img/demo.png index 9c5acc3..c1ade62 100644 Binary files a/docs/img/demo.png and b/docs/img/demo.png differ diff --git a/docs/img/namedargs.gif b/docs/img/namedargs.gif index 3c1427b..39821f6 100644 Binary files a/docs/img/namedargs.gif and b/docs/img/namedargs.gif differ diff --git a/docs/img/quickstart.gif b/docs/img/quickstart.gif index 7500d80..1a5a100 100644 Binary files a/docs/img/quickstart.gif and b/docs/img/quickstart.gif differ diff --git a/docs/img/subcommands.gif b/docs/img/subcommands.gif index 6a2625a..cab5033 100644 Binary files a/docs/img/subcommands.gif and b/docs/img/subcommands.gif differ diff --git a/examples/cover/main.go b/examples/cover/main.go index 5cc7912..22d49e1 100644 --- a/examples/cover/main.go +++ b/examples/cover/main.go @@ -22,6 +22,7 @@ func main() { cli.Example("Do a thing", "demo thing --count"), cli.Flag(&count, "count", 'c', "Count the thing"), cli.Run(func(ctx context.Context, cmd *cli.Command) error { + // Here ^^^ is the context from below, cli passes it in for you fmt.Fprintln(cmd.Stdout(), "Hello from demo, my arguments were: ", cmd.Args()) return nil }), diff --git a/go.mod b/go.mod index 54cf80f..62fa18c 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,6 @@ require ( require ( go.yaml.in/yaml/v4 v4.0.0-rc.3 // indirect - golang.org/x/sys v0.38.0 // indirect - golang.org/x/term v0.37.0 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/term v0.38.0 // indirect ) diff --git a/go.sum b/go.sum index 6311f50..5d69996 100644 --- a/go.sum +++ b/go.sum @@ -6,9 +6,9 @@ go.followtheprocess.codes/test v1.1.0 h1:1v2JyMd3STr7dIXzcHEhct2qvS8/mTtGYbSyhpR go.followtheprocess.codes/test v1.1.0/go.mod h1:BHZi5SZahJw01xcuc7EgrlyzX7zJLXAWy11rOR9geVw= go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go= go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= -golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= -golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU= -golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q= +golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg= golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ= golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=