| Conditions | 3 |
| Total Lines | 106 |
| Code Lines | 73 |
| Lines | 106 |
| Ratio | 100 % |
| 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 | # MIT License |
||
| 187 | View Code Duplication | def main(): |
|
| 188 | |||
| 189 | verbose_parser = argparse.ArgumentParser(add_help=False) |
||
| 190 | verbose_parser.add_argument( |
||
| 191 | '-v', '--verbose', |
||
| 192 | action='count', |
||
| 193 | help='Give *A LOT* more output.', |
||
| 194 | ) |
||
| 195 | |||
| 196 | cli_parser = argparse.ArgumentParser( |
||
| 197 | description=PROJECT_DESCRIPTION, |
||
| 198 | parents=[verbose_parser], |
||
| 199 | ) |
||
| 200 | |||
| 201 | subcmd_parsers = cli_parser.add_subparsers( |
||
| 202 | title='Subcommands', |
||
| 203 | description='%(prog)s implements the following subcommands:', |
||
| 204 | dest='subcmd', |
||
| 205 | ) |
||
| 206 | |||
| 207 | csv_parser = subcmd_parsers.add_parser( |
||
| 208 | 'csv', |
||
| 209 | parents=[verbose_parser], |
||
| 210 | help='Dumps visible and recovered records to CSV files', |
||
| 211 | description=( |
||
| 212 | 'Recovers as many records as possible from the database passed as ' |
||
| 213 | 'argument and outputs all visible and recovered records to CSV ' |
||
| 214 | 'files in output_dir' |
||
| 215 | ), |
||
| 216 | ) |
||
| 217 | csv_parser.add_argument( |
||
| 218 | 'sqlite_path', |
||
| 219 | help='sqlite3 file path' |
||
| 220 | ) |
||
| 221 | csv_parser.add_argument( |
||
| 222 | 'output_dir', |
||
| 223 | nargs='?', |
||
| 224 | default=None, |
||
| 225 | help='Output directory' |
||
| 226 | ) |
||
| 227 | csv_parser.add_argument( |
||
| 228 | '-d', '--database-name', |
||
| 229 | nargs='?', |
||
| 230 | default=None, |
||
| 231 | help='Database name' |
||
| 232 | ) |
||
| 233 | |||
| 234 | list_parser = subcmd_parsers.add_parser( # pylint:disable=W0612 |
||
| 235 | 'list', |
||
| 236 | parents=[verbose_parser], |
||
| 237 | help='Displays supported DB types', |
||
| 238 | description=( |
||
| 239 | 'Displays the names of all database types with table heuristics ' |
||
| 240 | 'known to {}'.format(PROJECT_NAME) |
||
| 241 | ), |
||
| 242 | ) |
||
| 243 | |||
| 244 | grep_parser = subcmd_parsers.add_parser( |
||
| 245 | 'grep', |
||
| 246 | parents=[verbose_parser], |
||
| 247 | help='Matches a string in one or more pages of the database', |
||
| 248 | description='Bar', |
||
| 249 | ) |
||
| 250 | grep_parser.add_argument( |
||
| 251 | 'sqlite_path', |
||
| 252 | help='sqlite3 file path' |
||
| 253 | ) |
||
| 254 | grep_parser.add_argument( |
||
| 255 | 'needle', |
||
| 256 | help='String to match in the database' |
||
| 257 | ) |
||
| 258 | |||
| 259 | undelete_parser = subcmd_parsers.add_parser( |
||
| 260 | 'undelete', |
||
| 261 | parents=[verbose_parser], |
||
| 262 | help='Inserts recovered records into a copy of the database', |
||
| 263 | description=( |
||
| 264 | 'Recovers as many records as possible from the database passed as ' |
||
| 265 | 'argument and inserts all recovered records into a copy of' |
||
| 266 | 'the database.' |
||
| 267 | ), |
||
| 268 | ) |
||
| 269 | undelete_parser.add_argument( |
||
| 270 | 'sqlite_path', |
||
| 271 | help='sqlite3 file path' |
||
| 272 | ) |
||
| 273 | undelete_parser.add_argument( |
||
| 274 | 'output_path', |
||
| 275 | help='Output database path' |
||
| 276 | ) |
||
| 277 | undelete_parser.add_argument( |
||
| 278 | '-d', '--database-name', |
||
| 279 | nargs='?', |
||
| 280 | default=None, |
||
| 281 | help='Database name' |
||
| 282 | ) |
||
| 283 | |||
| 284 | cli_args = cli_parser.parse_args() |
||
| 285 | if cli_args.verbose: |
||
| 286 | _LOGGER.setLevel(logging.DEBUG) |
||
| 287 | |||
| 288 | if cli_args.subcmd: |
||
| 289 | subcmd_dispatcher(cli_args) |
||
| 290 | else: |
||
| 291 | # No subcommand specified, print the usage and bail |
||
| 292 | cli_parser.print_help() |
||
| 293 |