Bump to 0.60 (#4892)

* WIP

* semi-revert metadata change
This commit is contained in:
JT
2022-03-23 07:32:03 +13:00
committed by GitHub
parent 352cf31db2
commit 1c964cdfe7
53 changed files with 237 additions and 1425 deletions

View File

@ -1,5 +1,5 @@
use nu_plugin::LabeledError;
use nu_protocol::{Span, Value};
use nu_protocol::{ast::CellPath, Span, Value};
#[derive(Debug, Eq, PartialEq)]
pub enum Action {
@ -17,6 +17,7 @@ pub enum SemVerAction {
#[derive(Default)]
pub struct Inc {
pub error: Option<String>,
pub cell_path: Option<CellPath>,
pub action: Option<Action>,
}
@ -83,6 +84,26 @@ impl Inc {
}
pub fn inc(&self, head: Span, value: &Value) -> Result<Value, LabeledError> {
if let Some(cell_path) = &self.cell_path {
let working_value = value.clone();
let cell_value = working_value.follow_cell_path(&cell_path.members)?;
let cell_value = self.inc_value(head, &cell_value)?;
let mut value = value.clone();
value
.update_data_at_cell_path(&cell_path.members, cell_value)
.map_err(|x| {
let error: LabeledError = x.into();
error
})?;
Ok(value)
} else {
self.inc_value(head, value)
}
}
pub fn inc_value(&self, head: Span, value: &Value) -> Result<Value, LabeledError> {
match value {
Value::Int { val, span } => Ok(Value::Int {
val: val + 1,

View File

@ -1,6 +1,6 @@
use nu_plugin::{serve_plugin, CapnpSerializer};
use nu_plugin::{serve_plugin, JsonSerializer};
use nu_plugin_inc::Inc;
fn main() {
serve_plugin(&mut Inc::new(), CapnpSerializer {})
serve_plugin(&mut Inc::new(), JsonSerializer {})
}

View File

@ -1,12 +1,13 @@
use crate::inc::SemVerAction;
use crate::Inc;
use nu_plugin::{EvaluatedCall, LabeledError, Plugin};
use nu_protocol::{Signature, Value};
use nu_protocol::{ast::CellPath, Signature, SyntaxShape, 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.")
.optional("cell_path", SyntaxShape::CellPath, "cell path to update")
.switch(
"major",
"increment the major version (eg 1.2.1 -> 2.0.0)",
@ -34,6 +35,10 @@ impl Plugin for Inc {
return Ok(Value::Nothing { span: call.head });
}
let cell_path: Option<CellPath> = call.opt(0)?;
self.cell_path = cell_path;
if call.has_flag("major") {
self.for_semver(SemVerAction::Major);
}