question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add parameter to local/remote shell runner to change delimiter in named parameters

See original GitHub issue

While assisting some users today, I ran into a problem with optparse. In a nutshell, parsing options is hard in Bash, so there are many tendencies to shortcut. One such example:

while [ -n "$1" ]; do
    case $1 in
        -C|--gecos)    gecos=$2;  shift 2;;
        -e|--email)    email=$2;  shift 2;;
        -u|--userid)   userid=$2; shift 2;;
        -d|--dry-run)  dryrun=1;  shift;;
        -h|--help)     usage;;
        *) shift;;
    esac
done

Today, I can change the kwargs_op to any prefix I so desire. But, in all cases, the input is distilled to a dict, and then rendered as key-value pairs. (e.g.: --email=james@fryman.io). This causes a failure with the above logic.

This is not an uncommon pattern, and it would be good to be able to s/=/ / in the above parameter.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jfrymancommented, Jan 15, 2016

@lakshmi-kannan @manasdk fwiw, I’m not immediately blocked. The “workaround” was to fix the underlying script.

I avoided using the cmd jinja pattern hack as I think it’s certainly an antipattern we need to watch carefully. It is supported (https://docs.stackstorm.com/runners.html?highlight=runner#runner-parameters). It is disjointed to have the ability to modify the kwargs_op option, but not have one for the delimiter between keyword parameters. If anything, dropping to the cmd and writing it out manually all but nullifies the need for kwargs_op, since I could define it in the cmd for that need as well.

0reactions
powellchristophcommented, Dec 17, 2018

I have a simple bash script with named cli arguments that I am trying to use the local-shell-script with. I was able to change the kwarg_op seperator, but the runner still uses the = to separate k/v items.

So alittle script like this below would be called from the command like like: ./script.sh -r foo -w /tmp -s server -c client or ./script.sh -r foo -w /tmp I don’t want to use positional args, because they aren’t all required.

#!/bin/bash

while getopts r:w:c:s:m: option
do
    case "${option}" in
        r) REGION=${OPTARG//=/};;
        w) WORKDIR=${OPTARG//=/};;
        s) SERVER="ParameterValue=${OPTARG//=/}";;
        c) CLIENT="ParameterValue=${OPTARG//=/}";;
        m) MANIFEST=${OPTARG//=/}
            ;;
    esac
done

But using the following meta parameters. It gets passed by Stackstorm as ./script.sh -r=foo -w=/tmp -s=server -c=client

parameters:
  w:
    type: "string"
    required: true
  r:
    type: "string"
    required: true
  s:
    type: "string"
  c:
    type: "string"
  m:
    type: "string"
  kwarg_op:
    type: "string"
    immutable: true
    default: "-"

So now my args are passed to my script by getopts as =value and I have to use the ${OPTARG//=/} to strip it off.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bash - Passing named arguments to shell scripts
When using the variables, one can make sure that they have a default value set by using "${p_out:-"default value"}" for example. From 3.5.3...
Read more >
Changing parameter delimiters - LoadRunner Professional
I need to change my parameter delimiters so I go to Tools -> Options -> Scripting -> Parameters. I change left delimiter to...
Read more >
The Shell executor - GitLab Docs
The Shell executor is a simple executor that you use to execute builds locally on the machine where GitLab Runner is installed. It...
Read more >
Spring Cloud Data Flow Reference Guide
OAuth Authentication using the Spring Cloud Data Flow Shell; 14.3.3. ... <name of application> , So for example to set Java options for...
Read more >
Bash Boilerplate Generator - toolstud.io
bash boilerplate shell sh macos linux. ... An multi is a multiple values parameter (can only be last parameter). Parameter 1. flag, option,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found