Skip to content

Commit

Permalink
feat: add main command for global help
Browse files Browse the repository at this point in the history
  • Loading branch information
fnuttens committed May 16, 2024
1 parent 07112c5 commit e4420b5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Florent Nuttens"]
name = "nu_plugin_hmac"
version = "0.2.1"
version = "0.3.0"
edition = "2021"

[dependencies]
Expand Down
33 changes: 31 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn nu_plugin::PluginCommand<Plugin = Self>>> {
vec![Box::new(Sha256), Box::new(Sha512)]
vec![Box::new(Main), Box::new(Sha256), Box::new(Sha512)]
}
}

Expand All @@ -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<Value, LabeledError> {
Ok(Value::string(engine.get_help()?, call.head))
}
}

impl SimplePluginCommand for Sha256 {
type Plugin = HmacPlugin;

Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e4420b5

Please sign in to comment.