diff --git a/netutils_linux_hardware/cli.py b/netutils_linux_hardware/cli.py index b54b6fb..0cc7cbf 100644 --- a/netutils_linux_hardware/cli.py +++ b/netutils_linux_hardware/cli.py @@ -16,39 +16,44 @@ 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", - 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', - default=FOLDING_NO) - 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', - help='Folds rates details to entire subsystems') - 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)', - default=False) - self.args = parser.parse_args() + self.parser.add_argument('--directory', type=str, help="Specify a data directory or a tarball", + default=default_directory) + 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) + self.parser.add_argument('--device', action='store_const', const=FOLDING_DEVICE, dest='folding', + help='Folds rates details to entire devices') + self.parser.add_argument('--subsystem', action='store_const', const=FOLDING_SUBSYSTEM, dest='folding', + help='Folds rates details to entire subsystems') + self.parser.add_argument('--server', action='store_const', const=FOLDING_SERVER, dest='folding', + help='Folds rates details to entire server') + 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 = 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) diff --git a/setup.py b/setup.py index 2e7983d..1e29dff 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def read(*paths): setuptools.setup( name='netutils-linux', - version='2.7.2', + version='2.7.3', author='Oleg Strizhechenko', author_email='oleg.strizhechenko@gmail.com', license='MIT',