Skip to content

Commit

Permalink
Added command stacks vars get
Browse files Browse the repository at this point in the history
  • Loading branch information
apoprotsky committed Oct 27, 2022
1 parent f1b5e9b commit 0774163
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/cmd/cmd.v
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn command_l3(command cli.Command) ! {
client := api.new(command.flags)
parser := template.new(command.flags)
commands := {
'stacks vars get': stacks_vars_get
'stacks vars update': stacks_vars_update
}
func := commands['$command.parent.parent.name $command.parent.name $command.name']
Expand Down
12 changes: 12 additions & 0 deletions src/cmd/stacks.v
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ fn get_stacks_name_flag() []cli.Flag {
]
}

fn get_stacks_variable_flag() []cli.Flag {
return [
cli.Flag{
flag: .string
name: 'variable'
abbrev: 'var'
description: 'Variable name'
required: true
},
]
}

fn get_stacks_flags() []cli.Flag {
mut flags := get_stacks_name_flag()
flags << [
Expand Down
1 change: 1 addition & 0 deletions src/cmd/stacks_vars.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn stacks_vars_command() cli.Command {
description: 'Manage stack variables.'
execute: stacks_vars
commands: [
stacks_vars_get_command(),
stacks_vars_update_command(),
]
}
Expand Down
33 changes: 33 additions & 0 deletions src/cmd/stacks_vars_get.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module cmd

import cli
import src.api
import src.template

fn stacks_vars_get(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')!
variable := command.flags.get_string('variable')!
stack := client.get_stack(endpoint_id, name) or {
return error('stack $name not exists in endpoint $endpoint')
}
val := stack.get_variable_value(variable)
if val == '' {
return error('variable $variable not fount in stack $name, endpoint $endpoint')
}
print(val)
}

fn stacks_vars_get_command() cli.Command {
mut flags := get_common_flags()
flags << get_endpoint_flag()
flags << get_stacks_name_flag()
flags << get_stacks_variable_flag()
return cli.Command{
name: 'get'
description: 'Get value of the stack variable.'
execute: command_l3
flags: flags
}
}
26 changes: 9 additions & 17 deletions src/cmd/stacks_vars_update.v
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,17 @@ fn stacks_vars_update_command() cli.Command {
mut flags := get_common_flags()
flags << get_endpoint_flag()
flags << get_stacks_name_flag()
flags << [
cli.Flag{
flag: .string
name: 'variable'
abbrev: 'var'
description: 'Variable name'
required: true
},
cli.Flag{
flag: .string
name: 'value'
abbrev: 'val'
description: 'Variable value'
required: true
},
]
flags << get_stacks_variable_flag()
flags << cli.Flag{
flag: .string
name: 'value'
abbrev: 'val'
description: 'Variable value'
required: true
}
return cli.Command{
name: 'update'
description: 'Uopdate value of the stack variable.'
description: 'Update value of the stack variable.'
execute: command_l3
flags: flags
}
Expand Down

0 comments on commit 0774163

Please sign in to comment.