From 29148c875681af6e762dbd8df391fc851c5c4b84 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Sun, 26 Nov 2023 19:12:09 -0800 Subject: [PATCH] [Teton] Add a cd command. --- sys/teton/terminal.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/teton/terminal.cpp b/sys/teton/terminal.cpp index 15561a4..208681f 100644 --- a/sys/teton/terminal.cpp +++ b/sys/teton/terminal.cpp @@ -25,10 +25,22 @@ void Terminal::ExecuteCommand(const glcr::String& command) { } glcr::StringView cmd = tokens[0]; if (cmd == "help") { - console_.WriteString("Available Commands: cwd\n"); + console_.WriteString("Available Commands: cwd cd ls\n"); } else if (cmd == "cwd") { console_.WriteString(cwd_); console_.WriteChar('\n'); + } else if (cmd == "cd") { + if (tokens.size() != 2) { + console_.WriteString("Provide an absolute path.\n>"); + return; + } + auto files_or = mmth::ListDirectory(tokens[1]); + if (files_or.ok()) { + cwd_ = tokens[1]; + } else { + console_.WriteString(glcr::StrFormat("Error: {}\n", files_or.error())); + } + } else if (cmd == "ls") { glcr::StringView directory; if (tokens.size() > 1) {