Skip to content

Commit 37bfdcb

Browse files
committed
update: staging command
1 parent 1b5df94 commit 37bfdcb

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

transcriptic/cli.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,19 @@ def launch_cmd(
606606
save_preview=save_preview,
607607
)
608608

609+
@cli.command("env")
610+
@click.argument("organization", metavar="ORGANIZATION_NAME", type=str, required=False)
611+
@click.argument("env", metavar="EMV_NAME", type=str, required=False)
612+
@click.pass_context
613+
def env_cmd(ctx, organization=None, env=None):
614+
"""Allows you to switch organizations. If the organization argument
615+
is provided, this will directly select the specified organization.
616+
"""
617+
api = ctx.obj.api
618+
config = ctx.parent.params["config"]
619+
commands.env(api, config, organization, env)
620+
621+
609622

610623
@cli.command("select-org")
611624
@click.argument("organization", metavar="ORGANIZATION_NAME", type=str, required=False)

transcriptic/commands.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import json
1111
import locale
1212
import os
13+
import random
1314
import re
1415
import sys
1516
import time
@@ -1013,6 +1014,7 @@ def launch(
10131014
)
10141015
run_id = req_json["id"]
10151016
formatted_url = api.url(f"{project}/runs/{run_id}")
1017+
click.echo(f"\nLR id: {req_id}")
10161018
click.echo(f"\nRun created: {formatted_url}")
10171019
return formatted_url
10181020
except Exception as err:
@@ -1066,6 +1068,38 @@ def select_org(api, config, organization=None):
10661068
click.echo(f"Logged in with organization: {organization}")
10671069

10681070

1071+
def env(
1072+
api,
1073+
config,
1074+
organization=None,
1075+
env=None,
1076+
):
1077+
env_root = env_prompt(env)
1078+
api.api_root = env_root
1079+
api.save(config)
1080+
1081+
click.echo('\n')
1082+
1083+
try:
1084+
org_list = [
1085+
{"name": org["name"], "subdomain": org["subdomain"]}
1086+
for org in api.organizations()
1087+
]
1088+
if organization is None:
1089+
organization = org_prompt(org_list)
1090+
except:
1091+
organization = api.organization_id
1092+
1093+
r = api.get_organization(org_id=organization)
1094+
if r.status_code != 200:
1095+
click.echo(f"Error accessing organization: {r.text}")
1096+
sys.exit(1)
1097+
1098+
api.organization_id = organization
1099+
api.save(config)
1100+
click.echo(f"Logged in with organization: {env_root}/{organization}")
1101+
1102+
10691103
def login(api, config, api_root=None, analytics=True, rsa_key=None):
10701104
"""Authenticate to your Transcriptic account."""
10711105
if api_root is None:
@@ -1318,6 +1352,64 @@ def _get_quick_launch(api, protocol, project):
13181352
return quick_launch
13191353

13201354

1355+
def env_prompt(env=None):
1356+
""""""
1357+
# "😺", "🐵", "🙈", "🙉", "🙊", "🐒",
1358+
rand = [
1359+
"(੭。╹▿╹。)੭",
1360+
" (੭ˊᵕˋ)੭ ",
1361+
" ( *◑∇◑)☞",
1362+
" ( ^o^)ノ",
1363+
" ₍ᐢ. ̫.ᐢ₎",
1364+
"づ ᴗ _ᴗ)づ",
1365+
" ՞•ﻌ•՞ฅ ",
1366+
" ⑅ᐢ..ᐢ ",
1367+
" ʕ·ᴥ·ʔ ",
1368+
" ᐡ ᐧ ﻌ ᐧ ᐡ ",
1369+
" ₍˄·͈༝·͈˄ ",
1370+
"૮ ˶ᵔ ᵕ ᵔ˶ ა",
1371+
"(* °ヮ° *) ",
1372+
" (ˊ•͈ ◡ •͈ˋ) "
1373+
]
1374+
envs = {
1375+
"PROD": "https://secure.strateos.com",
1376+
"STAGING": "https://webapp.staging.strateos.com",
1377+
"LOCAL": "http://localhost:5000",
1378+
# "DOCKER": "http://host.docker.internal:5000"
1379+
}
1380+
1381+
def parse_valid_env(env_str, envs):
1382+
try:
1383+
if env_str not in envs.keys():
1384+
raise ValueError(
1385+
f'Environment "{env_str}" selected not in: {list(envs.keys())}')
1386+
else:
1387+
return env_str
1388+
except:
1389+
raise BadParameter(
1390+
f"Please enter one of the following {envs.keys()}"
1391+
)
1392+
1393+
if env is None:
1394+
click.echo("Select the which ENV you want to point to:")
1395+
env_map = []
1396+
for name, endpoint in envs.items():
1397+
env_map.append(name)
1398+
click.echo(f"{random.choice(rand)}\t{name}\t{endpoint}")
1399+
1400+
1401+
selected_env = click.prompt(
1402+
"Which ENV would you like to configure your session with",
1403+
default='STAGING',
1404+
prompt_suffix="? ",
1405+
type=str,
1406+
value_proc=lambda x: parse_valid_env(x, envs),
1407+
)
1408+
else:
1409+
selected_env = parse_valid_env(env, envs)
1410+
return envs[selected_env]
1411+
1412+
13211413
def org_prompt(org_list):
13221414
"""Organization prompt for helping with selecting organization"""
13231415
if len(org_list) < 1:

0 commit comments

Comments
 (0)