[Pulp-list] CLI Argument Conventions
Jay Dobies
jason.dobies at redhat.com
Fri May 18 20:37:53 UTC 2012
In the v2 CLI we're working for more consistency across the sections.
Part of that is done through the prompt's render_* calls.
I added a module under pulp.gc_client.util called arg_utils. It should
be used when handling user-supplied options to make sure we handle
things consistently across the board. It has three calls so far:
convert_removed_options
Updating metadata, like configuration on a repo, is a pain because we
need to differentiate between the user removing an option and a user not
indicating to change one. The convention has been that specifying "" as
the value (or omitting it entirely) indicates to remove a config option
entirely. For instance: --verify_checksum=""
This call should be run on user-supplied arguments in any CLI update
call to ensure that any None values populated by the CLI framework are
removed (they represent the user not specifying to change a value) and
will convert empty strings to Nones (to indicate the user is explicitly
saying to set the value to none/remove it). It will modify the passed in
dict in place.
convert_boolean_args
This call takes a dict and a list of keys it should parse as
booleans. It will apply the CLI-wide convention for specifying booleans
(that way we're not mixing and matching some true/false, some 1/0) and
update the passed in dict with a boolean instead of a string. An
exception with a user-friendly message in its first arg is raised if the
parsing fails.
convert_file_contents
Similar to the boolean call, it takes a dict and a list of keys in it
that represent files on disk. It reads in the contents of the files and
replaces the filename in the dict with the contents, meant to be used
for small files like certificates and gpg keys. Again, if the file can't
be read it will raise an exception with a standard, already i18n-ified
message.
If you've written a CLI call that was handling any of these cases,
please take a few minutes to update them to these calls instead. I have
one last piece to add for this to have the client exception middleware
handle the possible exceptions raised by these calls and display the
error automatically so the extension writer doesn't have to.
--
Jay Dobies
Freenode: jdob @ #pulp
http://pulpproject.org | http://blog.pulpproject.org
More information about the Pulp-list
mailing list