Skip to content

Commit

Permalink
Merge pull request #125 from WadeBarnes/feature/indy-cli-command-proc…
Browse files Browse the repository at this point in the history
…essing-updates

Update indy-cli command processing
  • Loading branch information
swcurran authored Jul 23, 2020
2 parents 70999fd + 18d4131 commit ad1f84f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
3 changes: 3 additions & 0 deletions manage
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ indyCliUsage () {
$0 indy-cli
- Start an interactive indy-cli session in your Indy-Cli Container.
$0 indy-cli --help
- Get usage information for the indy-cli.
EOF
exit 1
}
Expand Down
51 changes: 35 additions & 16 deletions scripts/manage
Original file line number Diff line number Diff line change
Expand Up @@ -71,49 +71,68 @@ function start-client () {
}

function indy-cli() {
indyCliArgs="${1}"
shift || indyCliArgs=""

batchTemplate=$(find . -name "${indyCliArgs}")

for arg in "$@"; do
# Remove recognized arguments from the list after processing.
shift
case "${arg}" in
*=*)
batchFileArgs+=" ${arg}"
;;
*)
# Detemine whether or not the arg is a recognized cli-script template.
batchTemplate=$(find ./cli-scripts -type f -name "${arg}" 2>/dev/null)
if [ -z "${batchTemplate}" ]; then
# If not recognized, save it for later procesing ...
set -- "$@" "${arg}"
fi
;;
esac
done

# ========================================================================
# Prepare the cli batch script when using a template.
# ------------------------------------------------------------------------
if [ ! -z "${batchTemplate}" ]; then
batchfile="${batchTemplate}.run"

# ========================================================================
# Set default storageType if storgae configuration has not been specified.
# ------------------------------------------------------------------------
if [[ "${@}" != *"storageType"* ]]; then
set -- "$@" "storageType=default"
if [[ "${batchFileArgs}" != *"storageType"* ]]; then
batchFileArgs+=" storageType=default"
fi

if [[ "${@}" != *"storageConfig"* ]]; then
set -- "$@" "storageConfig={}"
if [[ "${batchFileArgs}" != *"storageConfig"* ]]; then
batchFileArgs+=" storageConfig={}"
fi

if [[ "${@}" != *"storageCredentials"* ]]; then
set -- "$@" "storageCredentials={}"
if [[ "${batchFileArgs}" != *"storageCredentials"* ]]; then
batchFileArgs+=" storageCredentials={}"
fi
# ========================================================================

# ========================================================================
# Set default outputFile name if not specified.
# - Only for scripts that require an input file.
# ------------------------------------------------------------------------
if [[ "${@}" == *"inputFile"* ]] && [[ "${@}" != *"outputFile"* ]]; then
cmd="${@} eval echo '\${inputFile}' | envsubst"
if [[ "${batchFileArgs}" == *"inputFile"* ]] && [[ "${batchFileArgs}" != *"outputFile"* ]]; then
cmd="${batchFileArgs} eval echo '\${inputFile}' | envsubst"
inputPath=$(eval ${cmd})
outputPath="${inputPath%/*}/signed-${inputPath##*/}"
set -- "$@" "outputFile=${outputPath}"
batchFileArgs+=" outputFile=${outputPath}"
fi
# ========================================================================

escapedArgs=$(echo $@ | sed "s~'~\\\'~g" | sed 's~\"~\\"~g')
escapedArgs=$(echo ${batchFileArgs} | sed "s~'~\\\'~g" | sed 's~\"~\\"~g')
cmd="${escapedArgs} envsubst < ${batchTemplate} > ${batchfile}"
eval ${cmd}
indyCliArgs="${batchfile}"
fi
# ========================================================================

eval ${INDY_CLI_EXE} ${indyCliArgs}

eval ${INDY_CLI_EXE} ${@} ${indyCliArgs}
# Clean up ...
if [ -f "${batchfile}" ]; then
rm -rf "${batchfile}"
Expand Down

0 comments on commit ad1f84f

Please sign in to comment.