Refactor: Big Function Alert

Our parse_args function is waving two red flags. First, it contains conditional logic. Second, it is too long. Let’s split it up.

project/1a/issues/lib/issues/cli.ex
 def​ parse_args(argv) ​do
  OptionParser.parse(argv, ​switches:​ [ ​help:​ ​:boolean​],
 aliases:​ [ ​h:​ ​:help​ ])
  |> elem(1)
  |> args_to_internal_representation()
 end
 
 def​ args_to_internal_representation([user, project, count]) ​do
  { user, project, String.to_integer(count) }
 end
 
 def​ args_to_internal_representation([user, project]) ​do
  { user, project, @default_count }
 end
 
 def​ args_to_internal_representation(_) ​do​ ​# bad arg or --help
 :help
 end

And run the tests:

 issues$ ​​mix​​ ​​test
 ......
 
 Finished in 0.05 seconds
 2 doctests, 4 tests, 0 failures