Skip to content

Instantly share code, notes, and snippets.

@dan-palmer
Created June 21, 2023 00:53
Show Gist options
  • Save dan-palmer/4f6badb5bbdb88f97362e7b932ea02ba to your computer and use it in GitHub Desktop.
Save dan-palmer/4f6badb5bbdb88f97362e7b932ea02ba to your computer and use it in GitHub Desktop.
defmodule Mix.Tasks.Todo do
use Mix.Task
@dir "~/.todos/"
def run(args) do
unless File.exists?(@dir), do: File.mkdir!(@dir)
case args do
["all"] ->
case File.ls!(@dir) do
[] -> IO.puts("No todos.")
list -> Enum.each(list, &IO.puts("- #{&1}\n#{File.read!("#{@dir}#{&1}")}\n"))
end
["create", todo] ->
File.write!("#{@dir}#{:os.system_time(:second)}", todo)
[action, id] when action in ~w(complete delete) ->
File.rm!("#{@dir}#{id}")
_else ->
IO.puts("watcha talkin bout willis")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment