summaryrefslogtreecommitdiff
path: root/commands/src/cd.rs
blob: efcd1747e19a17ab1a91ccc5bf369c21374bc252 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use toolkit::Toolkit;
use toolkit::error::*;
use crate::parser::Command;

pub fn run(tk: &mut Toolkit, command: Command) {
    if command.names.len() == 1 {
        let path = tk.resolve_path(&command.names[0]);

        if tk.file_exists(&path) {
            if tk.is_dir(&path) {
                tk.chdir(&path);
            } else {
                display_error(tk, Error::E09);
            }
        } else {
            display_error(tk, Error::E04);
        }
    } else if command.names.is_empty() {
        display_error(tk, Error::E03);
    } else if command.names.len() > 1 {
        display_error(tk, Error::E08);
    }
}