Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass no argument to action command instead of passing empty values #62

Open
davidferlay opened this issue Aug 6, 2024 · 1 comment
Open

Comments

@davidferlay
Copy link
Contributor

Observed

➜  launchr git:(main) pl example:arguments
Image "envvars:latest" exists locally

Total number of arguments passed to the script: 2
- Argument 1: ""
- Argument 2: false
  • When executing action with options, these options are passed to command as arguments
  command:
    - sh
    - /action/main.sh
    - "{{ .firstoption }}"
    - "{{ .secondoption }}"
  • Meaning that their default/empty value is passed to command executed in container even if options are not passed

Expected

  • Would be great that no option vlaue is passed to command executed in container when no option is used
➜  launchr git:(main) pl example:arguments
Image "envvars:latest" exists locally

Total number of arguments passed to the script: 0
@lexbritvin
Copy link
Collaborator

lexbritvin commented Feb 21, 2025

Considering the latest changes in Arguments and Options, it is now possible to not define "default" for both.

    - name: firstoption
      title: First option
      type: string
    - name: secondoption
      title: Second option
      description: Option to do something
      type: boolean
      default: false

There is no default value for firstoption and it's not required and variable in the template may be string|nil.
There is a default value for secondoption, will be false if not defined. If remove default, possible values may be true|false|nil in templates.

That allows us to make extra validation in actions.

  command:
    - sh
    - /action/main.sh
    - "{{ .firstoption | removeLineIfNil }}"
    - "{{ if not (isNil .secondoption) }}--secondoption={{ .secondoption }}{{ else }}{{ removeLine }}{{ end }}"

New template functions here .Arg | removeLineIfNil - template piping. It will process the template and remove the line if the given value is Nil.
if not (isNil .secondoption) - template condition to only check the value. May be helpful to pass flags as --secondoption={{ .secondoption }}
{{ removeLine }} - removes current line. Useful in condition result like we have in {{ else }}

Please, tell me if you like the naming, and it's clear for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants