Skip to content

Commit 44d52f2

Browse files
committed
update: staging command
1 parent 35349e8 commit 44d52f2

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

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
@@ -1011,6 +1012,7 @@ def launch(
10111012
)
10121013
run_id = req_json["id"]
10131014
formatted_url = api.url(f"{project}/runs/{run_id}")
1015+
click.echo(f"\nLR id: {req_id}")
10141016
click.echo(f"\nRun created: {formatted_url}")
10151017
return formatted_url
10161018
except Exception as err:
@@ -1064,6 +1066,38 @@ def select_org(api, config, organization=None):
10641066
click.echo(f"Logged in with organization: {organization}")
10651067

10661068

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

13181352

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

0 commit comments

Comments
 (0)