Skip to content

Commit

Permalink
feat: adds tutor config edit
Browse files Browse the repository at this point in the history
Quickly launch the default YAML editor for editing
the config.yml file.
  • Loading branch information
tecoholic committed Jul 24, 2024
1 parent 53cffff commit ecf0b53
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tutor/commands/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from __future__ import annotations

import json
import os.path
import subprocess
import typing as t

import click
import click.shell_completion

from shutil import which

from tutor import config as tutor_config
from tutor import env, exceptions, fmt
from tutor import interactive as interactive_config
Expand Down Expand Up @@ -220,8 +224,32 @@ def patches_list(context: Context) -> None:
renderer.print_patches_locations()


@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")

open_cmd = None

if which("open"): # MacOS
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

subprocess.call(open_cmd)


config_command.add_command(save)
config_command.add_command(printroot)
config_command.add_command(printvalue)
patches_command.add_command(patches_list)
config_command.add_command(patches_command)
config_command.add_command(edit)

0 comments on commit ecf0b53

Please sign in to comment.