Implemented 'rm' and 'rmdir' commands

This commit is contained in:
Jakob Friedl
2025-07-08 21:09:50 +02:00
parent 92da6f1288
commit 4a5f3baaa4
5 changed files with 111 additions and 0 deletions

View File

@@ -52,3 +52,36 @@ proc taskListDirectory*(cq: Conquest, arguments: seq[string]) =
cq.writeLine(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, fmt"Tasked agent to list files and directories.")
proc taskRemoveFile*(cq: Conquest, arguments: seq[string]) =
# Create a new task
let
date: string = now().format("dd-MM-yyyy HH:mm:ss")
task = Task(
id: generate(alphabet=join(toSeq('A'..'Z'), ""), size=8),
agent: cq.interactAgent.name,
command: RemoveFile,
args: arguments,
)
# Add new task to the agent's task queue
cq.interactAgent.tasks.add(task)
cq.writeLine(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, fmt"Tasked agent to remove file.")
proc taskRemoveDirectory*(cq: Conquest, arguments: seq[string]) =
# Create a new task
let
date: string = now().format("dd-MM-yyyy HH:mm:ss")
task = Task(
id: generate(alphabet=join(toSeq('A'..'Z'), ""), size=8),
agent: cq.interactAgent.name,
command: RemoveDirectory,
args: arguments,
)
# Add new task to the agent's task queue
cq.interactAgent.tasks.add(task)
cq.writeLine(fgBlack, styleBright, fmt"[{date}] [*] ", resetStyle, fmt"Tasked agent to remove directory.")

View File

@@ -31,6 +31,14 @@ var parser = newParser:
help("List files and directories.")
arg("directory", help="Relative or absolute path. Default: current working directory.", nargs = -1)
command("rm"):
help("Remove file.")
arg("file", help="Relative or absolute path to the file to delete.", nargs = -1)
command("rmdir"):
help("Remove directory.")
arg("directory", help="Relative or absolute path to the directory to delete.", nargs = -1)
command("help"):
nohelpflag()
@@ -78,6 +86,12 @@ proc handleAgentCommand*(cq: Conquest, args: varargs[string]) =
of "ls":
cq.taskListDirectory(opts.ls.get.directory)
of "rm":
cq.taskRemoveFile(opts.rm.get.file)
of "rmdir":
cq.taskRemoveDirectory(opts.rmdir.get.directory)
# Handle help flag
except ShortCircuit as err:
if err.flag == "argparse_help":

View File

@@ -18,6 +18,8 @@ type
GetWorkingDirectory = "pwd"
SetWorkingDirectory = "cd"
ListDirectory = "ls"
RemoveFile = "rm"
RemoveDirectory = "rmdir"
TaskStatus* = enum
Completed = "completed"