I have an umbrella app that I have just added a CLI application to. I want to include the CLI app as part of the umbrella so that I can use some of the common library applications from the umbrella.
I am using bakeware in order to build a stand alone executable for the CLI. Thus, I have to include a module entry point in the mix.exs
file:
def application do
[
mod: {Cli, []},
extra_applications: [
:logger
]
]
end
This is because bakeware implements its own start/2 callback from the Application module to achieve its functionality:
defmacro __using__(_opts) do
quote location: :keep do
@behaviour Bakeware.Script
import Bakeware.Script, only: [get_argc!: 0, get_args: 1, result_to_halt: 1]
use Application
def start(_type, _args) do
children = [
%{id: Task, restart: :temporary, start: {Task, :start_link, [&__MODULE__._main/0]}}
]
opts = [strategy: :one_for_all, name: __MODULE__.Supervisor]
Supervisor.start_link(children, opts)
end
@doc false
def _main() do
get_argc!()
|> get_args()
|> main()
|> result_to_halt()
|> :erlang.halt()
catch
error, reason ->
IO.warn(
"Caught exception in #{__MODULE__}.main/1: #{inspect(error)} => #{inspect(reason, pretty: true)}",
__STACKTRACE__
)
:erlang.halt(1)
end
end
end
I have tried implementing the start/2 callback within my CLI module and switch possibly on the start type or args coming in, but of course, they are the same no matter the start strategy.
Is there a way I can conditionally start this application based on CLI executable vs umbrella start?
Thanks!