Closed marco-m closed 2 years ago
we could add another function field to ffcli.Command, let's call it Parse . . .
I don't think I want ffcli to understand user-supplied code in any more granularity than the current definition of the Exec func. Also, the Command struct is already far too large.
Your idea to
. . . distinguish parse errors from other runtime errors via custom error types
is absolutely the right way to go 👍
Fair enough. Thanks.
Hello @peterbourgon,
Imagine a program that wants to use both
Command.Parse
andCommand.Run
, in order to distinguish the status code:This doesn't really work, because almost all subcommands do additional custom validation of the CLI arguments, and so we end up exiting 1 also for CLI parse errors. The alternatives I can imagine are:
On the other hand, we could add another function field to ffcli.Command, let's call it
Parse
. If non nil, Parse of the root command would call it.As an example, consider the
repeat
subcommand oftextctl
: https://github.com/peterbourgon/ff/blob/f5646899b17b9f61b7725a5191606484f56770f3/ffcli/examples/textctl/textctl.go#L30-L41It could be split in two parts:
If the function used by Parse was a method instead of an anonymous function (like the more complex example
objectctl
), it could also store state if needed.