From 5b62e442c2450036f32507888721ffcdd051a565 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Wed, 6 Nov 2024 03:05:26 +0100 Subject: [PATCH] Add --version option to Runic.main (#92) --- src/Runic.jl | 4 ++++ src/main.jl | 11 +++++++++++ test/runtests.jl | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/src/Runic.jl b/src/Runic.jl index e777dd2..a9c06a1 100644 --- a/src/Runic.jl +++ b/src/Runic.jl @@ -5,6 +5,10 @@ module Runic using JuliaSyntax: JuliaSyntax, @K_str, @KSet_str +const RUNIC_VERSION = pkgversion(@__MODULE__) +# XXX: This should probably be handled by Base. +Base.include_dependency(joinpath(pkgdir(@__MODULE__), "Project.toml")) + # Debug and assert utilities include("debug.jl") include("JuliaSyntax.jl") diff --git a/src/main.jl b/src/main.jl index 4d7951b..8008cc2 100644 --- a/src/main.jl +++ b/src/main.jl @@ -140,11 +140,19 @@ function print_help() -o , --output= File to write formatted output to. If no output is given, or if the file is `-`, output is written to stdout. + + --version + Print Runic and julia version information. """ ) return end +function print_version() + println(stdout, "runic version $(RUNIC_VERSION), julia version $(VERSION)") + return +end + function maybe_expand_directory!(outfiles, dir) if !isdir(dir) # Assumed to be a file, checked when using it @@ -205,6 +213,9 @@ function main(argv) elseif x == "--help" print_help() return errno + elseif x == "--version" + print_version() + return errno elseif x == "-q" || x == "--quiet" quiet = true elseif x == "-v" || x == "--verbose" diff --git a/test/runtests.jl b/test/runtests.jl index 7b85dca..2f1c1a5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1487,6 +1487,13 @@ end @test isempty(fd2) end + # runic --version + let (rc, fd1, fd2) = runic(["--version"]) + @test rc == 0 + @test occursin("runic version $(Runic.RUNIC_VERSION), julia version $(VERSION)", fd1) + @test isempty(fd2) + end + # runic stdout for argv in [ String[], ["-"],