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.
37 lines
986 B
Bash
37 lines
986 B
Bash
#shellcheck shell=sh
|
|
# myos ls [--groups] list the stacks myos can see, and where they come from
|
|
myos_cmd_ls() {
|
|
case ${MYOS_REFS_RAW:-}${MYOS_ARGS:-} in
|
|
*--groups*) myos_ls_groups; return 0 ;;
|
|
esac
|
|
_IFS=$IFS; IFS=:
|
|
for _d in $(myos_path); do
|
|
IFS=$_IFS
|
|
printf '%s%s%s\n' "$MYOS_C_INFO" "$_d" "$MYOS_C_RESET"
|
|
for _s in "$_d"/*; do
|
|
[ -d "$_s" ] || continue
|
|
_n=$(basename "$_s")
|
|
_f=$(find "$_s" -maxdepth 1 \( -name '*.yml' -o -name '*.yaml' \) | wc -l | tr -d ' ')
|
|
[ "$_f" = 0 ] && continue
|
|
printf ' %-24s %s compose file(s)\n' "$_n" "$_f"
|
|
done
|
|
IFS=:
|
|
done
|
|
IFS=$_IFS
|
|
}
|
|
|
|
myos_ls_groups() {
|
|
_IFS=$IFS; IFS=:
|
|
for _d in $(myos_path); do
|
|
IFS=$_IFS
|
|
for _f in "$_d"/*.mk "$_d"/*.env "$_d"/*/*.mk; do
|
|
[ -f "$_f" ] || continue
|
|
_n=$(basename "$_f"); _n=${_n%.mk}; _n=${_n%.env}
|
|
_v=$(myos_group_value "$_n")
|
|
[ -n "$_v" ] && printf '%-16s %s\n' "$_n" "$_v"
|
|
done
|
|
IFS=:
|
|
done
|
|
IFS=$_IFS
|
|
}
|