Skip to content

Commit 682173d

Browse files
authored
feat: #version command (leanprover#5768)
Prints `Lean.versionString` and target/platform information. Example: ``` Lean 4.12.0, commit 8218940 Target: arm64-apple-darwin23.5.0 macOS ```
1 parent 26df545 commit 682173d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Lean/Elab/BuiltinCommand.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Lean.Elab.Eval
1212
import Lean.Elab.Command
1313
import Lean.Elab.Open
1414
import Lean.Elab.SetOption
15+
import Init.System.Platform
1516

1617
namespace Lean.Elab.Command
1718

@@ -404,6 +405,16 @@ def failIfSucceeds (x : CommandElabM Unit) : CommandElabM Unit := do
404405
includedVars := sc.includedVars.filter (!omittedVars.contains ·) }
405406
| _ => throwUnsupportedSyntax
406407

408+
@[builtin_command_elab version] def elabVersion : CommandElab := fun _ => do
409+
let mut target := System.Platform.target
410+
if target.isEmpty then target := "unknown"
411+
-- Only one should be set, but good to know if multiple are set in error.
412+
let platforms :=
413+
(if System.Platform.isWindows then [" Windows"] else [])
414+
++ (if System.Platform.isOSX then [" macOS"] else [])
415+
++ (if System.Platform.isEmscripten then [" Emscripten"] else [])
416+
logInfo m!"Lean {Lean.versionString}\nTarget: {target}{String.join platforms}"
417+
407418
@[builtin_command_elab Parser.Command.exit] def elabExit : CommandElab := fun _ =>
408419
logWarning "using 'exit' to interrupt Lean"
409420

src/Lean/Parser/Command.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ Displays all available tactic tags, with documentation.
505505
-/
506506
@[builtin_command_parser] def printTacTags := leading_parser
507507
"#print " >> nonReservedSymbol "tactic " >> nonReservedSymbol "tags"
508+
/-- Shows the current Lean version. Prints `Lean.versionString`. -/
509+
@[builtin_command_parser] def version := leading_parser
510+
"#version"
508511
@[builtin_command_parser] def «init_quot» := leading_parser
509512
"init_quot"
510513
def optionValue := nonReservedSymbol "true" <|> nonReservedSymbol "false" <|> strLit <|> numLit

0 commit comments

Comments
 (0)