mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:05:01 +02:00
Category option for signature (#343)
* category option for signature * category option for signature * column description for $scope
This commit is contained in:
@ -1652,6 +1652,12 @@ pub mod signature {
|
||||
pub fn get_is_filter(self) -> bool {
|
||||
self.reader.get_bool_field(0)
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_category(
|
||||
self,
|
||||
) -> ::core::result::Result<crate::plugin_capnp::Category, ::capnp::NotInSchema> {
|
||||
::capnp::traits::FromU16::from_u16(self.reader.get_data_field::<u16>(1))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Builder<'a> {
|
||||
@ -1912,6 +1918,16 @@ pub mod signature {
|
||||
pub fn set_is_filter(&mut self, value: bool) {
|
||||
self.builder.set_bool_field(0, value);
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_category(
|
||||
self,
|
||||
) -> ::core::result::Result<crate::plugin_capnp::Category, ::capnp::NotInSchema> {
|
||||
::capnp::traits::FromU16::from_u16(self.builder.get_data_field::<u16>(1))
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_category(&mut self, value: crate::plugin_capnp::Category) {
|
||||
self.builder.set_data_field::<u16>(1, value as u16)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Pipeline {
|
||||
@ -1939,6 +1955,57 @@ pub mod signature {
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(u16)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Category {
|
||||
Default = 0,
|
||||
Conversions = 1,
|
||||
Core = 2,
|
||||
Date = 3,
|
||||
Env = 4,
|
||||
Experimental = 5,
|
||||
Filesystem = 6,
|
||||
Filters = 7,
|
||||
Formats = 8,
|
||||
Math = 9,
|
||||
Strings = 10,
|
||||
System = 11,
|
||||
Viewers = 12,
|
||||
}
|
||||
impl ::capnp::traits::FromU16 for Category {
|
||||
#[inline]
|
||||
fn from_u16(value: u16) -> ::core::result::Result<Category, ::capnp::NotInSchema> {
|
||||
match value {
|
||||
0 => ::core::result::Result::Ok(Category::Default),
|
||||
1 => ::core::result::Result::Ok(Category::Conversions),
|
||||
2 => ::core::result::Result::Ok(Category::Core),
|
||||
3 => ::core::result::Result::Ok(Category::Date),
|
||||
4 => ::core::result::Result::Ok(Category::Env),
|
||||
5 => ::core::result::Result::Ok(Category::Experimental),
|
||||
6 => ::core::result::Result::Ok(Category::Filesystem),
|
||||
7 => ::core::result::Result::Ok(Category::Filters),
|
||||
8 => ::core::result::Result::Ok(Category::Formats),
|
||||
9 => ::core::result::Result::Ok(Category::Math),
|
||||
10 => ::core::result::Result::Ok(Category::Strings),
|
||||
11 => ::core::result::Result::Ok(Category::System),
|
||||
12 => ::core::result::Result::Ok(Category::Viewers),
|
||||
n => ::core::result::Result::Err(::capnp::NotInSchema(n)),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ::capnp::traits::ToU16 for Category {
|
||||
#[inline]
|
||||
fn to_u16(self) -> u16 {
|
||||
self as u16
|
||||
}
|
||||
}
|
||||
impl ::capnp::traits::HasTypeId for Category {
|
||||
#[inline]
|
||||
fn type_id() -> u64 {
|
||||
0x8920_14c1_76ba_5343u64
|
||||
}
|
||||
}
|
||||
|
||||
pub mod flag {
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Owned(());
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::plugin::PluginError;
|
||||
use crate::plugin_capnp::{argument, flag, signature, Shape};
|
||||
use nu_protocol::{Flag, PositionalArg, Signature, SyntaxShape};
|
||||
use crate::plugin_capnp::{argument, flag, signature, Category as PluginCategory, Shape};
|
||||
use nu_protocol::{Category, Flag, PositionalArg, Signature, SyntaxShape};
|
||||
|
||||
pub(crate) fn serialize_signature(signature: &Signature, mut builder: signature::Builder) {
|
||||
builder.set_name(signature.name.as_str());
|
||||
@ -8,6 +8,22 @@ pub(crate) fn serialize_signature(signature: &Signature, mut builder: signature:
|
||||
builder.set_extra_usage(signature.extra_usage.as_str());
|
||||
builder.set_is_filter(signature.is_filter);
|
||||
|
||||
match signature.category {
|
||||
Category::Default => builder.set_category(PluginCategory::Default),
|
||||
Category::Conversions => builder.set_category(PluginCategory::Conversions),
|
||||
Category::Core => builder.set_category(PluginCategory::Core),
|
||||
Category::Date => builder.set_category(PluginCategory::Date),
|
||||
Category::Env => builder.set_category(PluginCategory::Env),
|
||||
Category::Experimental => builder.set_category(PluginCategory::Experimental),
|
||||
Category::FileSystem => builder.set_category(PluginCategory::Filesystem),
|
||||
Category::Filters => builder.set_category(PluginCategory::Filters),
|
||||
Category::Formats => builder.set_category(PluginCategory::Formats),
|
||||
Category::Math => builder.set_category(PluginCategory::Math),
|
||||
Category::Strings => builder.set_category(PluginCategory::Strings),
|
||||
Category::System => builder.set_category(PluginCategory::System),
|
||||
Category::Viewers => builder.set_category(PluginCategory::Viewers),
|
||||
}
|
||||
|
||||
// Serializing list of required arguments
|
||||
let mut required_list = builder
|
||||
.reborrow()
|
||||
@ -90,6 +106,25 @@ pub(crate) fn deserialize_signature(reader: signature::Reader) -> Result<Signatu
|
||||
.map_err(|e| PluginError::EncodingError(e.to_string()))?;
|
||||
let is_filter = reader.get_is_filter();
|
||||
|
||||
let category = match reader
|
||||
.get_category()
|
||||
.map_err(|e| PluginError::EncodingError(e.to_string()))?
|
||||
{
|
||||
PluginCategory::Default => Category::Default,
|
||||
PluginCategory::Conversions => Category::Conversions,
|
||||
PluginCategory::Core => Category::Core,
|
||||
PluginCategory::Date => Category::Date,
|
||||
PluginCategory::Env => Category::Env,
|
||||
PluginCategory::Experimental => Category::Experimental,
|
||||
PluginCategory::Filesystem => Category::FileSystem,
|
||||
PluginCategory::Filters => Category::Filters,
|
||||
PluginCategory::Formats => Category::Formats,
|
||||
PluginCategory::Math => Category::Math,
|
||||
PluginCategory::Strings => Category::Strings,
|
||||
PluginCategory::System => Category::System,
|
||||
PluginCategory::Viewers => Category::Viewers,
|
||||
};
|
||||
|
||||
// Deserializing required arguments
|
||||
let required_list = reader
|
||||
.get_required_positional()
|
||||
@ -141,6 +176,7 @@ pub(crate) fn deserialize_signature(reader: signature::Reader) -> Result<Signatu
|
||||
named,
|
||||
is_filter,
|
||||
creates_scope: false,
|
||||
category,
|
||||
})
|
||||
}
|
||||
|
||||
@ -222,7 +258,7 @@ fn deserialize_flag(reader: flag::Reader) -> Result<Flag, PluginError> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use capnp::serialize;
|
||||
use nu_protocol::{Signature, SyntaxShape};
|
||||
use nu_protocol::{Category, Signature, SyntaxShape};
|
||||
|
||||
pub fn write_buffer(
|
||||
signature: &Signature,
|
||||
@ -262,7 +298,8 @@ mod tests {
|
||||
Some('s'),
|
||||
)
|
||||
.switch("switch", "some switch", None)
|
||||
.rest("remaining", SyntaxShape::Int, "remaining");
|
||||
.rest("remaining", SyntaxShape::Int, "remaining")
|
||||
.category(Category::Conversions);
|
||||
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
write_buffer(&signature, &mut buffer).expect("unable to serialize message");
|
||||
@ -273,6 +310,7 @@ mod tests {
|
||||
assert_eq!(signature.usage, returned_signature.usage);
|
||||
assert_eq!(signature.extra_usage, returned_signature.extra_usage);
|
||||
assert_eq!(signature.is_filter, returned_signature.is_filter);
|
||||
assert_eq!(signature.category, returned_signature.category);
|
||||
|
||||
signature
|
||||
.required_positional
|
||||
|
Reference in New Issue
Block a user