Skip to content

Commit 785b58c

Browse files
committed
Add concore editor to CLI
1 parent 7c5ea5b commit 785b58c

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

concore_cli/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,16 @@ 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+
launch_editor()
175+
except Exception as e:
176+
console.print(f"[red]Error:[/red] {str(e)}")
177+
sys.exit(1)
178+
179+
169180
if __name__ == "__main__":
170181
cli()

concore_cli/commands/editor.py

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

0 commit comments

Comments
 (0)