@@ -21,6 +21,8 @@ defmodule Mix.Tasks.Docs do
2121 * `--output`, `-o` - Output directory for the generated
2222 docs, default: `"doc"`
2323
24+ * `--open` - open browser window pointed to the documentation
25+
2426 The command line options have higher precedence than the options
2527 specified in your `mix.exs` file below.
2628
@@ -32,17 +34,21 @@ defmodule Mix.Tasks.Docs do
3234 from ExDoc, for example:
3335
3436 def project do
35- [app: :my_app,
36- version: "0.1.0-dev",
37- deps: deps(),
38-
39- # Docs
40- name: "My App",
41- source_url: "https://github.com/USER/PROJECT",
42- homepage_url: "http://YOUR_PROJECT_HOMEPAGE",
43- docs: [main: "MyApp", # The main page in the docs
44- logo: "path/to/logo.png",
45- extras: ["README.md"]]]
37+ [
38+ app: :my_app,
39+ version: "0.1.0-dev",
40+ deps: deps(),
41+
42+ # Docs
43+ name: "My App",
44+ source_url: "https://github.com/USER/PROJECT",
45+ homepage_url: "http://YOUR_PROJECT_HOMEPAGE",
46+ docs: [
47+ main: "MyApp", # The main page in the docs
48+ logo: "path/to/logo.png",
49+ extras: ["README.md"]
50+ ]
51+ ]
4652 end
4753
4854 ExDoc also allows configuration specific to the documentation to
@@ -301,7 +307,8 @@ defmodule Mix.Tasks.Docs do
301307 canonical: :string ,
302308 formatter: :keep ,
303309 language: :string ,
304- output: :string
310+ output: :string ,
311+ open: :boolean
305312 ]
306313
307314 @ aliases [ n: :canonical , f: :formatter , o: :output ]
@@ -351,6 +358,11 @@ defmodule Mix.Tasks.Docs do
351358 for formatter <- get_formatters ( options ) do
352359 index = generator . ( project , version , Keyword . put ( options , :formatter , formatter ) )
353360 Mix . shell ( ) . info ( [ :green , "View #{ inspect ( formatter ) } docs at #{ inspect ( index ) } " ] )
361+
362+ if cli_opts [ :open ] do
363+ browser_open ( index )
364+ end
365+
354366 index
355367 end
356368 end
@@ -465,4 +477,15 @@ defmodule Mix.Tasks.Docs do
465477 options
466478 end
467479 end
480+
481+ defp browser_open ( url ) do
482+ { cmd , args } =
483+ case :os . type ( ) do
484+ { :win32 , _ } -> { "cmd" , [ "/c" , "start" , url ] }
485+ { :unix , :darwin } -> { "open" , [ url ] }
486+ { :unix , _ } -> { "xdg-open" , [ url ] }
487+ end
488+
489+ System . cmd ( cmd , args )
490+ end
468491end
0 commit comments