mirror of
https://github.com/ash-project/ash.git
synced 2024-09-08 05:51:11 +12:00
improvement: better positional argument handling with igniter
This commit is contained in:
parent
dc4a63c86c
commit
303da2a97f
5 changed files with 34 additions and 14 deletions
|
@ -1,11 +1,12 @@
|
|||
defmodule Mix.Tasks.Ash.Gen.Domain do
|
||||
@example "mix ash.gen.domain MyApp.Accounts"
|
||||
@moduledoc """
|
||||
Generates an Ash.Domain
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
mix ash.gen.domain MyApp.Accounts
|
||||
#{@example}
|
||||
```
|
||||
"""
|
||||
|
||||
|
@ -13,8 +14,16 @@ defmodule Mix.Tasks.Ash.Gen.Domain do
|
|||
use Igniter.Mix.Task
|
||||
|
||||
@impl Igniter.Mix.Task
|
||||
def igniter(igniter, [domain | argv]) do
|
||||
domain = Igniter.Code.Module.parse(domain)
|
||||
def info(_argv, _parent) do
|
||||
%Igniter.Mix.Task.Info{
|
||||
positional: [:domain],
|
||||
example: @example
|
||||
}
|
||||
end
|
||||
|
||||
@impl Igniter.Mix.Task
|
||||
def igniter(igniter, argv) do
|
||||
{%{domain: domain}, argv} = positional_args!(argv)
|
||||
domain_file = Igniter.Code.Module.proper_location(domain)
|
||||
|
||||
app_name = Igniter.Project.Application.app_name()
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
defmodule Mix.Tasks.Ash.Gen.Enum do
|
||||
@example "mix ash.gen.enum MyApp.Support.Ticket.Types.Status open,closed --short-name ticket_status"
|
||||
@moduledoc """
|
||||
Generates an Ash.Type.Enum
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
mix ash.gen.enum MyApp.Support.Ticket.Types.Status open,closed --short-name ticket_status
|
||||
#{@example}
|
||||
```
|
||||
|
||||
## Options
|
||||
|
@ -22,6 +23,8 @@ defmodule Mix.Tasks.Ash.Gen.Enum do
|
|||
schema: [
|
||||
short_name: :string
|
||||
],
|
||||
example: @example,
|
||||
positional: [:module_name, :types],
|
||||
aliases: [
|
||||
s: :short_name
|
||||
]
|
||||
|
@ -29,7 +32,9 @@ defmodule Mix.Tasks.Ash.Gen.Enum do
|
|||
end
|
||||
|
||||
@impl Igniter.Mix.Task
|
||||
def igniter(igniter, [module_name, types | argv]) do
|
||||
def igniter(igniter, argv) do
|
||||
{%{module_name: module_name, types: types}, argv} = positional_args!(argv)
|
||||
|
||||
enum = Igniter.Code.Module.parse(module_name)
|
||||
file_name = Igniter.Code.Module.proper_location(enum)
|
||||
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
defmodule Mix.Tasks.Ash.Gen.Resource do
|
||||
@example """
|
||||
mix ash.gen.resource Helpdesk.Support.Ticket \\
|
||||
--default-actions read \\
|
||||
--uuid-primary-key id \\
|
||||
--attribute subject:string:required:public \\
|
||||
--relationship belongs_to:representative:Helpdesk.Support.Representative \\
|
||||
--extend postgres,graphql
|
||||
"""
|
||||
@moduledoc """
|
||||
Generate and configure an Ash.Resource.
|
||||
|
||||
|
@ -7,12 +15,7 @@ defmodule Mix.Tasks.Ash.Gen.Resource do
|
|||
## Example
|
||||
|
||||
```bash
|
||||
mix ash.gen.resource Helpdesk.Support.Ticket \
|
||||
--default-actions read \
|
||||
--uuid-primary-key id \
|
||||
--attribute subject:string:required:public \
|
||||
--relationship belongs_to:representative:Helpdesk.Support.Representative \
|
||||
--extend postgres,graphql
|
||||
#{@example}
|
||||
```
|
||||
|
||||
## Options
|
||||
|
@ -33,6 +36,8 @@ defmodule Mix.Tasks.Ash.Gen.Resource do
|
|||
@impl Igniter.Mix.Task
|
||||
def info(_argv, _parent) do
|
||||
%Igniter.Mix.Task.Info{
|
||||
positional: [:resource],
|
||||
example: @example,
|
||||
schema: [
|
||||
attribute: :keep,
|
||||
relationship: :keep,
|
||||
|
@ -57,7 +62,8 @@ defmodule Mix.Tasks.Ash.Gen.Resource do
|
|||
end
|
||||
|
||||
@impl Igniter.Mix.Task
|
||||
def igniter(igniter, [resource | argv]) do
|
||||
def igniter(igniter, argv) do
|
||||
{%{resource: resource}, argv} = positional_args!(argv)
|
||||
resource = Igniter.Code.Module.parse(resource)
|
||||
app_name = Igniter.Project.Application.app_name()
|
||||
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -361,7 +361,7 @@ defmodule Ash.MixProject do
|
|||
{:simple_sat, "~> 0.1 and >= 0.1.1", optional: true},
|
||||
|
||||
# Code Generators
|
||||
{:igniter, "~> 0.2 and >= 0.2.12"},
|
||||
{:igniter, "~> 0.3 and >= 0.3.10"},
|
||||
|
||||
# Dev/Test dependencies
|
||||
{:eflame, "~> 1.0", only: [:dev, :test]},
|
||||
|
|
2
mix.lock
2
mix.lock
|
@ -19,7 +19,7 @@
|
|||
"git_cli": {:hex, :git_cli, "0.3.0", "a5422f9b95c99483385b976f5d43f7e8233283a47cda13533d7c16131cb14df5", [:mix], [], "hexpm", "78cb952f4c86a41f4d3511f1d3ecb28edb268e3a7df278de2faa1bd4672eaf9b"},
|
||||
"git_ops": {:hex, :git_ops, "2.6.1", "cc7799a68c26cf814d6d1a5121415b4f5bf813de200908f930b27a2f1fe9dad5", [:mix], [{:git_cli, "~> 0.2", [hex: :git_cli, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "ce62d07e41fe993ec22c35d5edb11cf333a21ddaead6f5d9868fcb607d42039e"},
|
||||
"glob_ex": {:hex, :glob_ex, "0.1.7", "eae6b6377147fb712ac45b360e6dbba00346689a87f996672fe07e97d70597b1", [:mix], [], "hexpm", "decc1c21c0c73df3c9c994412716345c1692477b9470e337f628a7e08da0da6a"},
|
||||
"igniter": {:hex, :igniter, "0.3.9", "2a3c80e3d5a0f3758670eaa7658fe6334633dab3fd9bca9aae69802f8282a0b3", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:inflex, "~> 2.0", [hex: :inflex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:owl, "~> 0.9", [hex: :owl, repo: "hexpm", optional: false]}, {:rewrite, "~> 0.9", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}, {:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: false]}], "hexpm", "2a5b8618a0aef8e5a545d05d389ba20fc5b0b4b8a6c45cf4f900890c263c7fdc"},
|
||||
"igniter": {:hex, :igniter, "0.3.10", "b264ed66d14f52d8fabbf5cdbcc65ce57ee35cca120066dd24f530dcc943dd48", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:inflex, "~> 2.0", [hex: :inflex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:owl, "~> 0.9", [hex: :owl, repo: "hexpm", optional: false]}, {:rewrite, "~> 0.9", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}, {:ucwidth, "~> 0.2", [hex: :ucwidth, repo: "hexpm", optional: false]}], "hexpm", "8cbf5397296cd4d3dcbd7977e8f760190321ceff1d7d393a7bcad373c46f2626"},
|
||||
"inflex": {:hex, :inflex, "2.1.0", "a365cf0821a9dacb65067abd95008ca1b0bb7dcdd85ae59965deef2aa062924c", [:mix], [], "hexpm", "14c17d05db4ee9b6d319b0bff1bdf22aa389a25398d1952c7a0b5f3d93162dd8"},
|
||||
"iterex": {:hex, :iterex, "0.1.1", "90378a9561ad87da46737dceaf02e68a0b3023746216a4de34a0c509f5f505d4", [:mix], [], "hexpm", "c4f5916a6dbb03aa4c3d5c480069e13075ca6a57bd0c28d643da3891962440ad"},
|
||||
"jason": {:hex, :jason, "1.4.3", "d3f984eeb96fe53b85d20e0b049f03e57d075b5acda3ac8d465c969a2536c17b", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "9a90e868927f7c777689baa16d86f4d0e086d968db5c05d917ccff6d443e58a3"},
|
||||
|
|
Loading…
Reference in a new issue