nushell on your web browser
nushell wasm terminal
at main 1.3 kB view raw
1use crate::{error::to_shell_err, globals::get_pwd}; 2use nu_engine::CallExt; 3use nu_protocol::{ 4 Category, PipelineData, ShellError, Signature, SyntaxShape, Type, 5 engine::{Command, EngineState, Stack}, 6}; 7 8#[derive(Clone)] 9pub struct Mkdir; 10 11impl Command for Mkdir { 12 fn name(&self) -> &str { 13 "mkdir" 14 } 15 16 fn signature(&self) -> Signature { 17 Signature::build("mkdir") 18 .required( 19 "path", 20 SyntaxShape::Filepath, 21 "path of the directory(s) to create", 22 ) 23 .input_output_type(Type::Nothing, Type::Nothing) 24 .category(Category::FileSystem) 25 } 26 27 fn description(&self) -> &str { 28 "create a directory in the virtual filesystem." 29 } 30 31 fn run( 32 &self, 33 engine_state: &EngineState, 34 stack: &mut Stack, 35 call: &nu_protocol::engine::Call, 36 _: PipelineData, 37 ) -> Result<PipelineData, ShellError> { 38 let path: String = call.req(engine_state, stack, 0)?; 39 let new_dir = get_pwd() 40 .join(path.trim_end_matches('/')) 41 .map_err(to_shell_err(call.head))?; 42 new_dir 43 .create_dir_all() 44 .map_err(to_shell_err(call.head)) 45 .map(|_| PipelineData::Empty) 46 } 47}