Skip to content

Instantly share code, notes, and snippets.

@alanpeabody
Last active December 14, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanpeabody/5027182 to your computer and use it in GitHub Desktop.
Save alanpeabody/5027182 to your computer and use it in GitHub Desktop.
Dynamo validate path
diff --git a/lib/mix/tasks/dynamo.ex b/lib/mix/tasks/dynamo.ex [22/1920]
index b5a268d..8f41e37 100644
--- a/lib/mix/tasks/dynamo.ex
+++ b/lib/mix/tasks/dynamo.ex
@@ -40,9 +40,9 @@ defmodule Mix.Tasks.Dynamo do
[] ->
raise Mix.Error, message: "expected PATH to be given, please use `mix dynamo PATH`"
[path|_] ->
+ path = validate_path(path)
name = opts[:app] || Path.basename(Path.expand(path))
check_project_name!(name)
- check_project_path!(path)
File.mkdir_p!(path)
File.cd!(path, fn -> do_generate(underscore(name), opts) end)
end
@@ -103,10 +103,19 @@ defmodule Mix.Tasks.Dynamo do
end
end
- defp check_project_path!(path) do
+ defp validate_path(path) do
path = Path.basename(Path.expand(path))
if path == camelize(path) do
- raise Mix.Error, message: "project path must be underscore and match module name. Try: mix dynamo #{underscore(path)}"
+ IO.puts "Project path must be underscore and match module name. Would you like to use #{underscore(path)} instead?"
+ response = IO.gets "[yes, no] default yes > "
+ response = to_binary(response) |> String.downcase |> String.strip
+ if response == "no" or response == "n" do
+ raise Mix.Error, message: "Invalid project path name, please use snake_case"
+ else
+ underscore(path)
+ end
+ else
+ path
end
end
# ... (1 -4 are SSL errors I still need to investigate)
5) test compiles an application (Mix.TasksTest)
** (File.Error) could not read file mix.exs: no such file or directory
stacktrace:
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:108: Mix.TasksTest.app_with_dynamo_deps_path/0
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:9: Mix.TasksTest."-test compiles an application/1-fun-0-"/0
/home/alan/elixir/elixir/lib/elixir/lib/file.ex:894: File.cd!/2
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:8: Mix.TasksTest."test compiles an application"/1
6) test prints application filters (Mix.TasksTest)
** (File.Error) could not read file mix.exs: no such file or directory
stacktrace:
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:108: Mix.TasksTest.app_with_dynamo_deps_path/0
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:35: Mix.TasksTest."-test prints application filters/1-fun-0-"/0
/home/alan/elixir/elixir/lib/elixir/lib/file.ex:894: File.cd!/2
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:34: Mix.TasksTest."test prints application filters"/1
7) test runs application code (Mix.TasksTest)
** (File.Error) could not read file mix.exs: no such file or directory
stacktrace:
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:108: Mix.TasksTest.app_with_dynamo_deps_path/0
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:56: Mix.TasksTest."-test runs application code/1-fun-0-"/0
/home/alan/elixir/elixir/lib/elixir/lib/file.ex:894: File.cd!/2
/home/alan/elixir/dynamo/test/mix/tasks_test.exs:55: Mix.TasksTest."test runs application code"/1
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment