Re: [PATCH 1/8] virsh: Introduce macros to reject mutually exclusive arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/07/2013 05:53 AM, Peter Krempa wrote:
> This patch adds three macros to the virsh source tree that help to
> easily check for mutually exclusive parameters.
> 
> VSH_EXCLUSIVE_OPTIONS_EXPR has four arguments, two expressions to check
> and two names of the parameters to print in the message.
> 
> VSH_EXCLUSIVE_OPTIONS is more specific and check the command structure
> for the parameters using vshCommandOptBool.
> 
> VSH_EXCLUSIVE_OPTIONS_VAR is meant to check boolean variables with the
> same name as the parameters.
> ---
>  po/POTFILES.in |  1 +
>  tools/virsh.h  | 42 ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
> 

> +++ b/tools/virsh.h
> @@ -375,4 +375,46 @@ char *_vshStrdup(vshControl *ctl, const char *s, const char *filename,
>  # define realloc use_vshRealloc_instead_of_realloc
>  # define strdup use_vshStrdup_instead_of_strdup
> 
> +/* Macros to help dealing with mutually exclusive options. */
> +
> +/* VSH_EXCLUSIVE_OPTIONS_EXPR:
> + *
> + * @NAME1: String containing the name of the option.
> + * @EXPR1: Expression to validate the variable (boolean variable)
> + * @NAME2: String containing the name of the option.
> + * @EXPR2: Expression to validate the variable (boolean variable)
> + *
> + * Reject mutually exclusive command options in virsh. Use the
> + * provided expression to check the variables.
> + */
> +# define VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, EXPR1, NAME2, EXPR2)             \
> +    if ((EXPR1) && (EXPR2)) {                                               \
> +        vshError(ctl, _("Options --%s and --%s are mutually exclusive"),    \
> +                 NAME1, NAME2);                                             \
> +        return false;                                                       \

This does an early return, and therefore the macro must be used before
anything that needs cleanup.

At any rate, these look sane to me.  ACK if you add a sentence along
those lines.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]