virt-xml-validate: add --help/--version option
All good tools should have --help and --version output :) Furthermore, we want to ensure a failed exit if xmllint fails, or even for 'virt-xml-validate > /dev/full'. * tools/virt-xml-validate.in: Add option parsing. Output errors to stderr. Update documentation to match. * tools/Makefile.am (virt-xml-validate): Substitute version. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
0192fd6711
commit
b2ea248ef7
@ -77,8 +77,9 @@ dist_man8_MANS = virt-sanlock-cleanup.8
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
virt-xml-validate: virt-xml-validate.in Makefile
|
virt-xml-validate: virt-xml-validate.in Makefile
|
||||||
$(AM_V_GEN)sed -e 's|[@]schemadir@|$(pkgdatadir)/schemas|' < $< > $@ \
|
$(AM_V_GEN)sed -e 's|[@]schemadir@|$(pkgdatadir)/schemas|g' \
|
||||||
|| (rm $@ && exit 1) && chmod +x $@
|
-e 's|[@]VERSION@|$(VERSION)|g' \
|
||||||
|
< $< > $@ || (rm $@ && exit 1) && chmod +x $@
|
||||||
|
|
||||||
virt-xml-validate.1: virt-xml-validate.in $(top_srcdir)/configure.ac
|
virt-xml-validate.1: virt-xml-validate.in $(top_srcdir)/configure.ac
|
||||||
$(AM_V_GEN)$(POD2MAN) --name VIRT-XML-VALIDATE $< $(srcdir)/$@ \
|
$(AM_V_GEN)$(POD2MAN) --name VIRT-XML-VALIDATE $< $(srcdir)/$@ \
|
||||||
|
@ -17,16 +17,39 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
-h | --h | --he | --hel | --help)
|
||||||
|
cat <<EOF
|
||||||
|
Usage:
|
||||||
|
$0 XML-FILE [SCHEMA-NAME]
|
||||||
|
$0 OPTION
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h | --help Display program help
|
||||||
|
-V | --version Display program version
|
||||||
|
EOF
|
||||||
|
exit ;;
|
||||||
|
-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
|
||||||
|
cat <<EOF
|
||||||
|
$0 (libvirt) @VERSION@
|
||||||
|
EOF
|
||||||
|
exit ;;
|
||||||
|
--) shift ;;
|
||||||
|
-*)
|
||||||
|
echo "$0: unrecognized option '$1'" >&2
|
||||||
|
exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
XMLFILE="$1"
|
XMLFILE="$1"
|
||||||
TYPE="$2"
|
TYPE="$2"
|
||||||
|
|
||||||
if [ -z "$XMLFILE" ]; then
|
if [ -z "$XMLFILE" ]; then
|
||||||
echo "syntax: $0 XMLFILE [TYPE]"
|
echo "syntax: $0 XMLFILE [TYPE]" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "$XMLFILE" ]; then
|
if [ ! -f "$XMLFILE" ]; then
|
||||||
echo "$0: document $XMLFILE does not exist"
|
echo "$0: document $XMLFILE does not exist" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -52,7 +75,7 @@ if [ -z "$TYPE" ]; then
|
|||||||
TYPE="nodedev"
|
TYPE="nodedev"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "$0: cannot determine schema type for $XMLFILE"
|
echo "$0: cannot determine schema type for $XMLFILE" >&2
|
||||||
exit 3
|
exit 3
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
@ -60,13 +83,13 @@ fi
|
|||||||
SCHEMA="@schemadir@/${TYPE}.rng"
|
SCHEMA="@schemadir@/${TYPE}.rng"
|
||||||
|
|
||||||
if [ ! -f "$SCHEMA" ]; then
|
if [ ! -f "$SCHEMA" ]; then
|
||||||
echo "$0: schema $SCHEMA does not exist"
|
echo "$0: schema $SCHEMA does not exist" >&2
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
|
xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
|
||||||
|
|
||||||
exit 0
|
exit
|
||||||
|
|
||||||
: <<=cut
|
: <<=cut
|
||||||
=pod
|
=pod
|
||||||
@ -78,6 +101,7 @@ exit 0
|
|||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
virt-xml-validate XML-FILE [SCHEMA-NAME]
|
virt-xml-validate XML-FILE [SCHEMA-NAME]
|
||||||
|
virt-xml-validate OPTION
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
@ -117,6 +141,20 @@ The schema for the XML format used to declare driver capabilities
|
|||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
=head1 OPTIONS
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item B<-h, --help>
|
||||||
|
|
||||||
|
Display command line help usage then exit.
|
||||||
|
|
||||||
|
=item B<-V, --version>
|
||||||
|
|
||||||
|
Display version information then exit.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
=head1 EXIT STATUS
|
=head1 EXIT STATUS
|
||||||
|
|
||||||
Upon successful validation, an exit status of 0 will be set. Upon
|
Upon successful validation, an exit status of 0 will be set. Upon
|
||||||
@ -134,7 +172,7 @@ Alternatively report bugs to your software distributor / vendor.
|
|||||||
|
|
||||||
=head1 COPYRIGHT
|
=head1 COPYRIGHT
|
||||||
|
|
||||||
Copyright (C) 2009-2012 by Red Hat, Inc.
|
Copyright (C) 2009-2013 by Red Hat, Inc.
|
||||||
Copyright (C) 2009 by Daniel P. Berrange
|
Copyright (C) 2009 by Daniel P. Berrange
|
||||||
|
|
||||||
=head1 LICENSE
|
=head1 LICENSE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user