add raw `export` command

This commit is contained in:
Maximilian Hils 2021-08-12 10:19:49 +02:00
parent 8866cc31bd
commit f8b4c7bd44
1 changed files with 11 additions and 5 deletions

View File

@ -182,12 +182,18 @@ class Export:
"""
Export a flow to the system clipboard.
"""
try:
pyperclip.copy(self.export_str(format, f))
except pyperclip.PyperclipException as e:
ctx.log.error(str(e))
@command.command("export")
def export_str(self, format: str, f: flow.Flow) -> str:
"""
Export a flow and return the result.
"""
if format not in formats:
raise exceptions.CommandError("No such export format: %s" % format)
func = formats[format]
val = strutils.always_str(func(f), "utf8", "backslashreplace")
try:
pyperclip.copy(val)
except pyperclip.PyperclipException as e:
ctx.log.error(str(e))
return strutils.always_str(func(f), "utf8", "backslashreplace")