Re: [libvirt] [PATCH 1/3] virt-xml-validate: add --help/--version option

2013-08-19 Thread Eric Blake
On 08/19/2013 04:43 PM, Eric Blake wrote:
 All good tools should have --help and --version output :)
 
 * tools/virt-xml-validate.in: Add option parsing.  Output errors
 to stderr.  Update documentation to match.
 * tools/Makefile.am (virt-xml-validate): Substitute version.
 

 +  --) shift ;;
 +  -*)
 +echo $0: unrecognized option '$1' 2
 +exit 1 ;;
 +esac
 +
  XMLFILE=$1

This treats '-' as an unrecognized option (which is a bit misleading,
since in POSIX terminology a lone - is NOT an option but an argument).
It also raises the question - should we allow for an XMLFILE of '-' to
mean reading from stdin, the way POSIX recommends?  That is, should we
support:

virsh dumpxml $dom | virt-xml-validate -

as a valid mode of execution?  Right now, that won't work (we consume
stdin while probing the type, so that it no longer has contents for the
actual validation pass), so it would need a separate patch to make the
shell script smarter about reusing an input file, which may turn out to
be a fair chunk of work before we get there (and it would probably be me
stuck implementing it...).  And if '-' works to specify stdin, why not
also let this tool operate in filter mode (no arguments implies reading
from stdin, just as an explicit - would).

I guess the fact that I changed '-' to raise an error in this patch is a
minor change for people used to using '-' as the name of a file in the
current directory; but as that is not typical usage, and as they can
work around that by using './-', I don't consider it a regression [but I
_will_ update the commit message to mention that this is an intentional
change in corner-case behavior]

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



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/3] virt-xml-validate: add --help/--version option

2013-08-19 Thread Guan Nan Ren
ACK

- Original Message -
From: Eric Blake ebl...@redhat.com
To: libvir-list@redhat.com
Sent: Monday, August 19, 2013 6:43:13 PM
Subject: [libvirt] [PATCH 1/3] virt-xml-validate: add --help/--version option

All good tools should have --help and --version output :)

* 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 ebl...@redhat.com
---
 tools/Makefile.am  |  5 +++--
 tools/virt-xml-validate.in | 44 +---
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/tools/Makefile.am b/tools/Makefile.am
index f85c35c..03c9fd0 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -77,8 +77,9 @@ dist_man8_MANS = virt-sanlock-cleanup.8
 endif

 virt-xml-validate: virt-xml-validate.in Makefile
-   $(AM_V_GEN)sed -e 's|[@]schemadir@|$(pkgdatadir)/schemas|'  $  $@ \
-   || (rm $@  exit 1)  chmod +x $@
+   $(AM_V_GEN)sed -e 's|[@]schemadir@|$(pkgdatadir)/schemas|g' \
+  -e 's|[@]VERSION@|$(VERSION)|g' \
+  $  $@ || (rm $@  exit 1)  chmod +x $@

 virt-xml-validate.1: virt-xml-validate.in $(top_srcdir)/configure.ac
$(AM_V_GEN)$(POD2MAN) --name VIRT-XML-VALIDATE $ $(srcdir)/$@ \
diff --git a/tools/virt-xml-validate.in b/tools/virt-xml-validate.in
index 9c584ed..9744612 100644
--- a/tools/virt-xml-validate.in
+++ b/tools/virt-xml-validate.in
@@ -17,16 +17,39 @@

 set -e

+case $1 in
+  -h | --h | --he | --hel | --help)
+cat EOF
+Usage:
+  $0 XML-FILE [SCHEMA-NAME]
+  $0 OPTION
+
+Options:
+  -h | --helpDisplay 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
 TYPE=$2

 if [ -z $XMLFILE ]; then
-  echo syntax: $0 XMLFILE [TYPE]
+  echo syntax: $0 XMLFILE [TYPE] 2
   exit 1
 fi

 if [ ! -f $XMLFILE ]; then
-  echo $0: document $XMLFILE does not exist
+  echo $0: document $XMLFILE does not exist 2
   exit 2
 fi

@@ -78,6 +101,7 @@ exit 0
 =head1 SYNOPSIS

   virt-xml-validate XML-FILE [SCHEMA-NAME]
+  virt-xml-validate OPTION

 =head1 DESCRIPTION

@@ -117,6 +141,20 @@ The schema for the XML format used to declare driver 
capabilities

 =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

 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

-Copyright (C) 2009-2012 by Red Hat, Inc.
+Copyright (C) 2009-2013 by Red Hat, Inc.
 Copyright (C) 2009 by Daniel P. Berrange

 =head1 LICENSE
-- 
1.8.3.1

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

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


Re: [libvirt] [PATCH 1/3] virt-xml-validate: add --help/--version option

2013-08-19 Thread Guan Nan Ren


- Original Message -
From: Eric Blake ebl...@redhat.com
Cc: libvir-list@redhat.com
Sent: Monday, August 19, 2013 6:58:56 PM
Subject: Re: [libvirt] [PATCH 1/3] virt-xml-validate: add --help/--version 
option

On 08/19/2013 04:43 PM, Eric Blake wrote:
 All good tools should have --help and --version output :)
 
 * tools/virt-xml-validate.in: Add option parsing.  Output errors
 to stderr.  Update documentation to match.
 * tools/Makefile.am (virt-xml-validate): Substitute version.
 

 +  --) shift ;;
 +  -*)
 +echo $0: unrecognized option '$1' 2
 +exit 1 ;;
 +esac
 +
  XMLFILE=$1

This treats '-' as an unrecognized option (which is a bit misleading,
since in POSIX terminology a lone - is NOT an option but an argument).
It also raises the question - should we allow for an XMLFILE of '-' to
mean reading from stdin, the way POSIX recommends?  That is, should we
support:

virsh dumpxml $dom | virt-xml-validate -


grep use grep -f - to donate the standard input. As written in its manpage
 -f is specified by POSIX. If we use -f, the single hyphen can be used
as a filename. But as you said in the follow, user can prefix the filename
with a path - ./-, or /home/Tim/-, so it is still fine in this case.



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


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

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


Re: [libvirt] [PATCH 1/3] virt-xml-validate: add --help/--version option

2013-08-19 Thread Eric Blake
On 08/19/2013 07:51 PM, Guan Nan Ren wrote:
 This treats '-' as an unrecognized option (which is a bit misleading,
 since in POSIX terminology a lone - is NOT an option but an argument).
 It also raises the question - should we allow for an XMLFILE of '-' to
 mean reading from stdin, the way POSIX recommends?  That is, should we
 support:
 
 virsh dumpxml $dom | virt-xml-validate -
 
 
 grep use grep -f - to donate the standard input. As written in its manpage
  -f is specified by POSIX. If we use -f, the single hyphen can be used
 as a filename. But as you said in the follow, user can prefix the filename
 with a path - ./-, or /home/Tim/-, so it is still fine in this case.

Actually, 'grep -f - file' and 'grep pattern -' are two quite different
uses of '-' meaning stdin (one treats stdin as the file containing the
pattern, the other treats stdin as the file to search).  But yes, the
point is that since POSIX requires '-' to mean stdin when possible,
people are used to that idiom, and used to using ./- when wanting to
refer to a file literally named -.

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



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list