From e4420b5d5ffcde3af14e52ff73402617c6568cde Mon Sep 17 00:00:00 2001 From: Florent Nuttens Date: Thu, 16 May 2024 08:50:53 +0200 Subject: [PATCH] feat: add main command for global help --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f05e3f4..bbc5f24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1190,7 +1190,7 @@ dependencies = [ [[package]] name = "nu_plugin_hmac" -version = "0.2.1" +version = "0.3.0" dependencies = [ "hex", "hmac", diff --git a/Cargo.toml b/Cargo.toml index 3bf9904..cfb7b38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Florent Nuttens"] name = "nu_plugin_hmac" -version = "0.2.1" +version = "0.3.0" edition = "2021" [dependencies] diff --git a/src/main.rs b/src/main.rs index f2fbec9..ec98f02 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,10 +6,9 @@ use nu_protocol::{Category, Example, LabeledError, Signature, SyntaxShape, Type, struct HmacPlugin; -// TODO: add help for global command (hmac) impl Plugin for HmacPlugin { fn commands(&self) -> Vec>> { - vec![Box::new(Sha256), Box::new(Sha512)] + vec![Box::new(Main), Box::new(Sha256), Box::new(Sha512)] } } @@ -18,9 +17,37 @@ fn main() { } // TODO: put in own module +struct Main; struct Sha256; struct Sha512; +impl SimplePluginCommand for Main { + type Plugin = HmacPlugin; + + fn name(&self) -> &str { + "hmac" + } + + fn usage(&self) -> &str { + "HMAC commands implementing various hash functions" + } + + fn signature(&self) -> Signature { + // TODO: choose better category + Signature::build(self.name()).category(Category::Experimental) + } + + fn run( + &self, + _plugin: &Self::Plugin, + engine: &EngineInterface, + call: &EvaluatedCall, + _input: &Value, + ) -> Result { + Ok(Value::string(engine.get_help()?, call.head)) + } +} + impl SimplePluginCommand for Sha256 { type Plugin = HmacPlugin; @@ -34,6 +61,7 @@ impl SimplePluginCommand for Sha256 { fn signature(&self) -> nu_protocol::Signature { Signature::build(self.name()) + // TODO: choose better category .category(Category::Experimental) .input_output_type(Type::String, Type::String) .required("secret", SyntaxShape::String, "Secret key to use") @@ -85,6 +113,7 @@ impl SimplePluginCommand for Sha512 { fn signature(&self) -> nu_protocol::Signature { Signature::build(self.name()) + // TODO: choose better category .category(Category::Experimental) .input_output_type(Type::String, Type::String) .required("secret", SyntaxShape::String, "Secret key to use")