gilbertbw

gilbertbw

Runtime Mix.Task - set long task description?

I have a Mix.Task I am writing. This is a generic Task runner task, where what it does depends entirely on the project configuration. As such I want running mix help check to use a runtime set long task description.

With a configuration like this:

def project do
[
  #...
  checks: [
    {"test", "mix", ~W"test --force --warnings-as-errors"},
    {"cspell", "npx", ~W"--package=cspell@8.16.0 --yes -- cspell ."},
    {"compile (no warnings)", "mix", ~W"compile --force --warnings-as-errors"},
  ]
  #...
]
#...

I want to show this as the help

Runs the following checks:
  - test
  - cspell
  - compile (no warnings)

I expect doing this would require getting Mix.Task.moduledoc changed to optionally call a callback on the task?

Alternatively if anyone knows of a better way to do what I am doing I am all ears. I believe I can not use an alias, both because I want to call external commands, and because I want to e.g. run test in the test enironment, then compile in the dev environment.

First Post!

harrisi

harrisi

I think you can probably do this with Mix.Project.config/0. Something like:

defmodule Mix.Tasks.CheckHelper do
  def build_help do
    checks = Mix.Project.config()
             |> Keyword.get(:checks)
             |> Enum.map(fn el -> elem(el, 0) end)
             |> Enum.join("\n\n")

    {0, checks}
  end
end
defmodule Mix.Tasks.Check do
  use Mix.Task

  alias Mix.Tasks.CheckHelper

  Module.put_attribute(__MODULE__, :moduledoc, CheckHelper.build_help())

  @impl Mix.Task
  def run(_args) do
    Mix.shell().info("use `mix help check`")
  end
end
$ mix check && mix help check
                                   mix check                                    

test

cspell

compile (no warnings)

I don’t think this is ideal, but it’s a starting point, hopefully. Or it’s bad enough that someone will correct it for an actual solution.

Where Next?

Popular in Questions Top

sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement