Taskfile, how to run only if binary not exists?

751 Views Asked by At

How to create precondition that only run if the binary not exists?

tasks:
  migrate:
    desc: Get golang-migrate
    cmds:
      - echo running wget bla bla
    preconditions:
      - sh: "test -z {{.MIGRATE_BIN}}"
        msg: "found, ignoring"
    vars:
      MIGRATE_BIN:
        sh: which migrate || true

or what kind of shell commands supported inside sh? it it based on $? return value or?

In normal shell I only need to do this:

MIGRATE_BIN=`which golang-migrate`
if [[ -z "$MIGRATE_BIN" ]]; then
   echo "do wget bla bla"
fi 
1

There are 1 best solutions below

0
Kokizzu On BEST ANSWER

Ah should use status instead of precondition

tasks:
  migrate:
    desc: Get golang-migrate
    cmds:
      - echo running wget bla bla
    status:
      - test -f {{.MIGRATE_BIN}}
    vars:
      MIGRATE_BIN:
        sh: which migrate || true