From 06310c73c1f35eb41594decaece4853e613a7b7a Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 4 Aug 2016 17:46:56 +0800 Subject: [PATCH] FEATURE: Allow templates to be nested. --- launcher | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/launcher b/launcher index b897b42..50268d7 100755 --- a/launcher +++ b/launcher @@ -244,11 +244,31 @@ set_links() { "require 'yaml'; puts YAML.load(STDIN.readlines.join)['links'].map{|l| '--link ' << l['link']['name'] << ':' << l['link']['alias'] << ' '}.join"` } -set_template_info() { - - templates=`cat $config_file | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e \ +find_templates() { + local templates=`cat $1 | $docker_path run $user_args --rm -i -a stdin -a stdout $image ruby -e \ "require 'yaml'; puts YAML.load(STDIN.readlines.join)['templates']"` + local arrTemplates=${templates// / } + + if [ ! -z $templates ]; then + for template in "${arrTemplates[@]}" + do + local nested_templates=$(find_templates $template) + + if [ ! -z "$nested_templates" ]; then + templates="$templates $nested_templates" + fi + done + + echo $templates + else + echo "" + fi +} + +set_template_info() { + templates=$(find_templates $config_file) + arrTemplates=(${templates// / }) config_data=$(cat $config_file) -- 2.25.1