Skip to content

Commit

Permalink
Update to latest version of Prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
silbermm committed Dec 12, 2023
1 parent 3afaf13 commit 4c6b8d9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 94 deletions.
43 changes: 1 addition & 42 deletions lib/exdoc_cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,6 @@ defmodule ExdocCLI do
$ exdoc Enum.flat_map
$ exdoc Enum.reduce/2
$ exdoc :ets.new/2 --open
```
"""

use Prompt, otp_app: :exdoc_cli

@help_txt """
exdoc <Module.function/airity>
Shows the builtin documentation for the specified Module
Available options:
--open Opens the Module in your $ELIXIR_EDITOR
--help, -h show this help message
--version, -v show the version
```
"""

@doc false
def main(argv) do
# enables the colors in output
IEx.configure(colors: [enabled: true])
process(argv, [], fallback: ExdocCLI.HelpCommand)
end

@doc false
def help do
display(@help_txt)
end

def help(:empty) do
display("""
An argument is required. Make sure to pass in the name of a module.
Examples:
exdoc Enum
exdoc Enum.map/2
exdoc :ets --open
""")
end
end
72 changes: 23 additions & 49 deletions lib/exdoc_cli/help_command.ex → lib/exdoc_cli/default_command.ex
Original file line number Diff line number Diff line change
@@ -1,63 +1,36 @@
# Exdoc CLI - Commandline tool for showing Elixir Docs
# Copyright (C) 2022 Matt Silbernagel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
defmodule ExdocCLI.DefaultCommand do
@moduledoc """
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
defmodule ExdocCLI.HelpCommand do
@moduledoc false
exdoc <Module.function/airity>
use Prompt.Command
require IEx.Helpers

@impl true
@doc false
def init(argv) do
argv
|> OptionParser.parse(
strict: [help: :boolean, open: :boolean],
aliases: [h: :help, o: :open]
)
|> parse()
end

defp parse({[help: true], _, _}), do: %{help: true}
Shows the builtin documentation for the specified Module
defp parse({opts, [topic | _], _}) do
open = Keyword.get(opts, :open, false)
%{help: false, topic: topic, open: open}
end
Available options:
--open Opens the Module in your $ELIXIR_EDITOR
@doc false
@impl true
def help() do
help = """
Shows the builtin help for the specified Module.
exdoc <Module> or <Module.function> or <Module.function/airity>
--open, -o Opens the Module in your $ELIXIR_EDITOR
--help, -h Shows this help message
"""
--help, -h show this help message
--version, -v show the version
"""
use Prompt.Command
require IEx.Helpers

display(help)
def init(args) do
# a leftover arg is required here for the module/function name
topic = List.first(args.leftover, nil)
Map.put(args, :topic, topic)
end

@doc false
@impl true
def process(%{help: true}), do: help()

def process(%{topic: nil}) do
display("Required argument was not provided.", color: :red)
help()
end

def process(%{topic: <<":" <> erlang_module>>, open: open}) do
IEx.configure(colors: [enabled: true])

{last, first_part} =
erlang_module
|> String.split(".")
Expand All @@ -75,6 +48,7 @@ defmodule ExdocCLI.HelpCommand do
end

def process(%{topic: topic, open: open}) do
IEx.configure(colors: [enabled: true])
{last, first_part} =
topic
|> String.split(".")
Expand Down
21 changes: 21 additions & 0 deletions lib/exdoc_cli/entry.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule ExdocCLI.Entry do
@moduledoc """
exdoc <Module.function/airity>
Shows the builtin documentation for the specified Module
Available options:
--open Opens the Module in your $ELIXIR_EDITOR
--help, -h show this help message
--version, -v show the version
"""
use Prompt.Router, otp_app: :exdoc_cli

alias ExdocCLI.DefaultCommand

command "", DefaultCommand do
arg(:help, :boolean)
arg(:open, :boolean, default: false)
end
end
5 changes: 3 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule ExdocCLI.MixProject do
end

def escript do
[main_module: ExdocCLI, name: "exdoc", strip_beams: [keep: ["Docs"]]]
[main_module: ExdocCLI.Entry, name: "exdoc", strip_beams: [keep: ["Docs"]]]
end

def application do
Expand All @@ -31,7 +31,8 @@ defmodule ExdocCLI.MixProject do

defp deps do
[
{:prompt, "~> 0.7.2"},
#{:prompt, "~> 0.9.4"},
{:prompt, path: "../prompt"},
{:ex_doc, ">= 0.28.2", only: :dev, runtime: false},
{:dialyxir, "~> 1.1", only: [:dev], runtime: false}
]
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_options": {:hex, :nimble_options, "0.3.7", "1e52dd7673d36138b1a5dede183b5d86dff175dc46d104a8e98e396b85b04670", [:mix], [], "hexpm", "2086907e6665c6b6579be54ef5001928df5231f355f71ed258f80a55e9f63633"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.2", "b99ca56bbce410e9d5ee4f9155a212e942e224e259c7ebbf8f2c86ac21d4fa3c", [:mix], [], "hexpm", "98d51bd64d5f6a2a9c6bb7586ee8129e27dfaab1140b5a4753f24dac0ba27d2f"},
"prompt": {:hex, :prompt, "0.7.2", "775893e08e39e5325724734595f61ae1d6768fe17a76542ce3c4a57a2f569dd3", [:mix], [{:nimble_options, "~> 0.3.0", [hex: :nimble_options, repo: "hexpm", optional: false]}], "hexpm", "99600fab6de2d950c7ea9d3012bf8b46e3365ad2782462f7dc9913ca2b6484fd"},
"prompt": {:hex, :prompt, "0.9.4", "079692c4114c80613fe0c25a5e5e18eddce5e02a612a2153035bf65cc1f280f9", [:mix], [{:nimble_options, "~> 0.3.0", [hex: :nimble_options, repo: "hexpm", optional: false]}], "hexpm", "7c45162aa0e3a096d7ab13a5e4a2cd8a9d36d25fe41e9a5820e8fafcbb15baf6"},
}

0 comments on commit 4c6b8d9

Please sign in to comment.