E

Conditional Command Execution Inquiry

Summary

The user is asking how to execute a command only when the --push option is not present, specifically wanting to run a command with a dry-run flag like git push tags --dry-run when --push is omitted. They suggest using a pre-declared conditional statement and mention incorporating it within a RUN command, providing a snippet that includes an ARG for EARTHLY_PUSH and a conditional check. They note that they were missing the ARG declaration.

Status
resolved
Tags
    Source
    #earthly
      e

      elliott.street

      9/24/2024

      it was the ARG declaration that I was missing

      e

      elliott.street

      9/24/2024

      brilliant, thanks!

      r

      rrjjvv

      9/24/2024

      In my snippet, I was using it within a RUN, but you can use it to control RUN itself:

              IF [ "$EARTHLY_PUSH" = "true" ]
      <snip>
              END```
      
      r

      rrjjvv

      9/24/2024

      You mean like this :slightly_smiling_face::

                    git push -u origin "$push_branch"; \
                  else \
                    echo "Will only push with --push!"; \
                  fi; \```
      You just have to pre-declare it like other builtin args.
      
      e

      elliott.street

      9/24/2024

      Is there a way to RUN a command only when --push is not provided?

      e.g. If I omit push, I'd to run my command with the its dry-run flag instead, e.g. git push tags --dry-run