| Conditions | 1 |
| Total Lines | 143 |
| Code Lines | 66 |
| 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 |
||
| 140 | @classmethod |
||
| 141 | def get_parser(cls): |
||
| 142 | """Create command line argument parser""" |
||
| 143 | parser = argparse.ArgumentParser(description="Simple read-only Thing 3 CLI.") |
||
| 144 | |||
| 145 | subparsers = parser.add_subparsers( |
||
| 146 | help="", metavar="command", required=True, dest="command" |
||
| 147 | ) |
||
| 148 | |||
| 149 | ################################ |
||
| 150 | # Core database methods |
||
| 151 | ################################ |
||
| 152 | subparsers.add_parser("inbox", help="Shows inbox tasks") |
||
| 153 | subparsers.add_parser("today", help="Shows todays tasks") |
||
| 154 | subparsers.add_parser("upcoming", help="Shows upcoming tasks") |
||
| 155 | subparsers.add_parser("anytime", help="Shows anytime tasks") |
||
| 156 | subparsers.add_parser("completed", help="Shows completed tasks") |
||
| 157 | subparsers.add_parser("canceled", help="Shows canceled tasks") |
||
| 158 | subparsers.add_parser("trash", help="Shows trashed tasks") |
||
| 159 | subparsers.add_parser("todos", help="Shows all todos") |
||
| 160 | subparsers.add_parser("all", help="Shows all tasks") |
||
| 161 | subparsers.add_parser("areas", help="Shows all areas") |
||
| 162 | subparsers.add_parser("projects", help="Shows all projects") |
||
| 163 | subparsers.add_parser("logbook", help="Shows tasks completed today") |
||
| 164 | subparsers.add_parser("tags", help="Shows all tags ordered by their usage") |
||
| 165 | subparsers.add_parser("deadlines", help="Shows tasks with due dates") |
||
| 166 | |||
| 167 | ################################ |
||
| 168 | # Additional functions |
||
| 169 | ################################ |
||
| 170 | subparsers.add_parser("feedback", help="Give feedback") |
||
| 171 | subparsers.add_parser( |
||
| 172 | "search", help="Searches for a specific task" |
||
| 173 | ).add_argument("string", help="String to search for") |
||
| 174 | |||
| 175 | ################################ |
||
| 176 | # To be implemented in things.py |
||
| 177 | ################################ |
||
| 178 | # subparsers.add_parser("repeating", help="Shows all repeating tasks") |
||
| 179 | # subparsers.add_parser("subtasks", help="Shows all subtasks") |
||
| 180 | # subparsers.add_parser("headings", help="Shows headings") |
||
| 181 | |||
| 182 | ################################ |
||
| 183 | # To be converted from https://github.com/alexanderwillner/things.sh |
||
| 184 | ################################ |
||
| 185 | # subparsers.add_parser("backlog", help="Shows backlog tasks") |
||
| 186 | # subparsers.add_parser("empty", help="Shows projects that are empty") |
||
| 187 | # subparsers.add_parser("hours", help="Shows hours planned today") |
||
| 188 | # subparsers.add_parser("ical", help="Shows tasks ordered by due date as iCal") |
||
| 189 | # subparsers.add_parser("lint", help="Shows tasks that float around") |
||
| 190 | # subparsers.add_parser( |
||
| 191 | # "mostClosed", help="Shows days when most tasks were closed" |
||
| 192 | # ) |
||
| 193 | # subparsers.add_parser( |
||
| 194 | # "mostCancelled", help="Shows days when most tasks were cancelled" |
||
| 195 | # ) |
||
| 196 | # subparsers.add_parser( |
||
| 197 | # "mostTrashed", help="Shows days when most tasks were trashed" |
||
| 198 | # ) |
||
| 199 | # subparsers.add_parser( |
||
| 200 | # "mostCreated", help="Shows days when most tasks were created" |
||
| 201 | # ) |
||
| 202 | # subparsers.add_parser("mostTasks", help="Shows projects that have most tasks") |
||
| 203 | # subparsers.add_parser( |
||
| 204 | # "mostCharacters", help="Shows tasks that have most characters" |
||
| 205 | # ) |
||
| 206 | # subparsers.add_parser("nextish", help="Shows all nextish tasks") |
||
| 207 | # subparsers.add_parser("old", help="Shows all old tasks") |
||
| 208 | # subparsers.add_parser("schedule", help="Schedules an event using a template") |
||
| 209 | # subparsers.add_parser("stat", help="Provides a number of statistics") |
||
| 210 | # subparsers.add_parser("statcsv", help="Exports some statistics as CSV") |
||
| 211 | # subparsers.add_parser("tag", help="Shows all tasks with the waiting for tag") |
||
| 212 | # subparsers.add_parser( |
||
| 213 | # "waiting", help="Shows all tasks with the waiting for tag" |
||
| 214 | # ) |
||
| 215 | |||
| 216 | ################################ |
||
| 217 | # To be converted from https://github.com/alexanderwillner/things.sh |
||
| 218 | ################################ |
||
| 219 | # parser.add_argument("-a", "--anonymize", |
||
| 220 | # action="store_true", default=False, |
||
| 221 | # help="anonymize output", dest="anonymize") |
||
| 222 | |||
| 223 | parser.add_argument( |
||
| 224 | "-p", "--filter-project", dest="filter_project", help="Filter by project" |
||
| 225 | ) |
||
| 226 | parser.add_argument( |
||
| 227 | "-a", "--filter-area", dest="filter_area", help="Filter by area" |
||
| 228 | ) |
||
| 229 | parser.add_argument( |
||
| 230 | "-t", "--filtertag", dest="filter_tag", help="Filter by tag" |
||
| 231 | ) |
||
| 232 | |||
| 233 | parser.add_argument( |
||
| 234 | "-o", |
||
| 235 | "--opml", |
||
| 236 | action="store_true", |
||
| 237 | default=False, |
||
| 238 | help="output as OPML", |
||
| 239 | dest="opml", |
||
| 240 | ) |
||
| 241 | |||
| 242 | parser.add_argument( |
||
| 243 | "-j", |
||
| 244 | "--json", |
||
| 245 | action="store_true", |
||
| 246 | default=False, |
||
| 247 | help="output as JSON", |
||
| 248 | dest="json", |
||
| 249 | ) |
||
| 250 | |||
| 251 | parser.add_argument( |
||
| 252 | "-c", |
||
| 253 | "--csv", |
||
| 254 | action="store_true", |
||
| 255 | default=False, |
||
| 256 | help="output as CSV", |
||
| 257 | dest="csv", |
||
| 258 | ) |
||
| 259 | |||
| 260 | parser.add_argument( |
||
| 261 | "-r", |
||
| 262 | "--recursive", |
||
| 263 | help="in-depth output", |
||
| 264 | dest="recursive", |
||
| 265 | default=False, |
||
| 266 | action="store_true", |
||
| 267 | ) |
||
| 268 | |||
| 269 | parser.add_argument( |
||
| 270 | "-d", "--database", help="set path to database", dest="database" |
||
| 271 | ) |
||
| 272 | |||
| 273 | parser.add_argument( |
||
| 274 | "--version", |
||
| 275 | "-v", |
||
| 276 | action="version", |
||
| 277 | version="%(prog)s (version {version})".format(version=__version__), |
||
| 278 | ) |
||
| 279 | |||
| 280 | argcomplete.autocomplete(parser) |
||
| 281 | |||
| 282 | return parser |
||
| 283 | |||
| 368 |