Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dsc/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ tableHeader_functionName = "Function"
tableHeader_functionCategory = "Category"
tableHeader_minArgs = "MinArgs"
tableHeader_maxArgs = "MaxArgs"
tableHeader_argTypes = "ArgTypes"
tableHeader_argTypes = "ReturnTypes"
invalidFunctionFilter = "Invalid function filter"
maxInt = "maxInt"
invalidManifest = "Error in manifest for"
Expand Down
20 changes: 10 additions & 10 deletions dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::resolve::{get_contents, Include};
use crate::resource_command::{get_resource, self};
use crate::tablewriter::Table;
use crate::util::{get_input, get_schema, in_desired_state, set_dscconfigroot, validate_json, write_object, DSC_CONFIG_ROOT, EXIT_DSC_ASSERTION_FAILED, EXIT_DSC_ERROR, EXIT_INVALID_ARGS, EXIT_INVALID_INPUT, EXIT_JSON_ERROR};
use dsc_lib::functions::AcceptedArgKind;
use dsc_lib::functions::FunctionArgKind;
use dsc_lib::{
configure::{
config_doc::{
Expand Down Expand Up @@ -697,12 +697,12 @@ fn list_functions(functions: &FunctionDispatcher, function_name: Option<&String>
write_table = true;
}
let mut include_separator = false;
let accepted_arg_types= [
(AcceptedArgKind::Array, "a"),
(AcceptedArgKind::Boolean, "b"),
(AcceptedArgKind::Number, "n"),
(AcceptedArgKind::String, "s"),
(AcceptedArgKind::Object, "o"),
let returned_types= [
(FunctionArgKind::Array, "a"),
(FunctionArgKind::Boolean, "b"),
(FunctionArgKind::Number, "n"),
(FunctionArgKind::String, "s"),
(FunctionArgKind::Object, "o"),
];

let asterisks = String::from("*");
Expand All @@ -724,9 +724,9 @@ fn list_functions(functions: &FunctionDispatcher, function_name: Option<&String>

if write_table {
// construct arg_types from '-' times number of accepted_arg_types
let mut arg_types = "-".repeat(accepted_arg_types.len());
for (i, (arg_type, letter)) in accepted_arg_types.iter().enumerate() {
if function.accepted_arg_types.contains(arg_type) {
let mut arg_types = "-".repeat(returned_types.len());
for (i, (arg_type, letter)) in returned_types.iter().enumerate() {
if function.return_types.contains(arg_type) {
arg_types.replace_range(i..=i, letter);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dsc/tests/dsc_function_list.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Describe 'Tests for function list subcommand' {
$out.name | Should -BeExactly 'resourceId'
$out.minArgs | Should -Be 2
$out.maxArgs | Should -Be 2
$out.acceptedArgTypes | Should -Be @('String')
$out.returnTypes | Should -Be @('String')
$out.description | Should -Not -BeNullOrEmpty
}
}
2 changes: 1 addition & 1 deletion dsc/tests/dsc_functions.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Describe 'tests for function expressions' {
$out = dsc -l trace config get -i $config_yaml 2>$TestDrive/error.log | ConvertFrom-Json
if ($isError) {
$LASTEXITCODE | Should -Be 2 -Because (Get-Content $TestDrive/error.log -Raw)
(Get-Content $TestDrive/error.log -Raw) | Should -Match 'Invalid item to find, must be a string or number'
(Get-Content $TestDrive/error.log -Raw) | Should -Match 'accepted types are: String, Number'
} else {
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw)
($out.results[0].result.actualState.output | Out-String) | Should -BeExactly ($expected | Out-String)
Expand Down
1 change: 1 addition & 0 deletions dsc_lib/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ argCountRequired = "Function '%{name}' requires between %{min_args} and %{max_ar
noArrayArgs = "Function '%{name}' does not accept array arguments, accepted types are: %{accepted_args_string}"
noBooleanArgs = "Function '%{name}' does not accept boolean arguments, accepted types are: %{accepted_args_string}"
noNumberArgs = "Function '%{name}' does not accept number arguments, accepted types are: %{accepted_args_string}"
noNullArgs = "Function '%{name}' does not accept null arguments, accepted types are: %{accepted_args_string}"
noObjectArgs = "Function '%{name}' does not accept object arguments, accepted types are: %{accepted_args_string}"
noStringArgs = "Function '%{name}' does not accept string arguments, accepted types are: %{accepted_args_string}"

Expand Down
34 changes: 15 additions & 19 deletions dsc_lib/src/functions/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::DscError;
use crate::configure::context::Context;
use crate::functions::{AcceptedArgKind, Function, FunctionCategory};
use crate::functions::{FunctionArgKind, Function, FunctionCategory, FunctionMetadata};
use rust_i18n::t;
use serde_json::Value;
use tracing::debug;
Expand All @@ -12,24 +12,20 @@ use tracing::debug;
pub struct Add {}

impl Function for Add {
fn description(&self) -> String {
t!("functions.add.description").to_string()
}

fn category(&self) -> FunctionCategory {
FunctionCategory::Numeric
}

fn min_args(&self) -> usize {
2
}

fn max_args(&self) -> usize {
2
}

fn accepted_arg_types(&self) -> Vec<AcceptedArgKind> {
vec![AcceptedArgKind::Number]
fn get_metadata(&self) -> FunctionMetadata {
FunctionMetadata {
name: "add".to_string(),
description: t!("functions.add.description").to_string(),
category: FunctionCategory::Numeric,
min_args: 2,
max_args: 2,
accepted_arg_ordered_types: vec![
vec![FunctionArgKind::Number],
vec![FunctionArgKind::Number],
],
remaining_arg_accepted_types: None,
return_types: vec![FunctionArgKind::Number],
}
}

fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
Expand Down
34 changes: 15 additions & 19 deletions dsc_lib/src/functions/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::DscError;
use crate::configure::context::Context;
use crate::functions::{AcceptedArgKind, Function, FunctionCategory};
use crate::functions::{FunctionArgKind, Function, FunctionCategory, FunctionMetadata};
use rust_i18n::t;
use serde_json::Value;
use tracing::debug;
Expand All @@ -12,24 +12,20 @@ use tracing::debug;
pub struct And {}

impl Function for And {
fn description(&self) -> String {
t!("functions.and.description").to_string()
}

fn category(&self) -> FunctionCategory {
FunctionCategory::Logical
}

fn min_args(&self) -> usize {
2
}

fn max_args(&self) -> usize {
usize::MAX
}

fn accepted_arg_types(&self) -> Vec<AcceptedArgKind> {
vec![AcceptedArgKind::Boolean]
fn get_metadata(&self) -> FunctionMetadata {
FunctionMetadata {
name: "and".to_string(),
description: t!("functions.and.description").to_string(),
category: FunctionCategory::Logical,
min_args: 2,
max_args: usize::MAX,
accepted_arg_ordered_types: vec![
vec![FunctionArgKind::Boolean],
vec![FunctionArgKind::Boolean],
],
remaining_arg_accepted_types: Some(vec![FunctionArgKind::Boolean]),
return_types: vec![FunctionArgKind::Boolean],
}
}

fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
Expand Down
31 changes: 12 additions & 19 deletions dsc_lib/src/functions/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use base64::{Engine as _, engine::general_purpose};

use crate::DscError;
use crate::configure::context::Context;
use crate::functions::{AcceptedArgKind, FunctionCategory};
use crate::functions::{FunctionArgKind, FunctionCategory, FunctionMetadata};
use rust_i18n::t;
use serde_json::Value;
use super::Function;
Expand All @@ -14,24 +14,17 @@ use super::Function;
pub struct Base64 {}

impl Function for Base64 {
fn description(&self) -> String {
t!("functions.base64.description").to_string()
}

fn category(&self) -> FunctionCategory {
FunctionCategory::String
}

fn accepted_arg_types(&self) -> Vec<AcceptedArgKind> {
vec![AcceptedArgKind::String]
}

fn min_args(&self) -> usize {
1
}

fn max_args(&self) -> usize {
1
fn get_metadata(&self) -> FunctionMetadata {
FunctionMetadata {
name: "base64".to_string(),
description: t!("functions.base64.description").to_string(),
category: FunctionCategory::String,
min_args: 1,
max_args: 1,
accepted_arg_ordered_types: vec![vec![FunctionArgKind::String]],
remaining_arg_accepted_types: None,
return_types: vec![FunctionArgKind::String],
}
}

fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
Expand Down
31 changes: 12 additions & 19 deletions dsc_lib/src/functions/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::DscError;
use crate::configure::context::Context;
use crate::functions::{AcceptedArgKind, Function, FunctionCategory};
use crate::functions::{FunctionArgKind, Function, FunctionCategory, FunctionMetadata};
use rust_i18n::t;
use serde_json::Value;
use tracing::debug;
Expand All @@ -12,24 +12,17 @@ use tracing::debug;
pub struct Bool {}

impl Function for Bool {
fn description(&self) -> String {
t!("functions.bool.description").to_string()
}

fn category(&self) -> FunctionCategory {
FunctionCategory::Logical
}

fn min_args(&self) -> usize {
1
}

fn max_args(&self) -> usize {
1
}

fn accepted_arg_types(&self) -> Vec<AcceptedArgKind> {
vec![AcceptedArgKind::String, AcceptedArgKind::Number]
fn get_metadata(&self) -> FunctionMetadata {
FunctionMetadata {
name: "bool".to_string(),
description: t!("functions.bool.description").to_string(),
category: FunctionCategory::Logical,
min_args: 1,
max_args: 1,
accepted_arg_ordered_types: vec![vec![FunctionArgKind::String, FunctionArgKind::Number]],
remaining_arg_accepted_types: None,
return_types: vec![FunctionArgKind::Boolean],
}
}

fn invoke(&self, args: &[Value], _context: &Context) -> Result<Value, DscError> {
Expand Down
Loading
Loading