#pragma once #include #include #include #include #include #include #include namespace sh { enum class Command { exit, echo, type, pwd, cd, unknown }; inline const std::mapcommandMap { {"exit", Command::exit}, {"echo", Command::echo}, {"type", Command::type}, {"pwd" , Command::pwd }, {"cd" , Command::cd } }; inline constexpr std::string_view doubleQuoteEscapeChars = "\"$`\n\\"; inline constexpr std::string_view tokenDelimiters = " \t"; void tokenize(std::vector& tokens, const std::string& input); Command getCommand(std::string_view input); std::optional isExec(const std::string& input); void printType(const std::string& input, const std::optional& stdoutFilePath = std::nullopt); std::filesystem::path getWorkingDir(); void changeDir(const std::vector& tokens, const std::optional& stdoutFilePath = std::nullopt); void printCommandStdout(std::string_view input, const std::optional& outputFilePath = std::nullopt, bool append = false); void printCommandStderr(std::string_view input, const std::optional& outputFilePath = std::nullopt, bool append = false); void executeCommand(const std::filesystem::path& exePath, const std::vector& tokens, const std::optional& stdoutFilePath = std::nullopt, const std::optional& stderrFilePath = std::nullopt, bool appendStdout = false, bool appendStderr = false); }