Skip to content

Instantly share code, notes, and snippets.

@karlhorky
Last active April 12, 2018 15:03
Show Gist options
  • Save karlhorky/58d540e405671101b6c638f35dd381fd to your computer and use it in GitHub Desktop.
Save karlhorky/58d540e405671101b6c638f35dd381fd to your computer and use it in GitHub Desktop.
Yarn: Set options conditionally based on value of positional argument
# Runs node -r @babel/register src/cli.js login --identity ../local-dev/cli_id_rsa
$ yarn cli login

# Runs node -r @babel/register src/cli.js logout --identity ../local-dev/cli_id_rsa
$ yarn cli logout

# Runs node -r @babel/register src/cli.js projects
$ yarn cli projects

Idea stolen from:

npm/npm#9627 (comment)

{
"scripts": {
"cli": "bash -c 'node -r @babel/register src/cli.js $1 $([[ $1 =~ login|logout ]] && echo \"--identity ../local-dev/cli_id_rsa\" || echo \"\")' -- "
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment