bookshelf-doc/Main.lean

83 lines
2.5 KiB
Plaintext
Raw Normal View History

2021-11-27 15:19:56 +00:00
import DocGen4
import Lean
2022-02-23 21:54:10 +00:00
import Cli
2021-11-27 15:19:56 +00:00
2022-02-23 21:54:10 +00:00
open DocGen4 Lean Cli
2021-11-27 15:19:56 +00:00
def getTopLevelModules (p : Parsed) : IO (List String) := do
let topLevelModules := p.variableArgsAs! String |>.toList
if topLevelModules.length == 0 then
2022-07-23 11:01:25 +00:00
throw <| IO.userError "No topLevelModules provided."
pure topLevelModules
def runSingleCmd (p : Parsed) : IO UInt32 := do
let relevantModules := [p.positionalArg! "module" |>.as! String]
2022-07-21 20:43:33 +00:00
let res ← lakeSetup (relevantModules)
match res with
2022-07-21 00:25:26 +00:00
| Except.ok ws =>
2022-07-21 20:43:33 +00:00
let relevantModules := relevantModules.map String.toName
let (doc, hierarchy) ← load (.loadAllLimitAnalysis relevantModules)
IO.println "Outputting HTML"
let baseConfig := getSimpleBaseContext hierarchy
2022-07-26 11:56:22 +00:00
htmlOutputResults baseConfig doc ws (p.hasFlag "ink")
pure 0
| Except.error rc => pure rc
2022-02-23 21:54:10 +00:00
2022-07-23 11:04:36 +00:00
def runIndexCmd (_p : Parsed) : IO UInt32 := do
2022-07-26 10:52:41 +00:00
let hierarchy ← Hierarchy.fromDirectory Output.basePath
let baseConfig := getSimpleBaseContext hierarchy
htmlOutputIndex baseConfig
pure 0
def runDocGenCmd (p : Parsed) : IO UInt32 := do
let modules : List String := p.variableArgsAs! String |>.toList
if modules.length == 0 then
2022-07-23 11:01:25 +00:00
throw <| IO.userError "No modules provided."
let res ← lakeSetup modules
match res with
| Except.ok ws =>
IO.println s!"Loading modules from: {←searchPathRef.get}"
2022-07-21 20:43:33 +00:00
let modules := modules.map String.toName
let (doc, hierarchy) ← load (.loadAll modules)
IO.println "Outputting HTML"
2022-07-26 11:56:22 +00:00
htmlOutput doc hierarchy ws (p.hasFlag "ink")
pure 0
| Except.error rc => pure rc
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."
FLAGS:
2022-07-26 11:56:22 +00:00
ink; "Render the files with LeanInk in addition"
ARGS:
module : String; "The module to generate the HTML for. Does not have to be part of topLevelModules."
]
2022-07-21 19:12:15 +00:00
def indexCmd := `[Cli|
index VIA runIndexCmd;
"Index the documentation that has been generated by single."
2022-07-21 17:07:35 +00:00
ARGS:
...topLevelModule : String; "The top level modules this documentation will be for."
]
2022-02-23 21:54:10 +00:00
def docGenCmd : Cmd := `[Cli|
"doc-gen4" VIA runDocGenCmd; ["0.0.1"]
"A documentation generator for Lean 4."
FLAGS:
2022-07-26 11:56:22 +00:00
ink; "Render the files with LeanInk in addition"
2022-02-23 21:54:10 +00:00
ARGS:
...modules : String; "The modules to generate the HTML for."
SUBCOMMANDS:
singleCmd;
2022-07-21 19:12:15 +00:00
indexCmd
2022-02-23 21:54:10 +00:00
]
def main (args : List String) : IO UInt32 :=
docGenCmd.validate args