Skip to content

Commit

Permalink
run: Add new argument --new--account to create a new account.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Niloth-p committed Aug 24, 2024
1 parent 817b46a commit 9681331
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def test_main_help(capsys: CaptureFixture[str], options: str) -> None:
"--theme THEME, -t THEME",
"-h, --help",
"-d, --debug",
"-n, --new-account",
"--list-accounts",
"--list-themes",
"--profile",
Expand Down
23 changes: 15 additions & 8 deletions zulipterminal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
help="specify the chosen alias of your zulip account "
"to fetch its configuration",
)
parser.add_argument(
"-n",
"--new-account",
action="store_true",
help="login to a new account",
)
parser.add_argument(
"--list-accounts",
action="store_true",
Expand Down Expand Up @@ -381,7 +387,7 @@ def _write_zuliprc(
return f"{ex.__class__.__name__}: zuliprc could not be created at {to_path}"


def resolve_to_valid_path(zuliprc_str: Optional[str]) -> str:
def resolve_to_valid_path(zuliprc_str: Optional[str], is_new_account: bool) -> str:
"""
Returns the path to a valid zuliprc file.
If a path is not provided by the user, searches the default locations.
Expand All @@ -394,12 +400,13 @@ def resolve_to_valid_path(zuliprc_str: Optional[str]) -> str:
else path.expanduser(zuliprc_str)
)
while zuliprc_path is None or not path.exists(zuliprc_path):
print(
f"{in_color('red', 'zuliprc file was not found')}"
f"{in_color('red', f' at {zuliprc_path}')}"
if zuliprc_path
else "."
)
if not is_new_account:
print(
f"{in_color('red', 'zuliprc file was not found')}"
f"{in_color('red', f' at {zuliprc_path}')}"
if zuliprc_path
else "."
)
try:
zuliprc_path = login_and_save()
# Invalid user inputs (e.g. pressing arrow keys) may cause ValueError
Expand Down Expand Up @@ -555,7 +562,7 @@ def main(options: Optional[List[str]] = None) -> None:
)
if args.config_file:
zuliprc_path = args.config_file
zuliprc_path = resolve_to_valid_path(zuliprc_path)
zuliprc_path = resolve_to_valid_path(zuliprc_path, args.new_account)

print(
"Detected:"
Expand Down

0 comments on commit 9681331

Please sign in to comment.