Skip to main content

command_stream/commands/
pwd.rs

1//! Virtual `pwd` command implementation
2
3use crate::commands::CommandContext;
4use crate::utils::CommandResult;
5use std::env;
6
7/// Execute the pwd command
8///
9/// Prints the current working directory.
10pub async fn pwd(_ctx: CommandContext) -> CommandResult {
11    match env::current_dir() {
12        Ok(path) => CommandResult::success(format!("{}\n", path.display())),
13        Err(e) => CommandResult::error(format!("pwd: {}\n", e)),
14    }
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20
21    #[tokio::test]
22    async fn test_pwd() {
23        let ctx = CommandContext::new(vec![]);
24        let result = pwd(ctx).await;
25        assert!(result.is_success());
26        assert!(!result.stdout.is_empty());
27    }
28}