Skip to content

Commit

Permalink
feat: implement 'list' command
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Bouyoud <jBouyoud@users.noreply.github.com>
  • Loading branch information
jBouyoud committed Nov 11, 2020
1 parent 3e787cc commit 396136f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
17 changes: 17 additions & 0 deletions scripts/commands/list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

set -eu

list_usage() {
cat <<EOF
helm config-scheme list
View all configured configuration schemes
EOF
}

list() {
repository_list_scheme | while read -r scheme; do
printf "%s\t%i file-uri(s)\n" "${scheme}" "$(repository_scheme_file_uri_count "${scheme}")"
done
}
8 changes: 8 additions & 0 deletions scripts/lib/repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ _repository_scheme_file() {
echo "${CONFIG_REPOSITORY}/${1}"
}

repository_list_scheme() {
ls -1 "${CONFIG_REPOSITORY}"
}

repository_scheme_exists() {
test -f "$(_repository_scheme_file "${1}")"
}

repository_view_scheme() {
cat "$(_repository_scheme_file "${1}")"
}

repository_create_scheme() {
scheme_name="${1}"

Expand Down
41 changes: 38 additions & 3 deletions tests/unit/list.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,43 @@ load '../bats/extensions/bats-support/load'
load '../bats/extensions/bats-assert/load'
load '../bats/extensions/bats-file/load'

@test "list:" {
@test "list -h: show help" {
run helm config-scheme list -h

assert_success
assert_output --partial 'helm config-scheme list'
}

@test "list --help: show help" {
run helm config-scheme list --help

assert_success
assert_output --partial 'helm config-scheme list'
}

@test "list help: show help" {
run helm config-scheme list help

assert_success
assert_output --partial 'helm config-scheme list'
}

@test "list: show none" {
run helm config-scheme list
assert_failure 2
assert_output --partial 'Error: Not yet implemented.'

assert_success
assert_output ''
}

@test "list: show all" {
helm config-scheme add scheme1 a.yaml
helm config-scheme add scheme2 a.yaml b.yaml
helm config-scheme add scheme3 a.yaml b.yaml b.yaml

run helm config-scheme list

assert_success
assert_output --partial 'scheme1 1 file-uri(s)'
assert_output --partial 'scheme2 2 file-uri(s)'
assert_output --partial 'scheme3 3 file-uri(s)'
}

0 comments on commit 396136f

Please sign in to comment.