diff --git a/grid5000/cli.py b/grid5000/cli.py index f553e4d55377ad2f104a9825386e9d9c2e5ce529..a4b064755bbc802a7ef5942bef9f4e2435499c63 100644 --- a/grid5000/cli.py +++ b/grid5000/cli.py @@ -40,10 +40,19 @@ def main(): IPython.embed(header=motd) -def auth(): - import argparse +def auth(user: str): from getpass import getpass + path = pathlib.Path(CONF_PATH) + + password = getpass("Grid'5000 password: ") + path.write_text("\n".join([f"username: {user}", f"password: {password}"])) + print(f"{CONF_PATH} created successfully") + + +def cli_auth(): + import argparse + parser = argparse.ArgumentParser(description=f"Check or create {CONF_PATH}") parser.add_argument("--user", "-u", help="Username on Grid'5000", required=True) args = parser.parse_args() @@ -52,11 +61,4 @@ def auth(): if path.exists(): print(f"{CONF_PATH} file already exists, not overwriting") return - user = args.user - - password = getpass("Grid'5000 password: ") - path.write_text("\n".join([ - f"username: {user}", - f"password: {password}" - ])) - print(f"{CONF_PATH} created successfully") + auth(args.user) diff --git a/setup.cfg b/setup.cfg index 1d588c1a8c0106e328a11695dcdc9c56fc2b8bb6..7b178203b6220d0e7e9982d2666a74041603cd77 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,4 +35,4 @@ exclude = [options.entry_points] console_scripts = grid5000 = grid5000.cli:main - grid5000-auth = grid5000.cli:auth \ No newline at end of file + grid5000-auth = grid5000.cli:cli_auth \ No newline at end of file