| Conditions | 1 |
| Total Lines | 161 |
| Code Lines | 82 |
| 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 |
||
| 226 | @classmethod |
||
| 227 | def get_parser(cls): |
||
| 228 | """Create command line argument parser.""" |
||
| 229 | parser = argparse.ArgumentParser(description="Simple read-only Thing 3 CLI.") |
||
| 230 | |||
| 231 | subparsers = parser.add_subparsers( |
||
| 232 | help="", metavar="command", required=True, dest="command" |
||
| 233 | ) |
||
| 234 | |||
| 235 | ################################ |
||
| 236 | # Core database methods |
||
| 237 | ################################ |
||
| 238 | subparsers.add_parser("inbox", help="Shows inbox tasks") |
||
| 239 | subparsers.add_parser("today", help="Shows todays tasks") |
||
| 240 | subparsers.add_parser("upcoming", help="Shows upcoming tasks") |
||
| 241 | subparsers.add_parser("anytime", help="Shows anytime tasks") |
||
| 242 | subparsers.add_parser("completed", help="Shows completed tasks") |
||
| 243 | subparsers.add_parser("someday", help="Shows someday tasks") |
||
| 244 | subparsers.add_parser("canceled", help="Shows canceled tasks") |
||
| 245 | subparsers.add_parser("trash", help="Shows trashed tasks") |
||
| 246 | subparsers.add_parser("todos", help="Shows all todos") |
||
| 247 | subparsers.add_parser("all", help="Shows all tasks") |
||
| 248 | subparsers.add_parser("areas", help="Shows all areas") |
||
| 249 | subparsers.add_parser("projects", help="Shows all projects") |
||
| 250 | subparsers.add_parser("logbook", help="Shows completed tasks") |
||
| 251 | subparsers.add_parser("logtoday", help="Shows tasks completed today") |
||
| 252 | subparsers.add_parser("tags", help="Shows all tags ordered by their usage") |
||
| 253 | subparsers.add_parser("deadlines", help="Shows tasks with due dates") |
||
| 254 | |||
| 255 | ################################ |
||
| 256 | # Additional functions |
||
| 257 | ################################ |
||
| 258 | subparsers.add_parser("feedback", help="Give feedback") |
||
| 259 | subparsers.add_parser( |
||
| 260 | "search", help="Searches for a specific task" |
||
| 261 | ).add_argument("string", help="String to search for") |
||
| 262 | |||
| 263 | ################################ |
||
| 264 | # To be implemented in things.py |
||
| 265 | ################################ |
||
| 266 | # subparsers.add_parser("repeating", help="Shows all repeating tasks") |
||
| 267 | # subparsers.add_parser("subtasks", help="Shows all subtasks") |
||
| 268 | # subparsers.add_parser("headings", help="Shows headings") |
||
| 269 | |||
| 270 | ################################ |
||
| 271 | # To be converted from https://github.com/alexanderwillner/things.sh |
||
| 272 | ################################ |
||
| 273 | # subparsers.add_parser("backlog", help="Shows backlog tasks") |
||
| 274 | # subparsers.add_parser("empty", help="Shows projects that are empty") |
||
| 275 | # subparsers.add_parser("hours", help="Shows hours planned today") |
||
| 276 | # subparsers.add_parser("ical", help="Shows tasks ordered by due date as iCal") |
||
| 277 | # subparsers.add_parser("lint", help="Shows tasks that float around") |
||
| 278 | # subparsers.add_parser( |
||
| 279 | # "mostClosed", help="Shows days when most tasks were closed" |
||
| 280 | # ) |
||
| 281 | # subparsers.add_parser( |
||
| 282 | # "mostCancelled", help="Shows days when most tasks were cancelled" |
||
| 283 | # ) |
||
| 284 | # subparsers.add_parser( |
||
| 285 | # "mostTrashed", help="Shows days when most tasks were trashed" |
||
| 286 | # ) |
||
| 287 | # subparsers.add_parser( |
||
| 288 | # "mostCreated", help="Shows days when most tasks were created" |
||
| 289 | # ) |
||
| 290 | # subparsers.add_parser("mostTasks", help="Shows projects that have most tasks") |
||
| 291 | # subparsers.add_parser( |
||
| 292 | # "mostCharacters", help="Shows tasks that have most characters" |
||
| 293 | # ) |
||
| 294 | # subparsers.add_parser("nextish", help="Shows all nextish tasks") |
||
| 295 | # subparsers.add_parser("old", help="Shows all old tasks") |
||
| 296 | # subparsers.add_parser("schedule", help="Schedules an event using a template") |
||
| 297 | # subparsers.add_parser("stat", help="Provides a number of statistics") |
||
| 298 | # subparsers.add_parser("statcsv", help="Exports some statistics as CSV") |
||
| 299 | # subparsers.add_parser("tag", help="Shows all tasks with the waiting for tag") |
||
| 300 | # subparsers.add_parser( |
||
| 301 | # "waiting", help="Shows all tasks with the waiting for tag" |
||
| 302 | # ) |
||
| 303 | |||
| 304 | ################################ |
||
| 305 | # To be converted from https://github.com/alexanderwillner/things.sh |
||
| 306 | ################################ |
||
| 307 | # parser.add_argument("-a", "--anonymize", |
||
| 308 | # action="store_true", default=False, |
||
| 309 | # help="anonymize output", dest="anonymize") |
||
| 310 | |||
| 311 | parser.add_argument( |
||
| 312 | "-p", "--filter-project", dest="filter_project", help="filter by project" |
||
| 313 | ) |
||
| 314 | parser.add_argument( |
||
| 315 | "-a", "--filter-area", dest="filter_area", help="filter by area" |
||
| 316 | ) |
||
| 317 | parser.add_argument( |
||
| 318 | "-t", "--filtertag", dest="filter_tag", help="filter by tag" |
||
| 319 | ) |
||
| 320 | parser.add_argument( |
||
| 321 | "-e", |
||
| 322 | "--only-projects", |
||
| 323 | action="store_true", |
||
| 324 | default=False, |
||
| 325 | dest="only_projects", |
||
| 326 | help="export only projects", |
||
| 327 | ) |
||
| 328 | parser.add_argument( |
||
| 329 | "-o", |
||
| 330 | "--opml", |
||
| 331 | action="store_true", |
||
| 332 | default=False, |
||
| 333 | help="output as OPML", |
||
| 334 | dest="opml", |
||
| 335 | ) |
||
| 336 | |||
| 337 | parser.add_argument( |
||
| 338 | "-j", |
||
| 339 | "--json", |
||
| 340 | action="store_true", |
||
| 341 | default=False, |
||
| 342 | help="output as JSON", |
||
| 343 | dest="json", |
||
| 344 | ) |
||
| 345 | |||
| 346 | parser.add_argument( |
||
| 347 | "-c", |
||
| 348 | "--csv", |
||
| 349 | action="store_true", |
||
| 350 | default=False, |
||
| 351 | help="output as CSV", |
||
| 352 | dest="csv", |
||
| 353 | ) |
||
| 354 | |||
| 355 | parser.add_argument( |
||
| 356 | "-g", |
||
| 357 | "--gantt", |
||
| 358 | action="store_true", |
||
| 359 | default=False, |
||
| 360 | help="output as mermaid-js GANTT", |
||
| 361 | dest="gantt", |
||
| 362 | ) |
||
| 363 | |||
| 364 | parser.add_argument( |
||
| 365 | "-r", |
||
| 366 | "--recursive", |
||
| 367 | help="in-depth output", |
||
| 368 | dest="recursive", |
||
| 369 | default=False, |
||
| 370 | action="store_true", |
||
| 371 | ) |
||
| 372 | |||
| 373 | parser.add_argument( |
||
| 374 | "-d", "--database", help="set path to database", dest="database" |
||
| 375 | ) |
||
| 376 | |||
| 377 | parser.add_argument( |
||
| 378 | "--version", |
||
| 379 | "-v", |
||
| 380 | action="version", |
||
| 381 | version=f"%(prog)s (version {__version__})", |
||
| 382 | ) |
||
| 383 | |||
| 384 | argcomplete.autocomplete(parser) |
||
| 385 | |||
| 386 | return parser |
||
| 387 | |||
| 479 |