diff --git a/bin/cdist-code-gen b/bin/cdist-code-gen index 33c67b08..07f2604d 100755 --- a/bin/cdist-code-gen +++ b/bin/cdist-code-gen @@ -23,21 +23,36 @@ . cdist-config -[ $# -eq 2 ] || __cdist_usage "" "" +[ $# -eq 3 ] || __cdist_usage "" "" "" set -ue export __cdist_target_host="$1"; shift +export __cdist_object_base_dir="$1"; shift export __cdist_object="$1"; shift +# Full path to object +export __cdist_object_dir="${__cdist_object_base_dir}/${__cdist_object}" + # Get type from object path -export __cdist_type=${__cdist_object%%/*} +export __cdist_type="${__cdist_object%%/*}" + +# Get id from object path (i.e no type prefix) +export __cdist_object_id="${__cdist_object#*/}" -# Full path to where the executable should exist, if the type has one -export __cdist_gencode="${__cdist_type_dir}/$__cdist_type/$__cdist_name_gencode" +# Full path to where the executable of the type should exist, if the type has one +gencode="$(__cdist_type_gencode "$__cdist_type")" +cd "$__cdist_object_dir" # Call gencode of type with __cdist_object -if [ -x "$__cdist_gencode" ]; then - "$__cdist_gencode" +if [ -x "$gencode" ]; then + cat << eof +# +# Code imported from $gencode +# + +eof + + "$gencode" fi