Merge pull request #42 from leanprover/cli

feat: actual CLI
main
Henrik Böving 2022-02-23 22:57:52 +01:00 committed by GitHub
commit d63145c304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 pure $ lakePath.withExtension System.FilePath.exeExtension
-- Modified from the LSP Server -- Modified from the LSP Server
def lakeSetupSearchPath (lakePath : System.FilePath) (imports : Array String) : IO Lean.SearchPath := do def lakeSetupSearchPath (lakePath : System.FilePath) (imports : List String) : IO Lean.SearchPath := do
let args := #["print-paths"] ++ imports let args := "print-paths" :: imports
let cmdStr := " ".intercalate (toString lakePath :: args.toList) let cmdStr := " ".intercalate (toString lakePath :: args)
let lakeProc ← Process.spawn { let lakeProc ← Process.spawn {
stdin := Process.Stdio.null stdin := Process.Stdio.null
stdout := Process.Stdio.piped stdout := Process.Stdio.piped
stderr := Process.Stdio.piped stderr := Process.Stdio.piped
cmd := lakePath.toString cmd := lakePath.toString
args args := args.toArray
} }
let stdout := String.trim (← lakeProc.stdout.readToEnd) let stdout := String.trim (← lakeProc.stdout.readToEnd)
let stderr := String.trim (← lakeProc.stderr.readToEnd) let stderr := String.trim (← lakeProc.stderr.readToEnd)

View File

@ -1,17 +1,27 @@
import DocGen4 import DocGen4
import Lean import Lean
import Cli
open DocGen4 Lean IO open DocGen4 Lean Cli
def main (args : List String) : IO Unit := do def runDocGenCmd (p : Parsed) : IO UInt32 := do
if args.isEmpty then let root := p.positionalArg! "root" |>.as! String
IO.println "Usage: doc-gen4 root/url/ Module1 Module2 ..." let modules : List String := p.variableArgsAs! String |>.toList
IO.Process.exit 1 let path ← lakeSetupSearchPath (←getLakePath) modules
return
let root := args.head!
let modules := args.tail!
let path ← lakeSetupSearchPath (←getLakePath) modules.toArray
IO.println s!"Loading modules from: {path}" IO.println s!"Loading modules from: {path}"
let doc ← load $ modules.map Name.mkSimple let doc ← load $ modules.map Name.mkSimple
IO.println "Outputting HTML" IO.println "Outputting HTML"
htmlOutput doc root 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 name := `Unicode
src := Source.git "https://github.com/xubaiw/Unicode.lean" "3b7b85472d42854a474099928a3423bb97d4fa64" src := Source.git "https://github.com/xubaiw/Unicode.lean" "3b7b85472d42854a474099928a3423bb97d4fa64"
},
{
name := `Cli
src := Source.git "https://github.com/mhuisi/lean4-cli" "1f8663e3dafdcc11ff476d74ef9b99ae5bdaedd3"
} }
] ]
} }