Skip to content

Commit

Permalink
Fixed(server-info): human-oriented error in case of no command specif…
Browse files Browse the repository at this point in the history
…ied.

#170
  • Loading branch information
strizhechenko committed Jan 14, 2018
1 parent 5d64088 commit c318616
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions netutils_linux_hardware/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,41 @@ class ServerInfo(object):
subsystems = ('cpu', 'memory', 'net', 'disk', 'system')

def __init__(self):
self.parser = argparse.ArgumentParser()
self.__parse_args()
self.__check_args()
self.main()

def __parse_args(self):
default_directory = '/tmp/netutils_server_info/'
parser = argparse.ArgumentParser()
parser.add_argument('--directory', type=str, help="Specify a data directory or a tarball",
self.parser.add_argument('--directory', type=str, help="Specify a data directory or a tarball",
default=default_directory)
parser.add_argument('--collect', action='store_true', help='Collect the data about the server', default=False)
parser.add_argument('--gzip', action='store_true', help="Compress the data", default=False)
parser.add_argument('--show', action='store_true', help='Shows data about the server in YAML', default=False)
parser.add_argument('--rate', action='store_true', help='Rates data about the server', default=False)
parser.add_argument('-f', '--folding', action='count', help='-f - device, -ff - subsystem, -fff - server',
self.parser.add_argument('--collect', action='store_true', help='Collect the data about the server', default=False)
self.parser.add_argument('--gzip', action='store_true', help="Compress the data", default=False)
self.parser.add_argument('--show', action='store_true', help='Shows data about the server in YAML', default=False)
self.parser.add_argument('--rate', action='store_true', help='Rates data about the server', default=False)
self.parser.add_argument('-f', '--folding', action='count', help='-f - device, -ff - subsystem, -fff - server',
default=FOLDING_NO)
parser.add_argument('--device', action='store_const', const=FOLDING_DEVICE, dest='folding',
self.parser.add_argument('--device', action='store_const', const=FOLDING_DEVICE, dest='folding',
help='Folds rates details to entire devices')
parser.add_argument('--subsystem', action='store_const', const=FOLDING_SUBSYSTEM, dest='folding',
self.parser.add_argument('--subsystem', action='store_const', const=FOLDING_SUBSYSTEM, dest='folding',
help='Folds rates details to entire subsystems')
parser.add_argument('--server', action='store_const', const=FOLDING_SERVER, dest='folding',
self.parser.add_argument('--server', action='store_const', const=FOLDING_SERVER, dest='folding',
help='Folds rates details to entire server')
parser.add_argument('--cpu', action='store_true', help='Show information about CPU', default=False)
parser.add_argument('--memory', action='store_true', help='Show information about RAM', default=False)
parser.add_argument('--net', action='store_true', help='Show information about network devices', default=False)
parser.add_argument('--disk', action='store_true', help='Show information about disks', default=False)
parser.add_argument('--system', action='store_true', help='Show information about system overall (rate only)',
self.parser.add_argument('--cpu', action='store_true', help='Show information about CPU', default=False)
self.parser.add_argument('--memory', action='store_true', help='Show information about RAM', default=False)
self.parser.add_argument('--net', action='store_true', help='Show information about network devices', default=False)
self.parser.add_argument('--disk', action='store_true', help='Show information about disks', default=False)
self.parser.add_argument('--system', action='store_true', help='Show information about system overall (rate only)',
default=False)
self.args = parser.parse_args()
self.args = self.parser.parse_args()

def __check_args(self):
""" Maybe they should be positional arguments, not options. But subparsers/groups are stupid """
assert any([self.args.collect, self.args.rate, self.args.show]), "Specify command: {0}".format(self.commands)

if not any([self.args.collect, self.args.rate, self.args.show]):
print('Error: please, specify --rate, --show or --collect command')
self.parser.print_help()
exit(1)
if not any(getattr(self.args, subsystem) for subsystem in self.subsystems):
for subsystem in self.subsystems:
setattr(self.args, subsystem, True)
Expand Down

0 comments on commit c318616

Please sign in to comment.