@@ -35,14 +35,37 @@ defmodule ExDoc.CLI do
3535 quiet: :boolean ,
3636 source_ref: :string ,
3737 source_url: :string ,
38- version: :boolean
38+ version: :boolean ,
39+ warnings_as_errors: :boolean
3940 ]
4041 )
4142
4243 if List . keymember? ( opts , :version , 0 ) do
4344 IO . puts ( "ExDoc v#{ ExDoc . version ( ) } " )
4445 else
45- generate ( args , opts , generator )
46+ results = generate ( args , opts , generator )
47+ error_results = Enum . filter ( results , & ( elem ( & 1 , 0 ) == :error ) )
48+
49+ if error_results == [ ] do
50+ Enum . map ( results , fn { :ok , value } -> value end )
51+ else
52+ formatters = Enum . map ( error_results , & elem ( & 1 , 1 ) . formatter )
53+
54+ format_message =
55+ case formatters do
56+ [ formatter ] -> "#{ formatter } format"
57+ _ -> "#{ Enum . join ( formatters , ", " ) } formats"
58+ end
59+
60+ message =
61+ "Documents have been generated, but generation for #{ format_message } failed due to warnings while using the --warnings-as-errors option."
62+
63+ message_formatted = IO.ANSI . format ( [ :red , message , :reset ] )
64+
65+ IO . puts ( :stderr , message_formatted )
66+
67+ exit ( { :shutdown , 1 } )
68+ end
4669 end
4770 end
4871
@@ -71,7 +94,11 @@ defmodule ExDoc.CLI do
7194 quiet? ||
7295 IO . puts ( IO.ANSI . format ( [ :green , "View #{ inspect ( formatter ) } docs at #{ inspect ( index ) } " ] ) )
7396
74- index
97+ if opts [ :warnings_as_errors ] == true and ExDoc.Utils . warned? ( ) do
98+ { :error , % { reason: :warnings_as_errors , formatter: formatter } }
99+ else
100+ { :ok , index }
101+ end
75102 end
76103 end
77104
@@ -164,29 +191,30 @@ defmodule ExDoc.CLI do
164191 ex_doc "Project" "1.0.0" "_build/dev/lib/project/ebin" -c "docs.exs"
165192
166193 Options:
167- PROJECT Project name
168- VERSION Version number
169- BEAMS Path to compiled beam files
170- --canonical Indicate the preferred URL with rel="canonical" link element
171- -c, --config Give configuration through a file instead of a command line.
172- See "Custom config" section below for more information.
173- -f, --formatter Docs formatter to use (html or epub), default: html and epub
174- --homepage-url URL to link to for the site name
175- --language Identify the primary language of the documents, its value must be
176- a valid [BCP 47](https://tools.ietf.org/html/bcp47) language tag, default: "en"
177- -l, --logo Path to a logo image for the project. Must be PNG, JPEG or SVG. The image will
178- be placed in the output "assets" directory.
179- -m, --main The entry-point page in docs, default: "api-reference"
180- -o, --output Path to output docs, default: "doc"
181- --package Hex package name
182- --paths Prepends the given path to Erlang code path. The path might contain a glob
183- pattern but in that case, remember to quote it: --paths "_build/dev/lib/*/ebin".
184- This option can be given multiple times
185- --proglang The project's programming language, default: "elixir"
186- -q, --quiet Only output warnings and errors
187- --source-ref Branch/commit/tag used for source link inference, default: "master"
188- -u, --source-url URL to the source code
189- -v, --version Print ExDoc version
194+ PROJECT Project name
195+ VERSION Version number
196+ BEAMS Path to compiled beam files
197+ --canonical Indicate the preferred URL with rel="canonical" link element
198+ -c, --config Give configuration through a file instead of a command line.
199+ See "Custom config" section below for more information.
200+ -f, --formatter Docs formatter to use (html or epub), default: html and epub
201+ --homepage-url URL to link to for the site name
202+ --language Identify the primary language of the documents, its value must be
203+ a valid [BCP 47](https://tools.ietf.org/html/bcp47) language tag, default: "en"
204+ -l, --logo Path to a logo image for the project. Must be PNG, JPEG or SVG. The image will
205+ be placed in the output "assets" directory.
206+ -m, --main The entry-point page in docs, default: "api-reference"
207+ -o, --output Path to output docs, default: "doc"
208+ --package Hex package name
209+ --paths Prepends the given path to Erlang code path. The path might contain a glob
210+ pattern but in that case, remember to quote it: --paths "_build/dev/lib/*/ebin".
211+ This option can be given multiple times.
212+ --proglang The project's programming language, default: "elixir".
213+ -q, --quiet Only output warnings and errors.
214+ --source-ref Branch/commit/tag used for source link inference, default: "master".
215+ -u, --source-url URL to the source code.
216+ -v, --version Print ExDoc version.
217+ --warnings-as-errors Exit with non-zero status if doc generation produces warnings.
190218
191219 ## Custom config
192220
0 commit comments