Skip to content

Commit 80f5451

Browse files
committed
run: Add -o argument to list realms with stored zuliprc.
Tests updated.
1 parent d553952 commit 80f5451

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tests/cli/test_run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def test_main_help(capsys: CaptureFixture[str], options: str) -> None:
133133
"--theme THEME, -t THEME",
134134
"-h, --help",
135135
"-d, --debug",
136+
"-o, --list-organizations",
136137
"--list-themes",
137138
"--profile",
138139
"--config-file CONFIG_FILE, -c CONFIG_FILE",

zulipterminal/cli/run.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
150150
help="config file downloaded from your zulip "
151151
"organization (default: ~/zuliprc)",
152152
)
153+
parser.add_argument(
154+
"-o",
155+
"--list-organizations",
156+
action="store_true",
157+
help="list all the organizations that you have configurations for, and exit",
158+
)
153159
parser.add_argument(
154160
"--theme",
155161
"-t",
@@ -455,6 +461,16 @@ def list_themes() -> str:
455461
)
456462

457463

464+
def list_realms() -> str:
465+
valid_orgs = [
466+
file.parent.name for file in Path(ZULIP_CONFIG_PATH).glob("*/zuliprc")
467+
]
468+
if len(valid_orgs) == 0:
469+
exit_with_error("No organizations found in zuliprc config folder.")
470+
text = "The following organizations are available:\n "
471+
return text + "\n ".join(valid_orgs)
472+
473+
458474
def path_to_realm_zuliprc(realm_name_prefix: str) -> str:
459475
if len(realm_name_prefix) < 3:
460476
exit_with_error("Organization name prefix must be at least 3 characters long")
@@ -513,6 +529,10 @@ def main(options: Optional[List[str]] = None) -> None:
513529
print(f"Zulip Terminal {ZT_VERSION}")
514530
sys.exit(0)
515531

532+
if args.list_organizations:
533+
print(list_realms())
534+
sys.exit(0)
535+
516536
if args.list_themes:
517537
print(list_themes())
518538
sys.exit(0)

0 commit comments

Comments
 (0)