Browse Source

display usage when no argument is parsed

Nicolo' Palazzini 5 years ago
parent
commit
224f37f2d1
2 changed files with 13 additions and 8 deletions
  1. 2 2
      README.md
  2. 11 6
      xfreerdpctl

+ 2 - 2
README.md

@@ -1,7 +1,7 @@
 # xfreerdpctl
 Simple tool to handle xfreerdp on LCM nodes.
 
-usage: xfreerdpctl [{status,start,stop,doctor}] [options]
+usage: xfreerdpctl [{status,start,stop}] [--options]
 
 positional arguments:
 
@@ -23,4 +23,4 @@ optional arguments:
   
   -2, --lcm2           LCM2 nodes are considered
   
-  -v, --version        Print program version
+  -v, --version        Print program version

+ 11 - 6
xfreerdpctl

@@ -1,20 +1,18 @@
 #!/usr/bin/python
 
-##Forkato da labcalcoloctl di Elisa Aliverti
 ##Autore: Nicolo' Palazzini
-##Ultima modifica: 2/05/2019
+##Liberamente ispirato a labcalcoloctl di Elisa Aliverti (all rights reserved)
+##Ultima modifica: Maggio 2019
 
 from time import time
 start = time()
 import argparse
-#import textwrap
 import os
 import subprocess, sys
 from threading import Thread
-#from getpass import getpass
 
 choices = ('status','start','stop')
-parser = argparse.ArgumentParser(description='Simple tool to handle xfreerdp on LCM nodes.', usage='xfreerdpctl {'+','.join(choices)+'} [options]')
+parser = argparse.ArgumentParser(description='Simple tool to handle xfreerdp on LCM nodes.', usage=sys.argv[0]+' {'+','.join(choices)+'} [--options]')
 
 ## positional arguments
 parser.add_argument( 'cmd', nargs="?", choices=choices, default='status', help='Specify command to execute, default is \'status\'' )
@@ -24,7 +22,7 @@ parser.add_argument( '-a', '--all', action='store_true', dest='lcm', help='All L
 parser.add_argument( '-n', nargs='+', dest='node', help='Select one or more nodes (at least one)' )
 parser.add_argument( '-1', '--lcm1', action='store_true', dest='lcm1', help='LCM1 nodes are considered' )
 parser.add_argument( '-2', '--lcm2', action='store_true', dest='lcm2', help='LCM2 nodes are considered' )
-parser.add_argument( '-v', '--version', action='version', version='%(prog)s 1.0', help='Print program version' )
+parser.add_argument( '-v', '--version', action='version', version='%(prog)s 1.1', help='Print program version' )
 
 args = parser.parse_args()
 
@@ -141,6 +139,13 @@ Hosts = [
 
 nodes = []
 
+# Show usage if no arguments
+if len(sys.argv) < 2:
+	parser.print_usage()
+	print "\nSimple tool to handle xfreerdp on LCM nodes."
+	print '\nTry: "'+sys.argv[0]+' --help" to display help message.'
+	sys.exit(1)
+
 # Filter hostlist according to arguments
 if args.lcm:
     nodes  = Hosts