Skip to content

Commit

Permalink
Merge pull request #14 from kodexa-ai/kodexa-profile
Browse files Browse the repository at this point in the history
Kodexa Profile Try-Except
  • Loading branch information
romekodexa authored Apr 3, 2024
2 parents a2f7a1e + 3694dfc commit b1a8356
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
13 changes: 10 additions & 3 deletions kodexa_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
}


def get_current_kodexa_profile():
try:
return KodexaPlatform.get_current_profile()
except:
return ""


def get_current_kodexa_url():
try:
return KodexaPlatform.get_url()
Expand Down Expand Up @@ -208,7 +215,7 @@ def safe_entry_point():
start_time = datetime.now().replace(microsecond=0)

try:
print(f"Using profile {KodexaPlatform.get_current_profile()} @ {get_current_kodexa_url()}\n")
print(f"Using profile {get_current_kodexa_profile()} @ {get_current_kodexa_url()}\n")
except:
print("Unable to load profile")

Expand Down Expand Up @@ -953,7 +960,7 @@ def platform(_: Info, python: bool, show_token: bool):
Get the details for the Kodexa instance we are logged into
"""

print(f"Profile: {KodexaPlatform.get_current_profile()}")
print(f"Profile: {get_current_kodexa_profile()}")
platform_url = get_current_kodexa_url()

if platform_url is not None:
Expand Down Expand Up @@ -1049,7 +1056,7 @@ def profile(_: Info, profile: str, delete: bool, list: bool):
print(f"Profiles: {','.join(KodexaPlatform.list_profiles())}")
else:
print(
f"Current profile: {KodexaPlatform.get_current_profile()} [{KodexaPlatform.get_url(KodexaPlatform.get_current_profile())}]")
f"Current profile: {get_current_kodexa_profile()} [{KodexaPlatform.get_url(get_current_kodexa_profile())}]")


@cli.command()
Expand Down
8 changes: 8 additions & 0 deletions tests/cli_runner_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from click.testing import CliRunner
from kodexa_cli.cli import get # replace this with the name of your module where configure command is defined
import os


def test_configure_command():
runner = CliRunner()
result = runner.invoke(get, ["org"])
11 changes: 11 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os, json

from appdirs import AppDirs

dirs = AppDirs("Kodexa", "Kodexa")

path = os.path.join(dirs.user_config_dir, ".kodexa.json")
if os.path.exists(path):
with open(path, "r") as outfile:
kodexa_config = json.load(outfile)
print(kodexa_config)

0 comments on commit b1a8356

Please sign in to comment.