Skip to content

Instantly share code, notes, and snippets.

@dan-palmer
Last active June 21, 2023 08:07
Show Gist options
  • Save dan-palmer/8cfb42d65a1234d9adc96e8ac431aff7 to your computer and use it in GitHub Desktop.
Save dan-palmer/8cfb42d65a1234d9adc96e8ac431aff7 to your computer and use it in GitHub Desktop.
unless File.exists?("~/.todos/"), do: File.mkdir!("~/.todos/")
case System.argv() do
["all"] ->
if (files = File.ls!("~/.todos/")) == [],
do: IO.puts("No todos."),
else: Enum.each(files, &IO.puts("- #{&1}\n#{File.read!("#{"~/.todos/"}#{&1}")}\n"))
["create", todo] ->
File.write!("#{"~/.todos/"}#{:os.system_time(:second)}", todo) && IO.puts("📝")
[action, id] when action in ~w(complete delete) ->
File.rm!("#{"~/.todos/"}#{id}") && IO.puts(if action == "delete", do: "🗑️", else: "✅")
_else ->
IO.puts("watcha talkin bout willis")
end
@avinayak
Copy link

How do i run this?

@dan-palmer
Copy link
Author

elixir todo.ex all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment