| Conditions | 1 |
| Total Lines | 52 |
| Code Lines | 47 |
| 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 | #!/usr/bin/env python3 |
||
| 29 | def handle_arguments() -> argparse.ArgumentParser: |
||
| 30 | """Provide CLI handler for application.""" |
||
| 31 | |||
| 32 | parser = argparse.ArgumentParser() |
||
| 33 | parser.add_argument("-a", "--all", |
||
| 34 | help="iterate over all folders", |
||
| 35 | action='store_true') |
||
| 36 | parser.add_argument("-d", "--detach", |
||
| 37 | help="remove attachments", |
||
| 38 | action='store_true') |
||
| 39 | parser.add_argument("-k", "--skip-download", |
||
| 40 | help="don't download attachments", |
||
| 41 | action='store_true') |
||
| 42 | parser.add_argument("-c", "--reset-cache", |
||
| 43 | help="reset cache", |
||
| 44 | action='store_true') |
||
| 45 | parser.add_argument("-r", "--read-only", |
||
| 46 | help="read-only mode for the imap server", |
||
| 47 | action='store_true') |
||
| 48 | parser.add_argument("-m", "--max-size", |
||
| 49 | help="max attachment size in KB", |
||
| 50 | default=200, type=int) |
||
| 51 | parser.add_argument("-f", "--folder", |
||
| 52 | help="imap folder to process", default="Inbox") |
||
| 53 | parser.add_argument("-l", "--upload", |
||
| 54 | help="local folder with messages to upload") |
||
| 55 | parser.add_argument("-t", "--target", |
||
| 56 | help="download attachments to this local folder", |
||
| 57 | default="attachments") |
||
| 58 | parser.add_argument("-s", "--server", help="imap server", required=True) |
||
| 59 | parser.add_argument("-u", "--user", help="imap user", required=True) |
||
| 60 | parser.add_argument("-o", "--port", help="imap port", required=False, |
||
| 61 | type=int) |
||
| 62 | parser.add_argument("-p", "--password", help="imap user", required=True) |
||
| 63 | parser.add_argument( |
||
| 64 | "-v", |
||
| 65 | "--verbose", |
||
| 66 | action="count", |
||
| 67 | default=0, |
||
| 68 | dest="verbosity", |
||
| 69 | help="be more verbose (-v, -vv)") |
||
| 70 | parser.add_argument( |
||
| 71 | "--version", |
||
| 72 | action="version", |
||
| 73 | version="%(prog)s (version {version})".format(version=__version__)) |
||
| 74 | |||
| 75 | args = parser.parse_args() |
||
| 76 | |||
| 77 | logging.basicConfig(level=logging.WARNING - args.verbosity * 10, |
||
| 78 | format="%(message)s") |
||
| 79 | |||
| 80 | return args |
||
| 81 | |||
| 119 |