mirror of
https://github.com/cosmo-sims/cosmICweb-music.git
synced 2024-09-19 16:53:43 +02:00
use click to open editor
This commit is contained in:
parent
eed3641aa8
commit
9f9bb3fbd1
1 changed files with 4 additions and 13 deletions
|
@ -24,8 +24,6 @@ logger.setLevel("INFO")
|
||||||
|
|
||||||
# Some constants
|
# Some constants
|
||||||
DEFAULT_URL = "https://cosmicweb.eu"
|
DEFAULT_URL = "https://cosmicweb.eu"
|
||||||
EDITOR = os.environ.get("EDITOR", "vim")
|
|
||||||
EDITOR_IS_VIM = EDITOR in {"vim", "nvim"}
|
|
||||||
|
|
||||||
|
|
||||||
def query_yes_no(question: str, default="yes") -> bool:
|
def query_yes_no(question: str, default="yes") -> bool:
|
||||||
|
@ -176,17 +174,10 @@ def fetch_multiple(
|
||||||
|
|
||||||
|
|
||||||
def edit_template(template: str) -> str:
|
def edit_template(template: str) -> str:
|
||||||
with tempfile.NamedTemporaryFile(suffix=".tmp.conf", mode="r+") as tf:
|
return_value = click.edit(template, extension=".conf")
|
||||||
tf.write(template)
|
if return_value is None:
|
||||||
tf.flush()
|
return template
|
||||||
editor_parameters = []
|
return return_value
|
||||||
if EDITOR_IS_VIM:
|
|
||||||
# backupcopy=yes prevents vim from creating copy and rename
|
|
||||||
editor_parameters.append("+set backupcopy=yes")
|
|
||||||
subprocess.call([EDITOR] + editor_parameters + [tf.name])
|
|
||||||
tf.seek(0)
|
|
||||||
template = tf.read()
|
|
||||||
return template
|
|
||||||
|
|
||||||
|
|
||||||
def apply_config_parameter(config: str, parameters: dict[str, Any]) -> str:
|
def apply_config_parameter(config: str, parameters: dict[str, Any]) -> str:
|
||||||
|
|
Loading…
Reference in a new issue