nushell/crates/nu-command/src/filesystem/umkdir.rs
Stefan Holderbach 95b78eee25
Change the usage misnomer to "description" (#13598)
# Description
    
The meaning of the word usage is specific to describing how a command
function is *used* and not a synonym for general description. Usage can
be used to describe the SYNOPSIS or EXAMPLES sections of a man page
where the permitted argument combinations are shown or example *uses*
are given.
Let's not confuse people and call it what it is a description.

Our `help` command already creates its own *Usage* section based on the
available arguments and doesn't refer to the description with usage.

# User-Facing Changes

`help commands` and `scope commands` will now use `description` or
`extra_description`
`usage`-> `description`
`extra_usage` -> `extra_description`

Breaking change in the plugin protocol:

In the signature record communicated with the engine.
`usage`-> `description`
`extra_usage` -> `extra_description`

The same rename also takes place for the methods on
`SimplePluginCommand` and `PluginCommand`

# Tests + Formatting
- Updated plugin protocol specific changes
# After Submitting
- [ ] update plugin protocol doc
2024-08-22 12:02:08 +02:00

108 lines
2.9 KiB
Rust

#[allow(deprecated)]
use nu_engine::{command_prelude::*, current_dir};
use uu_mkdir::mkdir;
#[cfg(not(windows))]
use uucore::mode;
use super::util::get_rest_for_glob_pattern;
#[derive(Clone)]
pub struct UMkdir;
const IS_RECURSIVE: bool = true;
const DEFAULT_MODE: u32 = 0o777;
#[cfg(not(windows))]
fn get_mode() -> u32 {
!mode::get_umask() & DEFAULT_MODE
}
#[cfg(windows)]
fn get_mode() -> u32 {
DEFAULT_MODE
}
impl Command for UMkdir {
fn name(&self) -> &str {
"mkdir"
}
fn description(&self) -> &str {
"Create directories, with intermediary directories if required using uutils/coreutils mkdir."
}
fn search_terms(&self) -> Vec<&str> {
vec!["directory", "folder", "create", "make_dirs", "coreutils"]
}
fn signature(&self) -> Signature {
Signature::build("mkdir")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.rest(
"rest",
SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::Directory]),
"The name(s) of the path(s) to create.",
)
.switch(
"verbose",
"print a message for each created directory.",
Some('v'),
)
.category(Category::FileSystem)
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
#[allow(deprecated)]
let cwd = current_dir(engine_state, stack)?;
let mut directories = get_rest_for_glob_pattern(engine_state, stack, call, 0)?
.into_iter()
.map(|dir| nu_path::expand_path_with(dir.item.as_ref(), &cwd, dir.item.is_expand()))
.peekable();
let is_verbose = call.has_flag(engine_state, stack, "verbose")?;
if directories.peek().is_none() {
return Err(ShellError::MissingParameter {
param_name: "requires directory paths".to_string(),
span: call.head,
});
}
for dir in directories {
if let Err(error) = mkdir(&dir, IS_RECURSIVE, get_mode(), is_verbose) {
return Err(ShellError::GenericError {
error: format!("{}", error),
msg: format!("{}", error),
span: None,
help: None,
inner: vec![],
});
}
}
Ok(PipelineData::empty())
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Make a directory named foo",
example: "mkdir foo",
result: None,
},
Example {
description: "Make multiple directories and show the paths created",
example: "mkdir -v foo/bar foo2",
result: None,
},
]
}
}