@@ -21,6 +21,8 @@ defmodule Mix.Tasks.Docs do
21
21
* `--output`, `-o` - Output directory for the generated
22
22
docs, default: `"doc"`
23
23
24
+ * `--open` - open browser window pointed to the documentation
25
+
24
26
The command line options have higher precedence than the options
25
27
specified in your `mix.exs` file below.
26
28
@@ -32,17 +34,21 @@ defmodule Mix.Tasks.Docs do
32
34
from ExDoc, for example:
33
35
34
36
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
+ ]
46
52
end
47
53
48
54
ExDoc also allows configuration specific to the documentation to
@@ -301,7 +307,8 @@ defmodule Mix.Tasks.Docs do
301
307
canonical: :string ,
302
308
formatter: :keep ,
303
309
language: :string ,
304
- output: :string
310
+ output: :string ,
311
+ open: :boolean
305
312
]
306
313
307
314
@ aliases [ n: :canonical , f: :formatter , o: :output ]
@@ -351,6 +358,11 @@ defmodule Mix.Tasks.Docs do
351
358
for formatter <- get_formatters ( options ) do
352
359
index = generator . ( project , version , Keyword . put ( options , :formatter , formatter ) )
353
360
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
+
354
366
index
355
367
end
356
368
end
@@ -465,4 +477,15 @@ defmodule Mix.Tasks.Docs do
465
477
options
466
478
end
467
479
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
468
491
end
0 commit comments