Skip to content

Commit

Permalink
run: Add -o argument to list realms with stored zuliprc.
Browse files Browse the repository at this point in the history
Tests updated.
  • Loading branch information
Niloth-p committed Jun 11, 2024
1 parent d553952 commit 80f5451
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def test_main_help(capsys: CaptureFixture[str], options: str) -> None:
"--theme THEME, -t THEME",
"-h, --help",
"-d, --debug",
"-o, --list-organizations",
"--list-themes",
"--profile",
"--config-file CONFIG_FILE, -c CONFIG_FILE",
Expand Down
20 changes: 20 additions & 0 deletions zulipterminal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
help="config file downloaded from your zulip "
"organization (default: ~/zuliprc)",
)
parser.add_argument(
"-o",
"--list-organizations",
action="store_true",
help="list all the organizations that you have configurations for, and exit",
)
parser.add_argument(
"--theme",
"-t",
Expand Down Expand Up @@ -455,6 +461,16 @@ def list_themes() -> str:
)


def list_realms() -> str:
valid_orgs = [
file.parent.name for file in Path(ZULIP_CONFIG_PATH).glob("*/zuliprc")
]
if len(valid_orgs) == 0:
exit_with_error("No organizations found in zuliprc config folder.")
text = "The following organizations are available:\n "
return text + "\n ".join(valid_orgs)


def path_to_realm_zuliprc(realm_name_prefix: str) -> str:
if len(realm_name_prefix) < 3:
exit_with_error("Organization name prefix must be at least 3 characters long")
Expand Down Expand Up @@ -513,6 +529,10 @@ def main(options: Optional[List[str]] = None) -> None:
print(f"Zulip Terminal {ZT_VERSION}")
sys.exit(0)

if args.list_organizations:
print(list_realms())
sys.exit(0)

if args.list_themes:
print(list_themes())
sys.exit(0)
Expand Down

0 comments on commit 80f5451

Please sign in to comment.