Commit 6a1979ef authored by Cyril Plisko's avatar Cyril Plisko

Named parameters

parent c7de3b3a
Pipeline #103842095 passed with stage
in 2 minutes and 39 seconds
......@@ -8,12 +8,12 @@ pub fn template() -> Template {
let eip1 = EIp::vpc();
let eip2 = EIp::vpc();
let scale = Parameter::string();
let scale = Parameter::string("scale");
let mut template = Template::new();
template
.description("Proxy Farm")
.parameter("scale", scale)
.parameter(scale)
.resource("proxy1", proxy1)
.resource("proxy1ip", eip1)
.resource("proxy2", proxy2)
......
use serde::Serialize;
use crate::skip_serializing_if::SkipSerializingIf;
#[derive(Clone, Debug, Default, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Parameter {
#[serde(skip)]
name: String,
#[serde(skip_serializing_if = "String::is_empty")]
allowed_pattern: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
allowed_values: Vec<String>,
#[serde(skip_serializing_if = "String::is_empty")]
constraint_description: String,
#[serde(skip_serializing_if = "String::is_empty")]
default: String,
#[serde(skip_serializing_if = "String::is_empty")]
description: String,
#[serde(skip_serializing_if = "u64::is_zero")]
max_length: u64,
#[serde(skip_serializing_if = "u64::is_zero")]
max_value: u64,
#[serde(skip_serializing_if = "u64::is_zero")]
min_length: u64,
#[serde(skip_serializing_if = "u64::is_zero")]
min_value: u64,
#[serde(skip_serializing_if = "bool::is_false")]
no_echo: bool,
r#type: DataType,
}
impl Parameter {
pub fn string() -> Self {
pub fn string(name: impl ToString) -> Self {
let name = name.to_string();
let r#type = DataType::String;
Self {
name,
r#type,
..Self::default()
}
}
pub fn number() -> Self {
pub fn number(name: impl ToString) -> Self {
let name = name.to_string();
let r#type = DataType::Number;
Self {
name,
r#type,
..Self::default()
}
}
pub(crate) fn name(&self) -> String {
self.name.clone()
}
}
#[derive(Clone, Debug, Serialize)]
......
......@@ -77,8 +77,8 @@ impl Template {
self
}
pub fn parameter(&mut self, name: impl Into<String>, parameter: Parameter) -> &mut Self {
let name = name.into();
pub fn parameter(&mut self, parameter: Parameter) -> &mut Self {
let name = parameter.name();
self.parameters.insert(name, parameter);
self
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment