Skip to content

Commit 91bd9d9

Browse files
authored
Merge pull request #515 from GREENRAT-K405/feat/concore-editor-cli
Add concore editor to CLI
2 parents 7c5ea5b + 98e1a6f commit 91bd9d9

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

concore_cli/cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,17 @@ def setup(dry_run, force):
166166
sys.exit(1)
167167

168168

169+
@cli.command()
170+
def editor():
171+
"""Launch concore-editor"""
172+
try:
173+
from .commands.editor import launch_editor
174+
175+
launch_editor()
176+
except Exception as e:
177+
console.print(f"[red]Error:[/red] {str(e)}")
178+
sys.exit(1)
179+
180+
169181
if __name__ == "__main__":
170182
cli()

concore_cli/commands/editor.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import sys
3+
import shutil
4+
import subprocess
5+
from rich.console import Console
6+
7+
console = Console()
8+
EDITOR_URL = "https://controlcore-project.github.io/concore-editor/"
9+
10+
11+
def open_editor_url(url):
12+
try:
13+
if sys.platform == "win32":
14+
os.system(f'start "" chrome "{url}"')
15+
else:
16+
if shutil.which("open"):
17+
if sys.platform == "darwin":
18+
subprocess.run(["open", "-a", "Google Chrome", url])
19+
elif sys.platform.startswith("linux"):
20+
subprocess.run(["xdg-open", url])
21+
else:
22+
if shutil.which("xdg-open"):
23+
subprocess.run(["xdg-open", url])
24+
else:
25+
console.print("unable to open browser for the concore editor.")
26+
except Exception as e:
27+
console.print(f"unable to open browser for the concore editor. ({e})")
28+
29+
30+
def launch_editor():
31+
console.print("[cyan]Opening concore-editor...[/cyan]")
32+
open_editor_url(EDITOR_URL)

0 commit comments

Comments
 (0)