pydoto-cli

Simple ToDo-like application, that just works. Add any tasks without closing your terminal.
git clone https://git.nfu.su/pydoto-cli.git
Log | Files | Refs | README

parser.py (2097B)


      1 import argparse as ap
      2 from datetime import datetime
      3 
      4 
      5 # Parser block
      6 def parseit():
      7     """Parse CLI flags"""
      8     parser = ap.ArgumentParser(description="Simple ToDo app written on pure python")
      9 
     10     parser.add_argument(
     11         "-c",
     12         "--create",
     13         nargs="*",
     14         metavar=("ARGS"),
     15         help="You can provide NAME, DESCRIPTION, EXPIRATION_DATE to create a new task",
     16     )
     17     parser.add_argument(
     18         "-f",
     19         "--db-create",
     20         action="store_true",
     21         help="Create a new DB file (if doesn't exist yet)",
     22     )
     23     parser.add_argument(
     24         "-r", "--remove", nargs=1, metavar=("ID"), help="Mark task/tasks as deleted"
     25     )
     26     parser.add_argument(
     27         "-d", "--done", nargs=1, metavar=("ID"), help="Mark task/tasks as completed"
     28     )
     29     parser.add_argument(
     30         "-a",
     31         "--print-tasks",
     32         action="store_true",
     33         help="Prints all tasks (excluding DELETED)",
     34     )
     35     parser.add_argument(
     36         "-A",
     37         "--print-all",
     38         action="store_true",
     39         help="Prints all tasks (including DELETED)",
     40     )
     41     parser.add_argument(
     42         "-i",
     43         "--id",
     44         action="store_true",
     45         help="Prints all tasks ID (excluding DELETED)",
     46     )
     47     parser.add_argument(
     48         "-I",
     49         "--all-id",
     50         action="store_true",
     51         help="Prints all tasks ID (including DELETED)",
     52     )
     53     parser.add_argument(
     54         "-S",
     55         "--cloud-save",
     56         action="store_true",
     57         help="Save .conf & .json files into your Cloud method, provided in .conf",
     58     )
     59     parser.add_argument(
     60         "-L",
     61         "--cloud-load",
     62         action="store_true",
     63         help="Load .conf & .json files from your Cloud method, provided in .conf",
     64     )
     65 
     66     args = parser.parse_args()
     67 
     68     return args
     69 
     70 
     71 def parse_expiration_date(date_string):
     72     try:
     73         exp_date = datetime.strptime(date_string, "%d-%m-%Y, %H:%M:%S")
     74     except ValueError:
     75         raise ap.ArgumentTypeError(
     76             f'!> Incorrect date format: {date_string}. Use "DD-MM-YYYY, HH:MM:SS" instead.'
     77         )
     78 
     79     return exp_date