mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 00:57:49 +02:00
simple inc plugin implementation
This commit is contained in:
47
crates/nu_plugin_inc/src/nu/mod.rs
Normal file
47
crates/nu_plugin_inc/src/nu/mod.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use crate::inc::SemVerAction;
|
||||
use crate::Inc;
|
||||
use nu_plugin::{plugin::PluginError, Plugin};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::{Signature, Span, Value};
|
||||
|
||||
impl Plugin for Inc {
|
||||
fn signature(&self) -> Vec<Signature> {
|
||||
vec![Signature::build("inc")
|
||||
.desc("Increment a value or version. Optionally use the column of a table.")
|
||||
.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(&mut self, name: &str, call: &Call, input: &Value) -> Result<Value, PluginError> {
|
||||
if name != "inc" {
|
||||
return Ok(Value::Nothing {
|
||||
span: Span::unknown(),
|
||||
});
|
||||
}
|
||||
|
||||
if call.has_flag("major") {
|
||||
self.for_semver(SemVerAction::Major);
|
||||
}
|
||||
if call.has_flag("minor") {
|
||||
self.for_semver(SemVerAction::Minor);
|
||||
}
|
||||
if call.has_flag("patch") {
|
||||
self.for_semver(SemVerAction::Patch);
|
||||
}
|
||||
|
||||
self.inc(input)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user