-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
100 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,48 @@ | ||
defmodule Mensagem.CLI do | ||
@moduledoc """ | ||
Print out random quotes like the Unix fortune program. | ||
Print out random quotes, like the Unix fortune program, | ||
and reminders. | ||
""" | ||
|
||
alias Mensagem.Quotes | ||
alias Mensagem.Remind | ||
|
||
def main(args) do | ||
args |> parse_args |> process | ||
end | ||
|
||
def parse_args(args) do | ||
parse = OptionParser.parse(args, switches: [help: :boolean], | ||
aliases: [h: :help]) | ||
parse = OptionParser.parse(args, switches: [help: :boolean, quote: :boolean, remind: :boolean], | ||
aliases: [h: :help, q: :quote, r: :remind]) | ||
|
||
case parse do | ||
{[help: true], _, _} -> :help | ||
{[quote: true], _, _} -> :quote | ||
{[remind: true], _, _} -> :remind | ||
_ -> [] | ||
end | ||
end | ||
|
||
def process([]), do: Quotes.fetch_quote |> print_quote | ||
def process([]), do: Quotes.fetch_quote <> "\n\n" <> Remind.fetch_remind |> print_message | ||
|
||
def process(:quote), do: Quotes.fetch_quote |> print_message | ||
|
||
def process(:remind), do: Remind.fetch_remind |> print_message | ||
|
||
def process(:help) do | ||
IO.puts """ | ||
Usage: mensagem | ||
without options: Print a random quote and reminders. | ||
Options: | ||
-h, --help: Help! | ||
-h, --help: Print a help message. | ||
-q, --quote: Print a random quote. | ||
-r, --remind: Print reminders. | ||
""" | ||
System.halt(0) | ||
end | ||
|
||
def print_quote(quote), do: IO.puts quote | ||
def print_message(message), do: IO.puts message | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule Mensagem.Remind do | ||
@moduledoc false | ||
|
||
def fetch_remind() do | ||
rem_path = Path.join(__DIR__, "Reminders.txt") | ||
#lines = File.read!(rem_path) |> String.split("\n", trim: true) | ||
text = File.read! rem_path | ||
|
||
case text do | ||
[] -> "No reminders." | ||
_ -> "Reminders for today.\n" <> text | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Feed the pet ant at 5pm | ||
Greet the wife on 2014/9/12 |