feat: actual CLI

main
Henrik Böving 2022-02-23 22:54:10 +01:00
parent 9dd5e316c1
commit 34d2239b68
3 changed files with 27 additions and 13 deletions

View File

@ -20,15 +20,15 @@ def getLakePath : IO FilePath := do
pure $ lakePath.withExtension System.FilePath.exeExtension
-- Modified from the LSP Server
def lakeSetupSearchPath (lakePath : System.FilePath) (imports : Array String) : IO Lean.SearchPath := do
let args := #["print-paths"] ++ imports
let cmdStr := " ".intercalate (toString lakePath :: args.toList)
def lakeSetupSearchPath (lakePath : System.FilePath) (imports : List String) : IO Lean.SearchPath := do
let args := "print-paths" :: imports
let cmdStr := " ".intercalate (toString lakePath :: args)
let lakeProc ← Process.spawn {
stdin := Process.Stdio.null
stdout := Process.Stdio.piped
stderr := Process.Stdio.piped
cmd := lakePath.toString
args
args := args.toArray
}
let stdout := String.trim (← lakeProc.stdout.readToEnd)
let stderr := String.trim (← lakeProc.stderr.readToEnd)

View File

@ -1,17 +1,27 @@
import DocGen4
import Lean
import Cli
open DocGen4 Lean IO
open DocGen4 Lean Cli
def main (args : List String) : IO Unit := do
if args.isEmpty then
IO.println "Usage: doc-gen4 root/url/ Module1 Module2 ..."
IO.Process.exit 1
return
let root := args.head!
let modules := args.tail!
let path ← lakeSetupSearchPath (←getLakePath) modules.toArray
def runDocGenCmd (p : Parsed) : IO UInt32 := do
let root := p.positionalArg! "root" |>.as! String
let modules : List String := p.variableArgsAs! String |>.toList
let path ← lakeSetupSearchPath (←getLakePath) modules
IO.println s!"Loading modules from: {path}"
let doc ← load $ modules.map Name.mkSimple
IO.println "Outputting HTML"
htmlOutput doc root
pure 0
def docGenCmd : Cmd := `[Cli|
"doc-gen4" VIA runDocGenCmd; ["0.0.1"]
"A documentation generator for Lean 4."
ARGS:
root : String; "The root URL to generate the HTML for (will be relative in the future)"
...modules : String; "The modules to generate the HTML for"
]
def main (args : List String) : IO UInt32 :=
docGenCmd.validate args

View File

@ -12,6 +12,10 @@ package «doc-gen4» {
{
name := `Unicode
src := Source.git "https://github.com/xubaiw/Unicode.lean" "3b7b85472d42854a474099928a3423bb97d4fa64"
},
{
name := `Cli
src := Source.git "https://github.com/mhuisi/lean4-cli" "1f8663e3dafdcc11ff476d74ef9b99ae5bdaedd3"
}
]
}