Running a shell script as a mix alias
Asked Answered
C

1

6

How can you run a shell script as a mix alias?

I've tried the following with no luck:

defp aliases() do
  [
    "test": [ "./scripts/test.sh" ]
  ]
end

defp aliases() do
  [
    "test": [ "scripts/test.sh" ]
  ]
end

Each returns with a variation of:

** (Mix) The task "./scripts/test" could not be found

Celesta answered 3/4, 2018 at 16:14 Comment(0)
E
9

You can use invoke the Mix.Tasks.Cmd task for this:

"test": ["cmd ./scripts/test.sh"]
$ cat a.sh
#!/bin/bash
echo foo
$ cat mix.exs | grep test
      "test": ["cmd ./a.sh", "cmd echo bar"]
$ mix test
foo
bar
Epicotyl answered 3/4, 2018 at 16:47 Comment(2)
This looks like the right answer. The only issue is that when used in an umbrella app it's recursive. Meaning it will run the command within each child app. If the script is meant to do something project-wide this may not be workable. Unfortunately, I don't see an alternative command.Celesta
⚡️🧟‍♀️🧟‍♂️ Because of the cmd functionality in umbrella projects, seems like it's just easier reference a local function "test": [&test/1] and: defp test(_argv), do: Mix.shell().cmd("./scripts/test.sh")Dawna

© 2022 - 2024 — McMap. All rights reserved.