Skip to content

Commit

Permalink
refactor: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tecoholic authored and Arunmozhi committed Sep 2, 2024
1 parent 6e5d054 commit c095e45
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tutor/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,21 @@ def patches_list(context: Context) -> None:
@click.command(name="edit", help="Edit config.yml of the current environment")
@click.pass_obj
def edit(context: Context) -> None:
config_file = os.path.join(context.root, "config.yml")
config_file = tutor_config.config_path(context.root)

if not os.path.isfile(config_file):
raise exceptions.TutorError(f"Missing config file at {config_file}")

open_cmd = None

if which("open"): # MacOS
if which("open"): # MacOS & linux distributions that ship `open`. eg., Ubuntu
open_cmd = ["open", config_file]
elif which("xdg-open"): # Linux
open_cmd = ["xdg-open", config_file]
elif which("start"): # Windows
open_cmd = ["start", '""', config_file]
else:
click.echo(
"Cannot find a way to open the editor automatically. Kindly open the file manually: "
+ config_file
)
return
raise exceptions.TutorError(f"Failed to find utility to launch an editor.")

subprocess.call(open_cmd)

Expand Down

0 comments on commit c095e45

Please sign in to comment.