lean4-htt/Lake/CLI/Help.lean
2022-07-28 23:31:39 -04:00

237 lines
7.4 KiB
Text

/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sebastian Ullrich, Mac Malone
-/
import Lake.Version
namespace Lake
def usage :=
uiVersionString ++ "
USAGE:
lake [OPTIONS] <COMMAND>
OPTIONS:
--version print version and exit
--help, -h print help of the program or a command and exit
--dir, -d=file use the package configuration in a specific directory
--file, -f=file use a specific file for the package configuration
--quiet, -q hide progress messages
--verbose, -v show verbose information (command invocations)
--lean=cmd specify the `lean` command used by Lake
-K key[=value] set the configuration file option named key
COMMANDS:
new <name> [<temp>] create a Lean package in a new directory
init <name> [<temp>] create a Lean package in the current directory
build [<targets>...] build targets
update update dependencies
upload <tag> upload build artifacts to a GitHub release
clean remove build outputs
script manage and run workspace scripts
scripts shorthand for `lake script list`
run <script> shorthand for `lake script run`
serve start the Lean language server
env <cmd> [<args>...] execute a command in the workspace's environment
exe <exe> [<args>...] build an exe and run it in the workspace's environment
See `lake help <command>` for more information on a specific command."
def templateHelp :=
s!"The initial configuration and starter files are based on the template:
std library and executable; default
exe executable only
lib library only
math library only with a mathlib dependency"
def helpNew :=
s!"Create a Lean package in a new directory
USAGE:
lake new <name> [<template>]
{templateHelp}"
def helpInit :=
s!"Create a Lean package in the current directory
USAGE:
lake init <name> [<template>]
{templateHelp}"
def helpBuild :=
"Build targets
USAGE:
lake build [<targets>...]
A target is specified with a string of the form:
[[@]<package>/][<target>|[+]<module>][:<facet>]
The optional `@` and `+` markers can be used to disambiguate packages
and modules from other kinds of targets (i.e., executables and libraries).
LIBRARY FACETS: build the library's ...
lean (default) Lean binaries (*.olean and *.ilean files)
static static binary (*.a file)
shared shared binary (*.so, *.dll, or *.dylib file)
MODULE FACETS: build the module's ...
bin (default) Lean binaries (*.olean and *.ilean files)
c C file produced by `lean`
o *.o object file (of its `lean.c` C file)
dynlib shared library (e.g., for `--load-dynlib`)
TARGET EXAMPLES: build the ...
a default facet of target `a`
@a default target(s) of package `a`
+A olean and .ilean files of module `A`
a/b default facet of target `b` of package `a`
a/+A:c C file of module `A` of package `a`
:foo facet `foo` of the root package
A bare `build` command will build the default facet of the root package.
Package dependencies are not updated during a build."
def helpUpdate :=
"Update dependencies
USAGE:
lake update
This command sets up the directory with the package's dependencies
(i.e., `packagesDir`, which is, by default, `lean_packages`).
For each (transitive) git dependency, the specified commit is checked out
into a sub-directory of `packagesDir`. Already checked out dependencies are
updated to the latest version compatible with the package's configuration.
If there are dependencies on multiple versions of the same package, the
version materialized is undefined. The specific revision of the resolved
packages are cached in the `manifest.json` file of the `packagesDir`.
No copy is made of local dependencies."
def helpUpload :=
"Upload build artifacts to a GitHub release
USAGE:
lake upload <tag>
Packs the root package's `buildDir` into a `tar.gz` archive using `tar` and
then uploads the asset to the pre-existing GitHub release `tag` using `gh`."
def helpClean :=
"Remove build outputs
USAGE:
lake clean
Deletes the build directory of the package."
def helpScriptCli :=
"Manage Lake scripts
USAGE:
lake script <COMMAND>
COMMANDS:
list list available scripts
run <script> run a script
doc <script> print the docstring of a given script
See `lake help <command>` for more information on a specific command."
def helpScriptList :=
"List available scripts
USAGE:
lake script list
This command prints the list of all available scripts in the workspace."
def helpScriptRun :=
"Run a script
USAGE:
lake script run [<package>/]<script> [<args>...]
This command runs the given `script` from `package`, passing `args` to it.
Defaults to the root package."
def helpScriptDoc :=
"Print a script's docstring
USAGE:
lake script doc [<package>/]<script>
Print the docstring of `script` in `package`. Defaults to the root package."
def helpServe :=
"Start the Lean language server
USAGE:
lake serve [-- <args>...]
Run the language server of the Lean installation (i.e., via `lean --server`)
with the package configuration's `moreServerArgs` field and `args`.
"
def helpEnv :=
"Execute a command in the workspace's environment
USAGE:
lake env <cmd> [<args>...]
Spawns a new process executing `cmd` with the given `args` and with
the environment set based on the workspace configuration and the detected
Lean/Lake installations.
Specifically, this command sets the following environment variables:
LAKE set to the detected Lake executable
LAKE_HOME set to the detected Lake home
LEAN_SYSROOT set to the detected Lean sysroot
LEAN_AR set to the detected Lean `ar` binary
LEAN_CC set to the detected `cc` (if not using bundled one)
LEAN_PATH adds the workspace's library directories
LEAN_SRC_PATH adds the workspace's source directories
PATH adds the workspace's library directories (Windows)
DYLD_LIBRARY_PATH adds the workspace's library directories (MacOS)
LD_LIBRARY_PATH adds the workspace's library directories (other Unix)"
def helpExe :=
"Build an executable target and run it in the workspace's environment
USAGE:
lake exe <exe-target> [<args>...]
Looks for the executable target in the workspace (see `lake help build` to
learn how to specify targets), builds it if it is out of date, and then runs
it with the given `args` in the workspace's environment (see `lake help env`
for how the environment is set)."
def helpScript : (cmd : String) → String
| "list" => helpScriptList
| "run" => helpScriptRun
| "doc" => helpScriptDoc
| _ => helpScriptCli
def help : (cmd : String) → String
| "new" => helpNew
| "init" => helpInit
| "build" => helpBuild
| "update" => helpUpdate
| "upload" => helpUpload
| "clean" => helpClean
| "script" => helpScriptCli
| "scripts" => helpScriptList
| "run" => helpScriptRun
| "serve" => helpServe
| "env" => helpEnv
| "exe" => helpExe
| _ => usage