You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not 100% opposed to the idea, but I like to typically think that it's outside the scope of Cyclopts. For example, for most interactive CLI prompts, I would recommend using questionary. However, this isn't 100% in the scope of questionary either.
With all that said, I took a brief look at Click's edit function, and I'm not sure why it's so complicated. I think below is a "good enough" implementation, but let me know what you think! I also have not really ever implemented this in my own CLIs before, so let me know if there are tweaks that can make it a bit more ergonomic.
importtempfileimportsubprocessimportosfrompathlibimportPathclassDidNotSaveError(Exception):
"""User did not save upon exiting."""defedit(initial_text="", default_editor="vim", save=True):
"""Get text input from a user via their default editor."""editor=os.environ.get("EDITOR", default_editor)
withtempfile.NamedTemporaryFile(suffix=".txt", mode="w", delete=False) astf:
path=Path(tf.name)
tf.write(initial_text)
start_mtime=path.stat().st_mtimetry:
subprocess.call([editor, path])
end_mtime=path.stat().st_mtimeifsaveandend_mtime<=start_mtime:
raiseDidNotSaveErroredited_text=path.read_text()
finally:
path.unlink()
returnedited_textresult=edit()
print(f"{result=}")
Click has the functionality for opening an editor. It would be nice to have that available in Cyclopts as well.
The text was updated successfully, but these errors were encountered: