Skip to content

Commit

Permalink
Command stacks vars set renamed to stacks vars update to more accurat…
Browse files Browse the repository at this point in the history
…ely determine the action to be performed
  • Loading branch information
apoprotsky committed Oct 26, 2022
1 parent 2edd697 commit f1b5e9b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/cmd/cmd.v
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn command_l3(command cli.Command) ! {
client := api.new(command.flags)
parser := template.new(command.flags)
commands := {
'stacks vars set': stacks_vars_set
'stacks vars update': stacks_vars_update
}
func := commands['$command.parent.parent.name $command.parent.name $command.name']
func(command, client, parser)!
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/stacks_vars.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn stacks_vars_command() cli.Command {
description: 'Manage stack variables.'
execute: stacks_vars
commands: [
stacks_vars_set_command(),
stacks_vars_update_command(),
]
}
}
10 changes: 5 additions & 5 deletions src/cmd/stacks_vars_set.v → src/cmd/stacks_vars_update.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cli
import src.api
import src.template

fn stacks_vars_set(command cli.Command, client api.Service, parser template.Service) ! {
fn stacks_vars_update(command cli.Command, client api.Service, parser template.Service) ! {
endpoint := command.flags.get_string('endpoint')!
endpoint_id := client.get_endpoint_id_by_name(endpoint)!
name := command.flags.get_string('name')!
Expand All @@ -20,7 +20,7 @@ fn stacks_vars_set(command cli.Command, client api.Service, parser template.Serv
if value != val {
request := api.StackUpdateRequest{
stack_file_content: client.get_stack_file(stack.id)!
env: stack.env.set_variable(variable, value)
env: stack.env.update_variable(variable, value)
prune: false
}
eprint('Stack $name found in endpoint $endpoint, updating variable $variable ... ')
Expand All @@ -31,7 +31,7 @@ fn stacks_vars_set(command cli.Command, client api.Service, parser template.Serv
}
}

fn stacks_vars_set_command() cli.Command {
fn stacks_vars_update_command() cli.Command {
mut flags := get_common_flags()
flags << get_endpoint_flag()
flags << get_stacks_name_flag()
Expand All @@ -52,8 +52,8 @@ fn stacks_vars_set_command() cli.Command {
},
]
return cli.Command{
name: 'set'
description: 'Set value of the stack variable.'
name: 'update'
description: 'Uopdate value of the stack variable.'
execute: command_l3
flags: flags
}
Expand Down
22 changes: 6 additions & 16 deletions src/entities/stack.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,18 @@ pub:

type StackEnvironment = []StackVariable

// set_variable returns new StackEnvironment with setteled variable
pub fn (se []StackVariable) set_variable(name string, value string) StackEnvironment {
mut exists := false
mut result := []StackVariable{}
for item in se {
// update_variable returns new StackEnvironment with updated variable
pub fn (se []StackVariable) update_variable(name string, value string) StackEnvironment {
func := fn [name, value] (item StackVariable) StackVariable {
if item.name == name {
exists = true
result << StackVariable{
return StackVariable{
name: name
value: value
}
} else {
result << item
}
return item
}
if !exists {
result << StackVariable{
name: name
value: value
}
}
return result
return se.map(func)
}

pub struct Stack {
Expand Down

0 comments on commit f1b5e9b

Please sign in to comment.