Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
lib/mix/tasks/hex_latest.ex
defmodule Mix.Tasks.Hex.Latest do
@doc """
## Example usage:
`mix hex.latest jason`
Or you can copy the output with `pbcopy` like this:
`mix hex.latest jason | pbcopy`
"""
use Mix.Task
@shortdoc "Get the latest version of hex package"
@impl Mix.Task
def run([package]) do
with {output, 0} <- System.cmd("mix", ["hex.info", package], stderr_to_stdout: true),
[_all, match] <- Regex.run(~r/Config: ({.*})/, output) do
Mix.Shell.IO.info(match <> ",")
else
{error_message, error_code} when is_integer(error_code) ->
error_message
|> String.trim()
|> Mix.Shell.IO.error()
end
end
def run(_) do
Mix.raise("""
Invalid arguments. Expected:
mix hex.latest [PACKAGE]
""")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment