anchore-cli
anchore-cli copied to clipboard
Consistent help behavior
Fixes #128 Fixes #26
This moves execution of the parent/group functions over any given sub-command into callbacks to be executed by the specifically-called subcommand. This has the effect of making any code in the parent/group function lazily executed. This allows --help to be called on any given command, even if the system is not up or cannot otherwise be connected to. This was not possible without this change because the parent/group commands typically have auth code that would be executed and, in cases where it failed, block the execution of the downstream subcommand with the --help flag.
To illustrate this, consider the commands anchore-cli image -h
and anchore-cli image list -h
. These commands should display the help text for image
and list
(the latter being a subcommand under the image
group), even if the cli is not able to connect to a configured anchore instance. Without this change the former command works as expected, but the second complains that it is unable to connect to anchore, even though the intent is just to display locally-stored help text. The reason for this is that it evaluates each part of the command in order, before moving to the next. So for anchore-cli image list -h
, the cli tries to run the auth code in image
to make sure the cli can access the configured anchore instance.
This change modifies the flow of execution so that (in this example) image
returns a callback to evaluate the auth of the user, to be executed by 'list'. This means that anchore-cli image list
will still execute as expected, and anchore-cli image list -h
will skip the auth step because the -h
flag preempts the normal execution of the code associated with list
and jsut return the help text.
This is a WIP and still needs more testing before it can be merged.