Skip to content

Commit 9681331

Browse files
committed
run: Add new argument --new--account to create a new account.
- If --new-account is used along with --config-file, - If the given path is valid, that zuliprc will be loaded - Else, a new account will be created, but not at the given path. - If --new-account is used along with account-alias, the new account argument will be ignored. Tests updated.
1 parent 817b46a commit 9681331

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

tests/cli/test_run.py

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def test_main_help(capsys: CaptureFixture[str], options: str) -> None:
135135
"--theme THEME, -t THEME",
136136
"-h, --help",
137137
"-d, --debug",
138+
"-n, --new-account",
138139
"--list-accounts",
139140
"--list-themes",
140141
"--profile",

zulipterminal/cli/run.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
141141
help="specify the chosen alias of your zulip account "
142142
"to fetch its configuration",
143143
)
144+
parser.add_argument(
145+
"-n",
146+
"--new-account",
147+
action="store_true",
148+
help="login to a new account",
149+
)
144150
parser.add_argument(
145151
"--list-accounts",
146152
action="store_true",
@@ -381,7 +387,7 @@ def _write_zuliprc(
381387
return f"{ex.__class__.__name__}: zuliprc could not be created at {to_path}"
382388

383389

384-
def resolve_to_valid_path(zuliprc_str: Optional[str]) -> str:
390+
def resolve_to_valid_path(zuliprc_str: Optional[str], is_new_account: bool) -> str:
385391
"""
386392
Returns the path to a valid zuliprc file.
387393
If a path is not provided by the user, searches the default locations.
@@ -394,12 +400,13 @@ def resolve_to_valid_path(zuliprc_str: Optional[str]) -> str:
394400
else path.expanduser(zuliprc_str)
395401
)
396402
while zuliprc_path is None or not path.exists(zuliprc_path):
397-
print(
398-
f"{in_color('red', 'zuliprc file was not found')}"
399-
f"{in_color('red', f' at {zuliprc_path}')}"
400-
if zuliprc_path
401-
else "."
402-
)
403+
if not is_new_account:
404+
print(
405+
f"{in_color('red', 'zuliprc file was not found')}"
406+
f"{in_color('red', f' at {zuliprc_path}')}"
407+
if zuliprc_path
408+
else "."
409+
)
403410
try:
404411
zuliprc_path = login_and_save()
405412
# Invalid user inputs (e.g. pressing arrow keys) may cause ValueError
@@ -555,7 +562,7 @@ def main(options: Optional[List[str]] = None) -> None:
555562
)
556563
if args.config_file:
557564
zuliprc_path = args.config_file
558-
zuliprc_path = resolve_to_valid_path(zuliprc_path)
565+
zuliprc_path = resolve_to_valid_path(zuliprc_path, args.new_account)
559566

560567
print(
561568
"Detected:"

0 commit comments

Comments
 (0)