Current section
Files
Jump to
Current section
Files
lib/nex/new/options.ex
defmodule Nex.New.Options do
@moduledoc false
alias Nex.New.Legacy
def parse!(args) do
{opts, parsed_args, invalid} =
OptionParser.parse(args, strict: [path: :string, starter: :string, frontend: :string])
unless invalid == [] do
invalid_opts = Enum.map_join(invalid, ", ", fn {k, _} -> "--#{k}" end)
Mix.raise("Unknown option(s): #{invalid_opts}. Valid options: --path, --starter, --frontend")
end
name =
case parsed_args do
[project_name | _] ->
project_name
[] ->
Mix.raise(
"Expected project name. Usage: mix nex.new my_app [--path PATH] [--starter STARTER] [--frontend FRONTEND]"
)
end
unless Legacy.valid_name?(name) do
Mix.raise(
"Project name must start with a letter and contain only lowercase letters, numbers, and underscores. Reserved names (elixir, mix, nex, etc.) are not allowed."
)
end
starter = Legacy.normalize_starter(opts[:starter])
frontend = Legacy.normalize_frontend(opts[:frontend])
base_path = opts[:path] || "."
project_path = Path.expand(Path.join(base_path, name))
if File.exists?(project_path) do
Mix.raise("Path #{project_path} already exists")
end
%{
name: name,
starter: starter,
frontend: frontend,
base_path: base_path,
project_path: project_path,
assigns: %{app_name: name, module_name: Macro.camelize(name), frontend: frontend}
}
end
def starter_label(starter), do: Legacy.starter_label(starter)
def frontend_label(frontend), do: Legacy.frontend_label(frontend)
def skip_deps_install?, do: Legacy.skip_deps_install?()
end