Files
nushell/crates/nu_plugin_inc/src/nu/mod.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

74 lines
1.9 KiB
Rust

use crate::{inc::SemVerAction, Inc};
use nu_plugin::{EngineInterface, EvaluatedCall, Plugin, PluginCommand, SimplePluginCommand};
use nu_protocol::{ast::CellPath, LabeledError, Signature, SyntaxShape, Value};
pub struct IncPlugin;
impl Plugin for IncPlugin {
fn version(&self) -> String {
env!("CARGO_PKG_VERSION").into()
}
fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
vec![Box::new(Inc::new())]
}
}
impl SimplePluginCommand for Inc {
type Plugin = IncPlugin;
fn name(&self) -> &str {
"inc"
}
fn description(&self) -> &str {
"Increment a value or version. Optionally use the column of a table."
}
fn signature(&self) -> Signature {
Signature::build(PluginCommand::name(self))
.optional("cell_path", SyntaxShape::CellPath, "cell path to update")
.switch(
"major",
"increment the major version (eg 1.2.1 -> 2.0.0)",
Some('M'),
)
.switch(
"minor",
"increment the minor version (eg 1.2.1 -> 1.3.0)",
Some('m'),
)
.switch(
"patch",
"increment the patch version (eg 1.2.1 -> 1.2.2)",
Some('p'),
)
}
fn run(
&self,
_plugin: &IncPlugin,
_engine: &EngineInterface,
call: &EvaluatedCall,
input: &Value,
) -> Result<Value, LabeledError> {
let mut inc = self.clone();
let cell_path: Option<CellPath> = call.opt(0)?;
inc.cell_path = cell_path;
if call.has_flag("major")? {
inc.for_semver(SemVerAction::Major);
}
if call.has_flag("minor")? {
inc.for_semver(SemVerAction::Minor);
}
if call.has_flag("patch")? {
inc.for_semver(SemVerAction::Patch);
}
inc.inc(call.head, input)
}
}