File: _in_argv.py

package info (click to toggle)
python-milc 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 788 kB
  • sloc: python: 1,868; sh: 55; makefile: 3
file content (26 lines) | stat: -rw-r--r-- 733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys
from typing import Optional


def _in_argv(argument: str) -> bool:
    """Returns true if the argument is found is sys.argv.

    Since long options can be passed as either '--option value' or '--option=value' we need to check for both forms.
    """
    for arg in sys.argv:
        if arg.split('=')[0] == argument:
            return True

    return False


def _index_argv(argument: str) -> Optional[int]:
    """Returns the location of the argument in sys.argv, or None.

    Since long options can be passed as either '--option value' or '--option=value' we need to check for both forms.
    """
    for i, arg in enumerate(sys.argv):
        if arg.split('=')[0] == argument:
            return i

    return None