Skip to content

Commit

Permalink
File Write Tome (#712)
Browse files Browse the repository at this point in the history
* added the tome and tested it

* remove colon
  • Loading branch information
Cictrone authored Mar 15, 2024
1 parent 91052d1 commit 3192f98
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tavern/tomes/file_write/main.eldritch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

def main():
new_file_path = input_params['path']
new_file_parent_dir = file.parent_dir(new_file_path)
new_file_content = input_params['content']

# if file parent directory does not exist, error and exit.
if not file.exists(new_file_parent_dir):
eprint(f"[ERROR] Parent Directory for File does not exist at path: '{new_file_path}'.")
eprint(f"[ERROR] Exiting...")
return

# if file exists, remove it.
if file.exists(new_file_path):
print("[INFO] File was detected at the path before write. Trying to remove the file...")
file.remove(new_file_path)
print("[INFO] File was successfully removed!")

# if unable to write to destination will error
file.write(new_file_path, new_file_content)

# Print a Success!
print(f"[INFO] The file '{new_file_path}' was successfully written!")


main()
14 changes: 14 additions & 0 deletions tavern/tomes/file_write/metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Write File
description: Write the given utf-8 content to a file
author: cictrone
support_model: FIRST_PARTY
tactic: EXECUTION
paramdefs:
- name: path
type: string
label: File path
placeholder: "/tmp/cat.txt"
- name: content
type: string
label: Content to write
placeholder: "meow"

0 comments on commit 3192f98

Please sign in to comment.