Quellcode durchsuchen

Read password from stdin if not provided as an input

Sean vor 4 Jahren
Ursprung
Commit
b33e59dfdc
2 geänderte Dateien mit 9 neuen und 9 gelöschten Zeilen
  1. 8 8
      ocma/cli.py
  2. 1 1
      pyproject.toml

+ 8 - 8
ocma/cli.py

@@ -1,4 +1,5 @@
 import argparse
+from typing import Optional
 
 from ocma import connect
 
@@ -12,7 +13,7 @@ def run() -> None:
         "--username",
         metavar="username",
         type=str,
-        help="MS Account username",
+        help="MS Account username.",
         required=True,
     )
     parser.add_argument(
@@ -20,15 +21,14 @@ def run() -> None:
         "--password",
         metavar="password",
         type=str,
-        help="MS Account password",
-        required=True,
+        help="MS Account password. If not provided, it will be read from stdin.",
     )
     parser.add_argument(
         "-m",
         "--mfa",
         metavar="secret",
         type=str,
-        help="TOTP secret. Required, if you have set up 2FA with your MS account (only TOTP)",
+        help="TOTP secret. Required, if you have set up 2FA with your MS account (only TOTP).",
         required=False,
     )
 
@@ -43,7 +43,7 @@ def run() -> None:
     parser.add_argument(
         "--show-head",
         action="store_false",
-        help="If the browser window should be shown during the authentication process",
+        help="If the browser window should be shown during the authentication process.",
     )
 
     parser.add_argument(
@@ -60,14 +60,14 @@ def run() -> None:
     args = parser.parse_args()
 
     username: str = args.username
-    password: str = args.password
+    password: Optional[str] = args.password
     mfa_secret: str = args.mfa
     vpn_url: str = args.vpn_url
     headless: bool = args.show_head
     print_to_stdout: bool = args.print_to_stdout
 
-    if username is None or password is None:
-        raise ValueError("Username and password must be specified!")
+    if password is None:
+        password = input()
 
     if mfa_secret is not None:
         try:

+ 1 - 1
pyproject.toml

@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "ocma"
-version = "0.1.0"
+version = "0.1.1"
 description = ""
 authors = ["Sean <birdicode@gmail.com>"]