2021-11-04 22:04:21 +00:00
|
|
|
use crate::inc::SemVerAction;
|
|
|
|
use crate::Inc;
|
2021-12-05 03:11:19 +00:00
|
|
|
use nu_plugin::{EvaluatedCall, LabeledError, Plugin};
|
2022-03-22 18:32:03 +00:00
|
|
|
use nu_protocol::{ast::CellPath, Signature, SyntaxShape, Value};
|
2021-11-04 22:04:21 +00:00
|
|
|
|
|
|
|
impl Plugin for Inc {
|
|
|
|
fn signature(&self) -> Vec<Signature> {
|
|
|
|
vec![Signature::build("inc")
|
2022-03-27 19:25:30 +00:00
|
|
|
.usage("Increment a value or version. Optionally use the column of a table.")
|
2022-03-22 18:32:03 +00:00
|
|
|
.optional("cell_path", SyntaxShape::CellPath, "cell path to update")
|
2020-02-12 02:24:31 +00:00
|
|
|
.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'),
|
2021-11-04 22:04:21 +00:00
|
|
|
)]
|
|
|
|
}
|
|
|
|
|
2021-12-02 05:42:56 +00:00
|
|
|
fn run(
|
|
|
|
&mut self,
|
|
|
|
name: &str,
|
|
|
|
call: &EvaluatedCall,
|
|
|
|
input: &Value,
|
2021-12-05 03:11:19 +00:00
|
|
|
) -> Result<Value, LabeledError> {
|
2021-11-04 22:04:21 +00:00
|
|
|
if name != "inc" {
|
2021-12-19 07:46:13 +00:00
|
|
|
return Ok(Value::Nothing { span: call.head });
|
2021-11-04 22:04:21 +00:00
|
|
|
}
|
|
|
|
|
2022-03-22 18:32:03 +00:00
|
|
|
let cell_path: Option<CellPath> = call.opt(0)?;
|
|
|
|
|
|
|
|
self.cell_path = cell_path;
|
|
|
|
|
2021-11-04 22:04:21 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-12-02 23:11:25 +00:00
|
|
|
self.inc(call.head, input)
|
2019-12-29 05:17:24 +00:00
|
|
|
}
|
|
|
|
}
|