Added a basic CLI

This commit is contained in:
2024-10-12 20:50:00 -05:00
parent caa9a46c1b
commit bf061c4a93
4 changed files with 78 additions and 4 deletions

43
lib/elixir_rss/cli.ex Normal file
View File

@@ -0,0 +1,43 @@
defmodule ElixirRss.CLI do
@default_host "0.0.0.0"
@default_port 8080
@default_basepath "/"
def run(argv) do
parse_args(argv)
|> process()
end
def parse_args(argv) do
OptionParser.parse(
argv,
strict: [help: :boolean,
host: :string,
port: :integer,
path: :string],
aliases: [h: :help])
|> elem(0)
|> switches_to_internal()
end
defp switches_to_internal(kwargs) do
if Keyword.get(kwargs, :help) do
:help
else
{Keyword.get(kwargs, :host, @default_host),
Keyword.get(kwargs, :port, @default_port),
Keyword.get(kwargs, :path, @default_basepath)}
end
end
defp process(:help) do
IO.puts("""
usage: elixir_rss [--host HOST] [--port PORT] [--path BASEPATH]
""")
System.halt(0)
end
defp process({host, port, path}) do
IO.puts("Host: #{host}, Port: #{port}, Basepath: #{path}")
end
end

View File

@@ -1,4 +1,4 @@
defmodule ElixirRss.Fetch do
defmodule ElixirRss.Http do
def fetch(url) do
url
|> HTTPoison.get()