make version info available

This commit is contained in:
Robert Bendun 2023-01-14 22:48:15 +01:00
parent e008a45cf7
commit 4178308e96
3 changed files with 27 additions and 1 deletions

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Builtin function documentation generation from C++ Musique implementation source code
- New builtins: digits
- Negative numbers!
- Version command via `:version` in REPL or `--version`, `-v` in command line.
### Removed

View File

@ -1,7 +1,18 @@
MAKEFLAGS="-j $(grep -c ^processor /proc/cpuinfo)"
MAJOR := 0
MINOR := 3
PATCH := 1
COMMIT := gc$(shell git rev-parse --short HEAD 2>/dev/null)
ifeq ($(COMMIT),gc)
COMMIT = "gcunknown"
endif
VERSION := $(MAJOR).$(MINOR).$(PATCH)-dev+$(COMMIT)
CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result
CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/
CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ -DMusique_Version='"$(VERSION)"'
LDFLAGS=-flto
LDLIBS= -lpthread

View File

@ -84,6 +84,9 @@ static T pop(std::span<char const*> &span)
" --ast\n"
" prints ast for given code\n"
"\n"
" -v,--version\n"
" prints Musique interpreter version\n"
"\n"
"Thanks to:\n"
" Sy Brand, https://sybrand.ink/, creator of tl::expected https://github.com/TartanLlama/expected\n"
" Justine Tunney, https://justinetunney.com, creator of bestline readline library https://github.com/jart/bestline\n"
@ -289,6 +292,12 @@ static Result<bool> handle_repl_session_commands(std::string_view input, Runner
std::exit(0);
}
},
Command { "version",
+[](Runner&, std::optional<std::string_view>) -> std::optional<Error> {
std::cout << Musique_Version << std::endl;
return {};
},
},
Command { "clear",
+[](Runner&, std::optional<std::string_view>) -> std::optional<Error> {
std::cout << "\x1b[1;1H\x1b[2J" << std::flush;
@ -424,6 +433,11 @@ static std::optional<Error> Main(std::span<char const*> args)
continue;
}
if (arg == "--version" || arg == "-v") {
std::cout << Musique_Version << std::endl;
return {};
}
if (arg == "-o" || arg == "--output") {
if (args.empty()) {
std::cerr << "musique: error: option " << arg << " requires an argument" << std::endl;