Parse arguments passed by command line interface
()
| 2379 | |
| 2380 | |
| 2381 | def parse_cli_args(): |
| 2382 | """Parse arguments passed by command line interface""" |
| 2383 | |
| 2384 | AP_kwargs = dict( |
| 2385 | prog="InstaPy", |
| 2386 | description="Parse InstaPy constructor's arguments", |
| 2387 | epilog="And that's how you'd pass arguments by CLI..", |
| 2388 | conflict_handler="resolve", |
| 2389 | ) |
| 2390 | if python_version() < "3.5": |
| 2391 | parser = CustomizedArgumentParser(**AP_kwargs) |
| 2392 | else: |
| 2393 | AP_kwargs.update(allow_abbrev=False) |
| 2394 | parser = ArgumentParser(**AP_kwargs) |
| 2395 | |
| 2396 | """ Flags that REQUIRE a value once added |
| 2397 | ```python quickstart.py --username abc``` |
| 2398 | """ |
| 2399 | parser.add_argument("-u", "--username", help="Username", type=str, metavar="abc") |
| 2400 | parser.add_argument("-p", "--password", help="Password", type=str, metavar="123") |
| 2401 | parser.add_argument( |
| 2402 | "-pd", "--page-delay", help="Implicit wait", type=int, metavar=25 |
| 2403 | ) |
| 2404 | parser.add_argument( |
| 2405 | "-pa", "--proxy-address", help="Proxy address", type=str, metavar="192.168.1.1" |
| 2406 | ) |
| 2407 | parser.add_argument( |
| 2408 | "-pp", "--proxy-port", help="Proxy port", type=int, metavar=8080 |
| 2409 | ) |
| 2410 | |
| 2411 | """ Auto-booleans: adding these flags ENABLE themselves automatically |
| 2412 | ```python quickstart.py --use-firefox``` |
| 2413 | """ |
| 2414 | parser.add_argument( |
| 2415 | "-uf", "--use-firefox", help="Use Firefox", action="store_true", default=None |
| 2416 | ) |
| 2417 | parser.add_argument( |
| 2418 | "-hb", |
| 2419 | "--headless-browser", |
| 2420 | help="Headless browser", |
| 2421 | action="store_true", |
| 2422 | default=None, |
| 2423 | ) |
| 2424 | parser.add_argument( |
| 2425 | "-dil", |
| 2426 | "--disable-image-load", |
| 2427 | help="Disable image load", |
| 2428 | action="store_true", |
| 2429 | default=None, |
| 2430 | ) |
| 2431 | parser.add_argument( |
| 2432 | "-bsa", |
| 2433 | "--bypass-suspicious-attempt", |
| 2434 | help="Bypass suspicious attempt", |
| 2435 | action="store_true", |
| 2436 | default=None, |
| 2437 | ) |
| 2438 | parser.add_argument( |
no test coverage detected