| Conditions | 1 |
| Total Lines | 80 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # Copyright (C) 2019 Greenbone Networks GmbH |
||
| 44 | def __init__(self, description): |
||
| 45 | """ Create a command-line arguments parser for OSPD. """ |
||
| 46 | self._name = description |
||
| 47 | parser = argparse.ArgumentParser(description=description) |
||
| 48 | |||
| 49 | parser.add_argument( |
||
| 50 | '--version', action='store_true', help='Print version then exit.' |
||
| 51 | ) |
||
| 52 | |||
| 53 | parser.add_argument( |
||
| 54 | '-s', |
||
| 55 | '--config', |
||
| 56 | nargs='?', |
||
| 57 | default=DEFAULT_CONFIG_PATH, |
||
| 58 | help='Configuration file path (default: %(default)s)', |
||
| 59 | ) |
||
| 60 | |||
| 61 | parser.add_argument( |
||
| 62 | '-p', |
||
| 63 | '--port', |
||
| 64 | default=DEFAULT_PORT, |
||
| 65 | type=self.network_port, |
||
| 66 | help='TCP Port to listen on. Default: %(default)s', |
||
| 67 | ) |
||
| 68 | parser.add_argument( |
||
| 69 | '-b', |
||
| 70 | '--bind-address', |
||
| 71 | default=DEFAULT_ADDRESS, |
||
| 72 | dest='address', |
||
| 73 | help='Address to listen on. Default: %(default)s', |
||
| 74 | ) |
||
| 75 | parser.add_argument( |
||
| 76 | '-u', |
||
| 77 | '--unix-socket', |
||
| 78 | default=DEFAULT_UNIX_SOCKET_PATH, |
||
| 79 | help='Unix file socket to listen on.' |
||
| 80 | ) |
||
| 81 | parser.add_argument( |
||
| 82 | '-k', |
||
| 83 | '--key-file', |
||
| 84 | default=DEFAULT_KEY_FILE, |
||
| 85 | help='Server key file. Default: {0}'.format(DEFAULT_KEY_FILE), |
||
| 86 | ) |
||
| 87 | parser.add_argument( |
||
| 88 | '-c', |
||
| 89 | '--cert-file', |
||
| 90 | default=DEFAULT_CERT_FILE, |
||
| 91 | help='Server cert file. Default: %(default)s', |
||
| 92 | ) |
||
| 93 | parser.add_argument( |
||
| 94 | '--ca-file', |
||
| 95 | help='CA cert file. Default: %(default)s', |
||
| 96 | default=DEFAULT_CA_FILE, |
||
| 97 | ) |
||
| 98 | parser.add_argument( |
||
| 99 | '-L', |
||
| 100 | '--log-level', |
||
| 101 | default='WARNING', |
||
| 102 | type=self.log_level, |
||
| 103 | help='Wished level of logging. Default: %(default)s', |
||
| 104 | ) |
||
| 105 | parser.add_argument( |
||
| 106 | '-f', |
||
| 107 | '--foreground', |
||
| 108 | action='store_true', |
||
| 109 | help='Run in foreground and logs all messages to console.', |
||
| 110 | ) |
||
| 111 | parser.add_argument( |
||
| 112 | '-l', |
||
| 113 | '--log-file', |
||
| 114 | help='Path to the logging file.', |
||
| 115 | ) |
||
| 116 | parser.add_argument( |
||
| 117 | '--niceness', |
||
| 118 | default=DEFAULT_NICENESS, |
||
| 119 | type=int, |
||
| 120 | help='Start the scan with the given niceness. Default %(default)s', |
||
| 121 | ) |
||
| 122 | |||
| 123 | self.parser = parser |
||
| 124 | |||
| 190 |