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