Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default command should display help #20

Open
rupurt opened this issue Nov 30, 2023 · 0 comments
Open

Default command should display help #20

rupurt opened this issue Nov 30, 2023 · 0 comments

Comments

@rupurt
Copy link

rupurt commented Nov 30, 2023

I'm trying to write a CLI with subcommands and I'd like to have the default command with no args display the help message. What is the best way to achieve that?

Currently I get the following parse error

Failed to parse command ""
defmodule Bos.CLI do
  use Nexus

  defcommand(:broker, type: :null, doc: "broker subcommands.") do
    defcommand(:start, default: "", doc: "start a broker in the foreground.")
    defcommand(:stop, default: "", doc: "stop a running broker.")
  end

  @impl Nexus.CLI
  def version, do: "0.0.1"

  @impl Nexus.CLI
  def banner, do: "universal cli for bos"

  @impl Nexus.CLI
  def handle_input(:broker, %{value: value, subcommand: :start}) do
    IO.puts("TODO 'broker start'")
    IO.inspect(value, label: :value)
    :ok
  end

  def handle_input(:broker, %{value: value, subcommand: :stop}) do
    IO.puts("TODO 'broker stop'")
    IO.inspect(value, label: :value)
    System.halt(0)
    :ok
  end

  def handle_input(:broker, args) do
    IO.puts("TODO 'broker catch all'")
    IO.inspect(args, label: :args)
    System.halt(0)
    :ok
  end

  @impl Nexus.CLI
  def handle_input(:help) do
    IO.puts(Nexus.help(__MODULE__))
    System.halt(0)
    :ok
  end

  def handle_input(catch_all) do
    IO.puts("CATCH all/1: #{inspect(catch_all)}")
    System.halt(0)
    :ok
  end

  Nexus.help()
  Nexus.parse()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant