forked from leanprover/doc-gen4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.lean
107 lines (88 loc) · 3.5 KB
/
Main.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import DocGen4
import Lean
import Cli
open DocGen4 Lean Cli
def getTopLevelModules (p : Parsed) : IO (List String) := do
let topLevelModules := p.variableArgsAs! String |>.toList
if topLevelModules.length == 0 then
throw <| IO.userError "No topLevelModules provided."
return topLevelModules
def runHeaderDataCmd (_p : Parsed) : IO UInt32 := do
headerDataOutput
return 0
def runSingleCmd (p : Parsed) : IO UInt32 := do
let relevantModules := #[p.positionalArg! "module" |>.as! String |> String.toName]
let sourceUri := p.positionalArg! "sourceUri" |>.as! String
let (doc, hierarchy) ← load <| .loadAllLimitAnalysis relevantModules
let baseConfig ← getSimpleBaseContext hierarchy
htmlOutputResults baseConfig doc (some sourceUri)
return 0
def runIndexCmd (_p : Parsed) : IO UInt32 := do
let hierarchy ← Hierarchy.fromDirectory Output.basePath
let baseConfig ← getSimpleBaseContext hierarchy
htmlOutputIndex baseConfig
return 0
def runGenCoreCmd (_p : Parsed) : IO UInt32 := do
let (doc, hierarchy) ← loadCore
let baseConfig ← getSimpleBaseContext hierarchy
htmlOutputResults baseConfig doc none
return 0
def runDocGenCmd (_p : Parsed) : IO UInt32 := do
IO.println "You most likely want to use me via Lake now, check my README on Github on how to:"
IO.println "https://github.com/leanprover/doc-gen4"
return 0
def runBibPrepassCmd (p : Parsed) : IO UInt32 := do
if p.hasFlag "none" then
IO.println "INFO: reference page disabled"
disableBibFile
else
match p.variableArgsAs! String with
| #[source] =>
let contents ← IO.FS.readFile source
if p.hasFlag "json" then
IO.println "INFO: 'references.json' will be copied to the output path; there will be no 'references.bib'"
preprocessBibJson contents
else
preprocessBibFile contents Bibtex.process
| _ => throw <| IO.userError "there should be exactly one source file"
return 0
def singleCmd := `[Cli|
single VIA runSingleCmd;
"Only generate the documentation for the module it was given, might contain broken links unless all documentation is generated."
ARGS:
module : String; "The module to generate the HTML for. Does not have to be part of topLevelModules."
sourceUri : String; "The sourceUri as computed by the Lake facet"
]
def indexCmd := `[Cli|
index VIA runIndexCmd;
"Index the documentation that has been generated by single."
]
def genCoreCmd := `[Cli|
genCore VIA runGenCoreCmd;
"Generate documentation for the core Lean modules: Init and Lean since they are not Lake projects"
]
def bibPrepassCmd := `[Cli|
bibPrepass VIA runBibPrepassCmd;
"Run the bibliography prepass: copy the bibliography file to output directory. By default it assumes the input is '.bib'."
FLAGS:
n, none; "Disable bibliography in this project."
j, json; "The input file is '.json' which contains an array of objects with 4 fields: 'citekey', 'tag', 'html' and 'plaintext'."
ARGS:
...source : String; "The bibliography file. We only support one file for input. Should be '.bib' or '.json' according to flags."
]
def headerDataCmd := `[Cli|
headerData VIA runHeaderDataCmd;
"Produce `header-data.bmp`, this allows embedding of doc-gen declarations into other pages and more."
]
def docGenCmd : Cmd := `[Cli|
"doc-gen4" VIA runDocGenCmd; ["0.1.0"]
"A documentation generator for Lean 4."
SUBCOMMANDS:
singleCmd;
indexCmd;
genCoreCmd;
bibPrepassCmd;
headerDataCmd
]
def main (args : List String) : IO UInt32 :=
docGenCmd.validate args