add the myos CLI: one model for both modes
A stack is a directory of compose files; the current directory is a stack when it holds one. The same command works for a project, a catalogue stack, a group and a host singleton, and stacks sharing a project are now a single compose call. Two traps of the make engine are closed on the way: an unknown command is an error instead of a silent success, and a group is only expanded when its name is lowercase, so an environment variable can no longer be mistaken for one. That guard spells out its character class because a-z matches uppercase too under a dictionary collation.
This commit is contained in:
+37
-3
@@ -38,9 +38,9 @@ Describe 'lib/stack.sh'
|
||||
When call myos_stack_resolve postgres
|
||||
The output should equal "$HOME/.local/share/myos/stack/postgres"
|
||||
End
|
||||
It 'resolves a versioned reference'
|
||||
When run source spec/unit/stack_version_helper.sh
|
||||
The output should equal "postgres 9.6"
|
||||
It 'resolves a versioned reference to its stack directory'
|
||||
When call myos_stack_resolve "postgres:9.6"
|
||||
The output should equal "$HOME/.local/share/myos/stack/postgres"
|
||||
End
|
||||
It 'resolves a directory reference'
|
||||
When call myos_stack_resolve "$WORKDIR/stack/host"
|
||||
@@ -53,6 +53,24 @@ Describe 'lib/stack.sh'
|
||||
End
|
||||
End
|
||||
|
||||
Describe 'myos_stack_name / myos_stack_version'
|
||||
Parameters
|
||||
"postgres" postgres latest
|
||||
"postgres:9.6" postgres 9.6
|
||||
"host/fabio" fabio latest
|
||||
"host/fabio:1.6" fabio 1.6
|
||||
"drone/drone.yml" drone latest
|
||||
End
|
||||
It "reads the name out of $1"
|
||||
When call myos_stack_name "$1"
|
||||
The output should equal "$2"
|
||||
End
|
||||
It "reads the version out of $1"
|
||||
When call myos_stack_version "$1"
|
||||
The output should equal "$3"
|
||||
End
|
||||
End
|
||||
|
||||
Describe 'myos_compose_files'
|
||||
It 'loads the stack file and its env overlay'
|
||||
When call myos_compose_files "$HOME/.local/share/myos/stack/postgres" "docker-compose postgres" "" local
|
||||
@@ -134,3 +152,19 @@ Describe 'lib/stack.sh'
|
||||
End
|
||||
End
|
||||
End
|
||||
|
||||
Describe 'lib/stack.sh group safety'
|
||||
BeforeEach 'MYOS_PATH=/nonexistent'
|
||||
It 'does not expand an uppercase variable that happens to share a name'
|
||||
# shellcheck disable=SC2034
|
||||
DOMAIN="example.test"
|
||||
When call myos_group_expand DOMAIN
|
||||
The output should equal "DOMAIN"
|
||||
End
|
||||
It 'still expands a lowercase group'
|
||||
# shellcheck disable=SC2034
|
||||
host="host/consul host/fabio"
|
||||
When call myos_group_expand host
|
||||
The lines of output should equal 2
|
||||
End
|
||||
End
|
||||
|
||||
Reference in New Issue
Block a user