Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir script with dependency

Tags:

elixir

I'm writing a quick Elixir script, and I'd like to use a csv library dependency. It seems a bit overkill to create a new mix project just to add in dependency management for this one library. What would you recommend? Would you go the mix project route for a simple script with a dependency?

EDIT

Note: I'm not asking how to install and access dependencies globally. The question is, "would you go the mix project route..." What is the suggested approach?

like image 542
Elliot Larson Avatar asked Jan 06 '16 21:01

Elliot Larson


2 Answers

Go the mix project route. Quick and dirty scripts have a way of growing into bigger projects.

like image 175
Onorio Catenacci Avatar answered Nov 12 '22 23:11

Onorio Catenacci


Introduced as an experimental feature in Elixir 1.12, Mix.install/2 now allows you to specify a dependency directly in an Elixir script, giving you an alternative to a full-blown mix project.

Usage is quite straightforward: list your dependencies at the top of your script (in the same format that is returned from the regular deps function in a mix project), and it will take care of downloading, compiling, and caching the dependencies for you:

Mix.install([
  {:httpoison, "~> 1.8"},
  :jason
])
HTTPoison.start
IO.puts(Jason.encode!(%{hello: :world}))
...
like image 2
Gar Avatar answered Nov 13 '22 01:11

Gar