diff --git a/lib/mix/tasks/nabo.gen.post.ex b/lib/mix/tasks/nabo.gen.post.ex index 1002464..7405878 100644 --- a/lib/mix/tasks/nabo.gen.post.ex +++ b/lib/mix/tasks/nabo.gen.post.ex @@ -6,23 +6,31 @@ defmodule Mix.Tasks.Nabo.Gen.Post do @recursive true @moduledoc """ - Generates a post. + Generates a post with the given path. ## Example - mix nabo.gen.post first-post + mix nabo.gen.post first-post --path priv/posts + + ## Command line options + + * `-p`, `--path` - the path where the posts locate """ @doc false def run(args) do - case OptionParser.parse(args) do - {_, [slug], _} -> + switches = [path: :string] + aliases = [p: :path] + + case OptionParser.parse(args, switches: switches, aliases: aliases) do + {options, [slug], _invalid} -> + root_path = Keyword.get(options, :root, "priv/posts/") datetime = DateTime.utc_now() - posts_path = "priv/posts" - path = Path.relative_to(posts_path, Mix.Project.app_path) + path = Path.relative_to(root_path, Mix.Project.app_path) file = Path.join(path, "#{format_datetime(datetime)}_#{slug}.md") create_file(file, post_template(slug: slug, datetime: datetime)) + _ -> Mix.raise "expected nabo.gen.post to receive post slug, " <> "got: #{inspect(Enum.join(args, " "))}" diff --git a/lib/mix/tasks/nabo.gen.repo.ex b/lib/mix/tasks/nabo.gen.repo.ex index 6226e17..d6ed388 100644 --- a/lib/mix/tasks/nabo.gen.repo.ex +++ b/lib/mix/tasks/nabo.gen.repo.ex @@ -23,6 +23,7 @@ defmodule Mix.Tasks.Nabo.Gen.Repo do create_directory(Path.dirname(file)) create_file(file, repo_template(mod: repo)) + _ -> Mix.raise "expected nabo.gen.repo to receive repo name, " <> "got: #{inspect Enum.join(args, " ")}"