Skip to content

Commit

Permalink
Hide option from docs with doc: false
Browse files Browse the repository at this point in the history
  • Loading branch information
pnezis committed May 19, 2024
1 parent ada0c4c commit aad18fa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cli_options/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added

* If an option is declared as `:hidden` it will not be included in the docs.
* Support deprecating options.
* If an option is set with `doc: false` it is not included in docs.
* Support deprecating options with `:deprecated`.

## [v0.1.0](https://github.com/sportradar/elixir-workspace/tree/cli_options/v0.1.0) (2024-05-13)

Expand Down
2 changes: 1 addition & 1 deletion cli_options/lib/cli_options/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule CliOptions.Docs do
end

defp remove_hidden_options(schema),
do: Enum.reject(schema, fn {_key, opts} -> opts[:hidden] end)
do: Enum.reject(schema, fn {_key, opts} -> opts[:doc] == false end)

defp maybe_sort(schema, true), do: Enum.sort_by(schema, fn {key, _value} -> key end, :asc)
defp maybe_sort(schema, _other), do: schema
Expand Down
10 changes: 4 additions & 6 deletions cli_options/lib/cli_options/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ defmodule CliOptions.Schema do
default: []
],
doc: [
type: :string,
type: {:or, [:string, {:in, [false]}]},
type_doc: "`t:String.t/0` or `false`",
doc: """
The documentation for the CLI option. Can be any markdown string. This will be
used in the automatically generated options documentation.
used in the automatically generated options documentation. If set to `false`
then the option will not be included in the generated docs.
"""
],
required: [
Expand Down Expand Up @@ -142,10 +144,6 @@ defmodule CliOptions.Schema do
will be raised during parsing.
"""
],
hidden: [
type: :boolean,
doc: "If set to `true` the option will not be included in the generated docs"
],
deprecated: [
type: :string,
doc: """
Expand Down
2 changes: 1 addition & 1 deletion cli_options/test/cli_options/docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule CliOptions.DocsTest do
],
hidden_option: [
type: :boolean,
hidden: true
doc: false
]
]

Expand Down
4 changes: 2 additions & 2 deletions cli_options/test/cli_options/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule CliOptions.SchemaTest do
message =
"invalid schema for :foo, unknown options [:missing, :other], valid options are: " <>
"[:type, :default, :long, :short, :aliases, :short_aliases, :doc, :required, :multiple, " <>
":allowed, :hidden, :deprecated]"
":allowed, :deprecated]"

assert_raise ArgumentError, message, fn ->
CliOptions.Schema.new!(schema)
Expand Down Expand Up @@ -101,7 +101,7 @@ defmodule CliOptions.SchemaTest do

# invalid strings
schema = [foo: [doc: 1]]
message = "invalid schema for :foo, invalid value for :doc option: expected string, got: 1"
message = ~r"invalid schema for :foo, expected :doc option"

assert_raise ArgumentError, message, fn ->
CliOptions.Schema.new!(schema)
Expand Down

0 comments on commit aad18fa

Please sign in to comment.