import Lake
open Lake DSL

meta if get_config? env = some "dev" then -- dev is so not everyone has to build it
require "leanprover" / "doc-gen4"

package "doug" where
  version := v!"0.1.0"

lean_lib «Doug» where
  -- add library configuration options here

@[default_target]
lean_exe "doug" where
  root := `Main

/--
Doug
-/
script test (args) do
  let exe := (← doug.get).file
  IO.println s!"exe: {exe}"
  IO.println s!"args: {args}"
  let proc ← IO.Process.spawn
    ⟨{stdin := .inherit, stdout := .piped, stderr := .piped},
      exe.toString, args.toArray, none, #[], false ⟩
  IO.print (← proc.stdout.readToEnd)
  IO.eprintln (← IO.FS.Handle.readToEnd proc.stderr)
  let ret ← proc.wait
  IO.println s!"returned: {ret}"
  pure ret
