Skip to content

Commit 8787154

Browse files
Add new argument --appconfig to load given app config (#102)
Co-authored-by: Sergey Fedorov <oni.strech@gmail.com>
1 parent 4712e5a commit 8787154

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/mix/tasks/avrora.reg.schema.ex

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ defmodule Mix.Tasks.Avrora.Reg.Schema do
1515
* `--name` - the full name of the schema to register (exclusive with `--all`)
1616
* `--as` - the name which will be used to register schema (i.e subject)
1717
* `--all` - register all found schemas
18-
* `--module` - private Avrora client module (i.e MyClient)
18+
* `--module` - the private Avrora client module (i.e MyClient)
19+
* `--appconfig` - the app config file name to load from `config/` folder (i.e runtime)
1920
2021
The `--module` option allows to use your private Avrora client module instead of
2122
the default `Avrora`.
@@ -25,13 +26,17 @@ defmodule Mix.Tasks.Avrora.Reg.Schema do
2526
The `--name` option expects that given schema name will comply to
2627
`Avrora.Storage.File` module rules.
2728
29+
The `--appconfig` option expects just application config file name without an extension
30+
and will load it additionally to default. Note: runtime config doesn't support imports!
31+
2832
For example, if the schema name is `io.confluent.Payment` it should be stored
2933
as `<schemas path>/io/confluent/Payment.avsc`
3034
3135
## Usage
3236
3337
mix avrora.reg.schema --name io.confluent.Payment
3438
mix avrora.reg.schema --name io.confluent.Payment --as MyCustomName
39+
mix avrora.reg.schema --all --appconfig runtime
3540
mix avrora.reg.schema --all --module MyClient
3641
mix avrora.reg.schema --all
3742
"""
@@ -44,7 +49,8 @@ defmodule Mix.Tasks.Avrora.Reg.Schema do
4449
as: :string,
4550
all: :boolean,
4651
name: :string,
47-
module: :string
52+
module: :string,
53+
appconfig: :string
4854
]
4955
]
5056

@@ -54,6 +60,7 @@ defmodule Mix.Tasks.Avrora.Reg.Schema do
5460

5561
{opts, _, _} = OptionParser.parse(argv, @cli_options)
5662
{module_name, opts} = Keyword.pop(opts, :module, "Avrora")
63+
{app_config, opts} = Keyword.pop(opts, :appconfig)
5764

5865
module = Module.concat(Elixir, String.trim(module_name))
5966
config = Module.concat(module, Config)
@@ -62,6 +69,15 @@ defmodule Mix.Tasks.Avrora.Reg.Schema do
6269
{:ok, _} = Application.ensure_all_started(:avrora)
6370
{:ok, _} = module.start_link()
6471

72+
unless is_nil(app_config) do
73+
Mix.Project.config()
74+
|> Keyword.get(:config_path)
75+
|> Path.dirname()
76+
|> Path.join("#{app_config}.exs")
77+
|> List.wrap()
78+
|> Tasks.Loadconfig.run()
79+
end
80+
6581
case opts |> Keyword.keys() |> Enum.sort() do
6682
[:all] ->
6783
[config.self().schemas_path(), "**", "*.avsc"]

0 commit comments

Comments
 (0)