Conditions | 1 |
Total Lines | 104 |
Code Lines | 83 |
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 |
||
68 | @classmethod |
||
69 | def get_parser(cls): |
||
70 | """Create command line argument parser""" |
||
71 | parser = argparse.ArgumentParser(description="Simple read-only Thing 3 CLI.") |
||
72 | |||
73 | subparsers = parser.add_subparsers( |
||
74 | help="", metavar="command", required=True, dest="command" |
||
75 | ) |
||
76 | subparsers.add_parser("inbox", help="Shows inbox tasks") |
||
77 | subparsers.add_parser("today", help="Shows todays tasks") |
||
78 | subparsers.add_parser("upcoming", help="Shows upcoming tasks") |
||
79 | subparsers.add_parser("next", help="Shows next tasks") |
||
80 | subparsers.add_parser("backlog", help="Shows backlog tasks") |
||
81 | subparsers.add_parser("completed", help="Shows completed tasks") |
||
82 | subparsers.add_parser("cancelled", help="Shows cancelled tasks") |
||
83 | subparsers.add_parser("trashed", help="Shows trashed tasks") |
||
84 | subparsers.add_parser("feedback", help="Give feedback") |
||
85 | subparsers.add_parser("all", help="Shows all tasks") |
||
86 | subparsers.add_parser("csv", help="Exports tasks as CSV") |
||
87 | subparsers.add_parser("areas", help="Shows all areas") |
||
88 | subparsers.add_parser("opml", help="Exports tasks as OPML") |
||
89 | subparsers.add_parser("due", help="Shows tasks with due dates") |
||
90 | subparsers.add_parser("empty", help="Shows projects that are empty") |
||
91 | subparsers.add_parser("headings", help="Shows headings") |
||
92 | subparsers.add_parser("hours", help="Shows hours planned today") |
||
93 | subparsers.add_parser("ical", help="Shows tasks ordered by due date as iCal") |
||
94 | subparsers.add_parser("lint", help="Shows tasks that float around") |
||
95 | subparsers.add_parser("logbook", help="Shows tasks completed today") |
||
96 | subparsers.add_parser( |
||
97 | "mostClosed", help="Shows days when most tasks were closed" |
||
98 | ) |
||
99 | subparsers.add_parser( |
||
100 | "mostCancelled", help="Shows days when most tasks were cancelled" |
||
101 | ) |
||
102 | subparsers.add_parser( |
||
103 | "mostTrashed", help="Shows days when most tasks were trashed" |
||
104 | ) |
||
105 | subparsers.add_parser( |
||
106 | "mostCreated", help="Shows days when most tasks were created" |
||
107 | ) |
||
108 | subparsers.add_parser("mostTasks", help="Shows projects that have most tasks") |
||
109 | subparsers.add_parser( |
||
110 | "mostCharacters", help="Shows tasks that have most characters" |
||
111 | ) |
||
112 | subparsers.add_parser("nextish", help="Shows all nextish tasks") |
||
113 | subparsers.add_parser("old", help="Shows all old tasks") |
||
114 | subparsers.add_parser("projects", help="Shows all projects") |
||
115 | subparsers.add_parser("repeating", help="Shows all repeating tasks") |
||
116 | subparsers.add_parser("schedule", help="Schedules an event using a template") |
||
117 | subparsers.add_parser("search", help="Searches for a specific task") |
||
118 | subparsers.add_parser("stat", help="Provides a number of statistics") |
||
119 | subparsers.add_parser("statcsv", help="Exports some statistics as CSV") |
||
120 | subparsers.add_parser("subtasks", help="Shows all subtasks") |
||
121 | subparsers.add_parser("tag", help="Shows all tasks with the waiting for tag") |
||
122 | subparsers.add_parser("tags", help="Shows all tags ordered by their usage") |
||
123 | subparsers.add_parser( |
||
124 | "waiting", help="Shows all tasks with the waiting for tag" |
||
125 | ) |
||
126 | |||
127 | parser.add_argument( |
||
128 | "-j", |
||
129 | "--json", |
||
130 | action="store_true", |
||
131 | default=False, |
||
132 | help="output as JSON", |
||
133 | dest="json", |
||
134 | ) |
||
135 | |||
136 | parser.add_argument( |
||
137 | "-c", |
||
138 | "--csv", |
||
139 | action="store_true", |
||
140 | default=False, |
||
141 | help="output as CSV", |
||
142 | dest="csv", |
||
143 | ) |
||
144 | |||
145 | parser.add_argument( |
||
146 | "-o", |
||
147 | "--opml", |
||
148 | action="store_true", |
||
149 | default=False, |
||
150 | help="output as OPML", |
||
151 | dest="opml", |
||
152 | ) |
||
153 | |||
154 | parser.add_argument( |
||
155 | "-a", |
||
156 | "--anonymize", |
||
157 | action="store_true", |
||
158 | default=False, |
||
159 | help="anonymize output", |
||
160 | dest="anonymize", |
||
161 | ) |
||
162 | |||
163 | parser.add_argument( |
||
164 | "--version", |
||
165 | action="version", |
||
166 | version=f"%(prog)s (version {things3.__version__})", |
||
167 | ) |
||
168 | |||
169 | argcomplete.autocomplete(parser) |
||
170 | |||
171 | return parser |
||
172 | |||
206 |