Skip to content

Commit bc9df22

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 7643361 commit bc9df22

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

tests/cli/test_run.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
157157
action="store_true",
158158
help="list all the organizations that you have configurations for, and exit",
159159
)
160+
parser.add_argument(
161+
"-n",
162+
"--new-organization",
163+
action="store_true",
164+
help="login to a new organization",
165+
)
160166
parser.add_argument(
161167
"--theme",
162168
"-t",
@@ -294,7 +300,7 @@ def get_api_key(realm_url: str) -> Optional[Tuple[str, str, str, str]]:
294300
return None
295301

296302

297-
def fetch_zuliprc(zuliprc_path: str) -> str:
303+
def fetch_zuliprc(zuliprc_path: str, new_realm: bool) -> str:
298304
supported_locations = [
299305
ZULIP_CONFIG_PATH,
300306
HOME_PATH_ZULIPRC,
@@ -305,8 +311,13 @@ def fetch_zuliprc(zuliprc_path: str) -> str:
305311
if zuliprc_path != ""
306312
else "any of the following locations:\n " + "\n ".join(supported_locations)
307313
)
314+
missing_zuliprc_text = (
315+
""
316+
if new_realm
317+
else f"{in_color('red', f'zuliprc file was not found at {locations_checked}')}"
318+
)
308319
print(
309-
f"{in_color('red', f'zuliprc file was not found at {locations_checked}')}"
320+
f"{missing_zuliprc_text}"
310321
f"\nPlease enter your credentials to login into your Zulip organization."
311322
f"\n"
312323
f"\nNOTE: The {in_color('blue', 'Zulip server URL')}"
@@ -392,15 +403,21 @@ def check_for_default_zuliprc() -> str:
392403
return ""
393404

394405

395-
def parse_zuliprc(zuliprc_str: str) -> Tuple[Dict[str, SettingData], str]:
406+
def parse_zuliprc(
407+
zuliprc_str: str, new_realm: bool
408+
) -> Tuple[Dict[str, SettingData], str]:
396409
zuliprc_path = (
397-
check_for_default_zuliprc()
398-
if zuliprc_str == ""
399-
else path.expanduser(zuliprc_str)
410+
(
411+
check_for_default_zuliprc()
412+
if zuliprc_str == ""
413+
else path.expanduser(zuliprc_str)
414+
)
415+
if not new_realm
416+
else ""
400417
)
401418
while zuliprc_path == "" or not path.exists(zuliprc_path):
402419
try:
403-
zuliprc_path = fetch_zuliprc(zuliprc_path)
420+
zuliprc_path = fetch_zuliprc(zuliprc_path, new_realm)
404421
# Invalid user inputs (e.g. pressing arrow keys) may cause ValueError
405422
except (OSError, ValueError):
406423
# Remove zuliprc file if created.
@@ -559,7 +576,7 @@ def main(options: Optional[List[str]] = None) -> None:
559576
)
560577

561578
try:
562-
zterm, zuliprc_path = parse_zuliprc(zuliprc_path)
579+
zterm, zuliprc_path = parse_zuliprc(zuliprc_path, args.new_organization)
563580

564581
### Validate footlinks settings (not from command line)
565582
if (

0 commit comments

Comments
 (0)