Compare commits

...

2 Commits

Author SHA1 Message Date
Nathan Mattes 8f002646a2 Add option parser and tests for it
TESTS!!!!
2021-11-30 21:48:17 +01:00
Nathan Mattes ad7be8bc62 Initial commit for issues project 2021-11-30 21:21:19 +01:00
9 changed files with 159 additions and 0 deletions

4
issues/.formatter.exs Normal file
View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

26
issues/.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where third-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
issues-*.tar
# Temporary files, for example, from tests.
/tmp/

21
issues/README.md Normal file
View File

@ -0,0 +1,21 @@
# Issues
**TODO: Add description**
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `issues` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:issues, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/issues](https://hexdocs.pm/issues).

18
issues/lib/issues.ex Normal file
View File

@ -0,0 +1,18 @@
defmodule Issues do
@moduledoc """
Documentation for `Issues`.
"""
@doc """
Hello world.
## Examples
iex> Issues.hello()
:world
"""
def hello do
:world
end
end

34
issues/lib/issues/cli.ex Normal file
View File

@ -0,0 +1,34 @@
defmodule Issues.CLI do
@default_count 4
@moduledoc """
Handle the command line parsing and the dispatch to the various functions that end up
generating a table of the last _n_ issues in a github project.
"""
def run(argv) do
parse_args(argv)
end
def parse_args(argv) do
parse =
OptionParser.parse(argv,
switches: [help: :boolean],
aliases: [h: :help]
)
case parse do
{[help: true], _, _} ->
:help
{_, [user, project, count], _} ->
{user, project, String.to_integer(count)}
{_, [user, project], _} ->
{user, project, @default_count}
_ ->
:help
end
end
end

28
issues/mix.exs Normal file
View File

@ -0,0 +1,28 @@
defmodule Issues.MixProject do
use Mix.Project
def project do
[
app: :issues,
version: "0.1.0",
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end

19
issues/test/cli_test.exs Normal file
View File

@ -0,0 +1,19 @@
defmodule CliTest do
use ExUnit.Case
doctest Issues
import Issues.CLI, only: [parse_args: 1]
test ":help returned by option parsing the -h and --help options" do
assert parse_args(["-h", "anything"]) == :help
assert parse_args(["--help", "anything"]) == :help
end
test "three values returned if three given" do
assert parse_args(["user", "project", "99"]) == {"user", "project", 99}
end
test "two values and default count returned if two values given" do
assert parse_args(["user", "project"]) == {"user", "project", 4}
end
end

View File

@ -0,0 +1,8 @@
defmodule IssuesTest do
use ExUnit.Case
doctest Issues
test "greets the world" do
assert Issues.hello() == :world
end
end

View File

@ -0,0 +1 @@
ExUnit.start()