| Conditions | 1 |
| Total Lines | 130 |
| Code Lines | 99 |
| 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) 2014-2020 Greenbone Networks GmbH |
||
| 49 | def __init__(self, description: str) -> None: |
||
| 50 | """ Create a command-line arguments parser for OSPD. """ |
||
| 51 | self._name = description |
||
| 52 | parser = argparse.ArgumentParser(description=description) |
||
| 53 | |||
| 54 | parser.add_argument( |
||
| 55 | '--version', action='store_true', help='Print version then exit.' |
||
| 56 | ) |
||
| 57 | |||
| 58 | parser.add_argument( |
||
| 59 | '-s', |
||
| 60 | '--config', |
||
| 61 | nargs='?', |
||
| 62 | default=DEFAULT_CONFIG_PATH, |
||
| 63 | help='Configuration file path (default: %(default)s)', |
||
| 64 | ) |
||
| 65 | |||
| 66 | parser.add_argument( |
||
| 67 | '-p', |
||
| 68 | '--port', |
||
| 69 | default=DEFAULT_PORT, |
||
| 70 | type=self.network_port, |
||
| 71 | help='TCP Port to listen on. Default: %(default)s', |
||
| 72 | ) |
||
| 73 | parser.add_argument( |
||
| 74 | '-b', |
||
| 75 | '--bind-address', |
||
| 76 | default=DEFAULT_ADDRESS, |
||
| 77 | dest='address', |
||
| 78 | help='Address to listen on. Default: %(default)s', |
||
| 79 | ) |
||
| 80 | parser.add_argument( |
||
| 81 | '-u', |
||
| 82 | '--unix-socket', |
||
| 83 | default=DEFAULT_UNIX_SOCKET_PATH, |
||
| 84 | help='Unix file socket to listen on. Default: %(default)s', |
||
| 85 | ) |
||
| 86 | parser.add_argument( |
||
| 87 | '--pid-file', |
||
| 88 | default=DEFAULT_PID_PATH, |
||
| 89 | help='Location of the file for the process ID. ' |
||
| 90 | 'Default: %(default)s', |
||
| 91 | ) |
||
| 92 | parser.add_argument( |
||
| 93 | '--lock-file-dir', |
||
| 94 | default=DEFAULT_LOCKFILE_DIR_PATH, |
||
| 95 | help='Directory where lock files are placed. Default: %(default)s', |
||
| 96 | ) |
||
| 97 | parser.add_argument( |
||
| 98 | '-m', |
||
| 99 | '--socket-mode', |
||
| 100 | default=DEFAULT_UNIX_SOCKET_MODE, |
||
| 101 | help='Unix file socket mode. Default: %(default)s', |
||
| 102 | ) |
||
| 103 | parser.add_argument( |
||
| 104 | '-k', |
||
| 105 | '--key-file', |
||
| 106 | default=DEFAULT_KEY_FILE, |
||
| 107 | help='Server key file. Default: %(default)s', |
||
| 108 | ) |
||
| 109 | parser.add_argument( |
||
| 110 | '-c', |
||
| 111 | '--cert-file', |
||
| 112 | default=DEFAULT_CERT_FILE, |
||
| 113 | help='Server cert file. Default: %(default)s', |
||
| 114 | ) |
||
| 115 | parser.add_argument( |
||
| 116 | '--ca-file', |
||
| 117 | default=DEFAULT_CA_FILE, |
||
| 118 | help='CA cert file. Default: %(default)s', |
||
| 119 | ) |
||
| 120 | parser.add_argument( |
||
| 121 | '-L', |
||
| 122 | '--log-level', |
||
| 123 | default='WARNING', |
||
| 124 | type=self.log_level, |
||
| 125 | help='Wished level of logging. Default: %(default)s', |
||
| 126 | ) |
||
| 127 | parser.add_argument( |
||
| 128 | '-f', |
||
| 129 | '--foreground', |
||
| 130 | action='store_true', |
||
| 131 | help='Run in foreground and logs all messages to console.', |
||
| 132 | ) |
||
| 133 | parser.add_argument( |
||
| 134 | '-t', |
||
| 135 | '--stream-timeout', |
||
| 136 | default=DEFAULT_STREAM_TIMEOUT, |
||
| 137 | type=int, |
||
| 138 | help='Stream timeout. Default: %(default)s', |
||
| 139 | ) |
||
| 140 | parser.add_argument( |
||
| 141 | '-l', '--log-file', help='Path to the logging file.' |
||
| 142 | ) |
||
| 143 | parser.add_argument( |
||
| 144 | '--niceness', |
||
| 145 | default=DEFAULT_NICENESS, |
||
| 146 | type=int, |
||
| 147 | help='Start the scan with the given niceness. Default %(default)s', |
||
| 148 | ) |
||
| 149 | parser.add_argument( |
||
| 150 | '--scaninfo-store-time', |
||
| 151 | default=DEFAULT_SCANINFO_STORE_TIME, |
||
| 152 | type=int, |
||
| 153 | help='Time in hours a scan is stored before being considered ' |
||
| 154 | 'forgotten and being delete from the scan table. ' |
||
| 155 | 'Default %(default)s, disabled.', |
||
| 156 | ) |
||
| 157 | parser.add_argument( |
||
| 158 | '--list-commands', |
||
| 159 | action='store_true', |
||
| 160 | help='Display all protocol commands', |
||
| 161 | ) |
||
| 162 | parser.add_argument( |
||
| 163 | '--max-scans', |
||
| 164 | default=DEFAULT_MAX_SCAN, |
||
| 165 | type=int, |
||
| 166 | help='Max. amount of parallel task that can be started. ' |
||
| 167 | 'Default %(default)s, disabled', |
||
| 168 | ) |
||
| 169 | parser.add_argument( |
||
| 170 | '--check-free-memory', |
||
| 171 | default=False, |
||
| 172 | type=self.str2bool, |
||
| 173 | help='Check if there is enough free memory to run the scan. ' |
||
| 174 | 'This is an experimental feature. ' |
||
| 175 | 'Default %(default)s, disabled', |
||
| 176 | ) |
||
| 177 | |||
| 178 | self.parser = parser |
||
| 179 | |||
| 254 |