Skip to content

Commit ee18654

Browse files
committed
run: Add -n argument to login to a realm, and create config.
If the realm already exists, will exit with an error saying so. Tests updated.
1 parent 80f5451 commit ee18654

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

tests/cli/test_run.py

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def test_main_help(capsys: CaptureFixture[str], options: str) -> None:
134134
"-h, --help",
135135
"-d, --debug",
136136
"-o, --list-organizations",
137+
"-n, --new-organization",
137138
"--list-themes",
138139
"--profile",
139140
"--config-file CONFIG_FILE, -c CONFIG_FILE",

zulipterminal/cli/run.py

+25-8
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
156156
action="store_true",
157157
help="list all the organizations that you have configurations for, and exit",
158158
)
159+
parser.add_argument(
160+
"-n",
161+
"--new-organization",
162+
action="store_true",
163+
help="login to a new organization",
164+
)
159165
parser.add_argument(
160166
"--theme",
161167
"-t",
@@ -293,15 +299,20 @@ def get_api_key(realm_url: str) -> Optional[Tuple[str, str, str, str]]:
293299
return None
294300

295301

296-
def fetch_zuliprc(zuliprc_path: str) -> str:
302+
def fetch_zuliprc(zuliprc_path: str, new_realm: bool) -> str:
297303
locations_checked = (
298304
zuliprc_path
299305
if zuliprc_path != ""
300306
else f"any of the following locations: "
301307
f"{DOWNLOADED_PATH_ZULIPRC} or {ZULIP_CONFIG_PATH} or {HOME_PATH_ZULIPRC}"
302308
)
309+
missing_zuliprc_text = (
310+
""
311+
if new_realm
312+
else f"{in_color('red', f'zuliprc file was not found at {locations_checked}')}"
313+
)
303314
print(
304-
f"{in_color('red', f'zuliprc file was not found at {locations_checked}')}"
315+
f"{missing_zuliprc_text}"
305316
f"\nPlease enter your credentials to login into your Zulip organization."
306317
f"\n"
307318
f"\nNOTE: The {in_color('blue', 'Zulip server URL')}"
@@ -387,15 +398,21 @@ def check_for_default_zuliprc() -> str:
387398
return ""
388399

389400

390-
def parse_zuliprc(zuliprc_str: str) -> Tuple[Dict[str, SettingData], str]:
401+
def parse_zuliprc(
402+
zuliprc_str: str, new_realm: bool
403+
) -> Tuple[Dict[str, SettingData], str]:
391404
zuliprc_path = (
392-
check_for_default_zuliprc()
393-
if zuliprc_str == ""
394-
else path.expanduser(zuliprc_str)
405+
(
406+
check_for_default_zuliprc()
407+
if zuliprc_str == ""
408+
else path.expanduser(zuliprc_str)
409+
)
410+
if not new_realm
411+
else ""
395412
)
396413
while zuliprc_path == "" or not path.exists(zuliprc_path):
397414
try:
398-
zuliprc_path = fetch_zuliprc(zuliprc_path)
415+
zuliprc_path = fetch_zuliprc(zuliprc_path, new_realm)
399416
# Invalid user inputs (e.g. pressing arrow keys) may cause ValueError
400417
except (OSError, ValueError):
401418
# Remove zuliprc file if created.
@@ -552,7 +569,7 @@ def main(options: Optional[List[str]] = None) -> None:
552569
)
553570

554571
try:
555-
zterm, zuliprc_path = parse_zuliprc(zuliprc_path)
572+
zterm, zuliprc_path = parse_zuliprc(zuliprc_path, args.new_organization)
556573

557574
### Validate footlinks settings (not from command line)
558575
if (

0 commit comments

Comments
 (0)