New noop command

This commit is contained in:
sagie gur ari 2020-07-03 08:57:23 +00:00
parent 95fa7a2e35
commit c97aaf159e
7 changed files with 127 additions and 0 deletions

View file

@ -8,6 +8,7 @@
* New ftp_get_in_memory command.
* New ftp_list command.
* New ftp_nlst command.
* New noop command.
* \[Breaking Change\] Conditions to support function calls #116
### v0.5.0 (2020-06-06)

View file

@ -2,6 +2,7 @@
* [std::Echo (echo)](#std__Echo)
* [std::Eval (eval)](#std__Eval)
* [std::IsDefined (is_defined)](#std__IsDefined)
* [std::Noop (noop)](#std__Noop)
* [std::Not (not)](#std__Not)
* [std::ReadUserInput (read)](#std__ReadUserInput)
* [std::Release (release)](#std__Release)
@ -244,6 +245,32 @@ exists = is_defined key
#### Aliases:
is_defined
<a name="std__Noop"></a>
## std::Noop
```sh
noop
```
Empty function that does nothing and returns none.
#### Parameters
All parameters are ignored
#### Return Value
None
#### Examples
```sh
noop
```
#### Aliases:
noop
<a name="std__Not"></a>
## std::Not
```sh

View file

@ -10,6 +10,7 @@ mod lib;
mod man;
mod math;
mod net;
mod noop;
mod not;
pub(crate) mod on_error;
mod process;
@ -32,6 +33,7 @@ pub(crate) fn load(commands: &mut Commands) -> Result<(), ScriptError> {
commands.set(eval::create(PACKAGE))?;
commands.set(is_defined::create(PACKAGE))?;
commands.set(man::create(PACKAGE))?;
commands.set(noop::create(PACKAGE))?;
commands.set(not::create(PACKAGE))?;
commands.set(read::create(PACKAGE))?;
commands.set(release::create(PACKAGE))?;

View file

@ -0,0 +1,19 @@
```sh
noop
```
Empty function that does nothing and returns none.
#### Parameters
All parameters are ignored
#### Return Value
None
#### Examples
```sh
noop
```

View file

@ -0,0 +1,39 @@
use crate::utils::pckg;
use duckscript::types::command::{Command, CommandResult};
#[cfg(test)]
#[path = "./mod_test.rs"]
mod mod_test;
#[derive(Clone)]
pub(crate) struct CommandImpl {
package: String,
}
impl Command for CommandImpl {
fn name(&self) -> String {
pckg::concat(&self.package, "Noop")
}
fn aliases(&self) -> Vec<String> {
vec!["noop".to_string()]
}
fn help(&self) -> String {
include_str!("help.md").to_string()
}
fn clone_and_box(&self) -> Box<dyn Command> {
Box::new((*self).clone())
}
fn run(&self, _arguments: Vec<String>) -> CommandResult {
CommandResult::Continue(None)
}
}
pub(crate) fn create(package: &str) -> Box<dyn Command> {
Box::new(CommandImpl {
package: package.to_string(),
})
}

View file

@ -0,0 +1,22 @@
use super::*;
use crate::test;
use crate::test::CommandValidation;
#[test]
fn common_functions() {
test::test_common_command_functions(create(""));
}
#[test]
fn run_no_args() {
test::run_script_and_validate(vec![create("")], "out = noop", CommandValidation::None);
}
#[test]
fn run_multiple_args() {
test::run_script_and_validate(
vec![create("")],
"out = noop 1 2 \"3 4\"",
CommandValidation::None,
);
}

17
test/std/noop_test.ds Normal file
View file

@ -0,0 +1,17 @@
fn test_no_args
value = noop
defined = is_defined value
assert_false ${value}
end
fn test_multiple_args
value = noop 1 2 3 4
defined = is_defined value
assert_false ${value}
end