From 9d4ae7127080a4ab76cd3e9cd0979b0eff17fbd3 Mon Sep 17 00:00:00 2001
From: msimonin <matthieu.simonin@inria.fr>
Date: Wed, 9 Mar 2022 15:18:34 +0100
Subject: [PATCH] cli_auth: extract method

---
 grid5000/cli.py | 22 ++++++++++++----------
 setup.cfg       |  2 +-
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/grid5000/cli.py b/grid5000/cli.py
index f553e4d..a4b0647 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 1d588c1..7b17820 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
-- 
GitLab