Skip to content

Commit e6a2775

Browse files
committed
feat: added --version flag to CLI
1 parent 2e23f03 commit e6a2775

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ build --enable_runfiles
66

77
build:windows --platforms=//bazel/platforms:windows
88
build:windows --host_platform=//bazel/platforms:windows
9+
build:windows --workspace_status_command=bazel/tools/wsc.cmd
910

1011
build:linux --platforms=//bazel/platforms:linux
1112
build:linux --host_platform=//bazel/platforms:linux
1213
build:linux --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux
14+
build:linux --workspace_status_command=bazel/tools/wsc.sh
1315

1416
common:ci --announce_rc
1517
common:ci --disk_cache=~/.cache/bazel-disk-cache

WORKSPACE.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
5252

5353
rules_pkg_dependencies()
5454

55+
http_archive(
56+
name = "rules_cc_stamp",
57+
strip_prefix = "rules_cc_stamp-63d4861f4d420b574fa0f112599aae2b8aee785e",
58+
urls = ["https://github.com/zaucy/rules_cc_stamp/archive/63d4861f4d420b574fa0f112599aae2b8aee785e.zip"],
59+
sha256 = "f469a3b97eeabeb850c655f59ea17799ff40badd3a0b3e9de38534c89ad2f87d",
60+
)
61+
5562
http_archive(
5663
name = "ecsact_si_wasm",
5764
sha256 = "4153154fd80e2cd48ddd8e0d0c208691f134b33d5c67dc6fc081b3f77149b2c2",

bazel/tools/wsc.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
3+
for /f %%i in ('git describe --tags --abbrev^=0') do set GIT_TAG=%%i
4+
echo STABLE_GIT_TAG %GIT_TAG%
5+

bazel/tools/wsc.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo GIT_TAG=$(git describe --tags --abbrev=0)
6+

cli/BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
load("@rules_cc//cc:defs.bzl", "cc_binary")
2+
load("@rules_cc_stamp//:index.bzl", "cc_stamp_header")
23
load("//bazel:copts.bzl", "copts")
34

45
package(default_visibility = ["//visibility:public"])
56

7+
cc_stamp_header(
8+
name = "bazel_stamp_header",
9+
out = "bazel_stamp_header.hh",
10+
)
11+
612
cc_binary(
713
name = "ecsact",
8-
srcs = ["cli.cc"],
14+
srcs = ["cli.cc", "bazel_stamp_header.hh"],
915
copts = copts,
16+
stamp = 1,
1017
deps = [
1118
"//cli/commands:codegen",
1219
"//cli/commands:command",

cli/cli.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string>
44
#include <string_view>
55
#include <unordered_map>
6+
#include "cli/bazel_stamp_header.hh"
67

78
#include "./commands/command.hh"
89
#include "./commands/codegen.hh"
@@ -25,9 +26,9 @@ constexpr auto USAGE = R"(Ecsact SDK Command Line
2526
2627
Usage:
2728
ecsact (--help | -h)
29+
ecsact (--version | -v)
2830
ecsact config ([<options>...] | --help)
2931
ecsact codegen ([<options>...] | --help)
30-
3132
)";
3233

3334
std::string colorize_logo() {
@@ -74,6 +75,9 @@ int main(int argc, char* argv[]) {
7475
if(command == "-h" || command == "--help") {
7576
print_usage();
7677
return 0;
78+
} else if(command == "-v" || command == "--version") {
79+
std::cout << STABLE_GIT_TAG << "\n";
80+
return 0;
7781
} else if(command.starts_with('-')) {
7882
std::cerr << "Expected subcommand and instead got '" << command << "'\n";
7983
print_usage();

0 commit comments

Comments
 (0)