Skip to content

Commit a79d971

Browse files
committed
feat: improve the --version output
1 parent 8872617 commit a79d971

File tree

9 files changed

+117
-29
lines changed

9 files changed

+117
-29
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
!crates/
33
!Cargo.toml
44
!Cargo.lock
5-
.env
5+
.env
6+
!.git/HEAD

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343
- uses: Swatinem/rust-cache@v2
4444
- name: Run cargo check
4545
run: cargo check --locked --release --package ${{ matrix.package }}
46+
- name: Print version
47+
if: matrix.package == 'yozefu'
48+
run: cargo run -- --version
4649

4750
build:
4851
name: Build w/o features

Cargo.lock

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/command/Cargo.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,21 @@ rdkafka = { version = "0.37.0", features = [
4040
"libz-static",
4141
"curl-static",
4242
"zstd",
43-
"external-lz4"
43+
"external-lz4",
4444
] }
4545
extism = { version = "1.10.0" }
4646
indexmap = "2.8.0"
4747
tui = { workspace = true }
4848
app = { workspace = true }
4949
lib = { workspace = true }
5050
reqwest = { version = "0.12.15", features = ["json"] }
51+
const_format = { version = "0.2.34", features = ["rust_1_64"] }
52+
const-str = "0.6.2"
5153

5254
[features]
53-
ssl-vendored = [
54-
"rdkafka/ssl-vendored",
55-
"tui/ssl-vendored",
56-
"app/ssl-vendored"
57-
]
55+
ssl-vendored = ["rdkafka/ssl-vendored", "tui/ssl-vendored", "app/ssl-vendored"]
5856
gssapi-vendored = [
5957
"rdkafka/gssapi-vendored",
6058
"tui/gssapi-vendored",
61-
"app/gssapi-vendored"
59+
"app/gssapi-vendored",
6260
]

crates/command/src/cli.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use crate::cluster::Cluster;
33
use crate::command::{Command, MainCommand, UtilityCommands};
44
use crate::theme::init_themes_file;
5+
use crate::version::VERSION_MESSAGE;
56
use app::APPLICATION_NAME;
67
use app::configuration::{ClusterConfig, GlobalConfig, SchemaRegistryConfig, YozefuConfig};
78
use clap::command;
@@ -14,14 +15,6 @@ use tui::error::TuiError;
1415
pub use clap::Parser;
1516
use indexmap::IndexMap;
1617

17-
const VERSION_MESSAGE: &str = concat!(
18-
env!("CARGO_PKG_VERSION"),
19-
"\n",
20-
env!("CARGO_PKG_REPOSITORY"),
21-
"\n",
22-
env!("CARGO_PKG_AUTHORS")
23-
);
24-
2518
// https://github.com/clap-rs/clap/issues/975
2619
/// CLI parser
2720
#[derive(Parser)]

crates/command/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod command;
77
mod headless;
88
mod log;
99
mod theme;
10+
mod version;
1011
use app::configuration::GlobalConfig;
1112
pub use clap::Parser;
1213
pub use cli::Cli;

crates/command/src/version.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//! Inspired of <https://vallentin.dev/blog/post/versioning>
2+
//!
3+
//! Github environment variables <https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables>
4+
//! The version message looks like this:
5+
//! ```
6+
//! yozefu 0.0.9 (develop:unknown, debug build, macos [aarch64])
7+
//! https://github.com/MAIF/yozefu
8+
//! Yann Prono <[email protected]>
9+
//! ```
10+
use const_format::{formatcp, str_index, str_split};
11+
use const_str::split_lines;
12+
use std::env::consts::{ARCH, OS};
13+
14+
#[cfg(debug_assertions)]
15+
const BUILD_TYPE: &str = "debug";
16+
17+
#[cfg(not(debug_assertions))]
18+
const BUILD_TYPE: &'static str = "release";
19+
20+
const GIT_BRANCH: &str = match option_env!("GITHUB_REF_NAME") {
21+
Some(v) => v,
22+
None => {
23+
const FIRST_LINE: &str = split_lines!(include_str!("../../../.git/HEAD"))[0];
24+
str_split!(FIRST_LINE, "/")[2]
25+
}
26+
};
27+
28+
const GIT_COMMIT: &str = match option_env!("GITHUB_SHA") {
29+
Some(v) => v,
30+
None => "unknown",
31+
};
32+
33+
pub(super) const VERSION_MESSAGE: &str = formatcp!(
34+
"{} ({}:{}, {} build, {} [{}]) \n{}\n{}",
35+
env!("CARGO_PKG_VERSION"),
36+
GIT_BRANCH,
37+
str_index!(GIT_COMMIT, 0..7),
38+
BUILD_TYPE,
39+
OS,
40+
ARCH,
41+
env!("CARGO_PKG_REPOSITORY"),
42+
env!("CARGO_PKG_AUTHORS"),
43+
);

deny.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ exceptions = [
110110
{ allow = ["BSL-1.0"], crate = "lazy-bytes-cast" },
111111
{ allow = ["Zlib"], crate = "throbber-widgets-tui" },
112112
{ allow = ["Zlib"], crate = "adler32" },
113+
{ allow = ["Zlib"], crate = "const_format" },
114+
{ allow = ["Zlib"], crate = "konst_macro_rules" },
115+
{ allow = ["Zlib"], crate = "const_format_proc_macros" },
116+
{ allow = ["Zlib"], crate = "konst" }
113117
]
114118

115119
# Some crates don't have (easily) machine readable licensing information,

docs/keybindings/README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ The choices I made are completely personal. I use a qwerty apple keyboard for yo
3232
<br />
3333

3434
**Records list**
35-
| Keybinding | Description |
36-
| ---------------------------- | :-------------------------------------------- |
37-
| <kbd>C</kbd> | Copy kafka record to clipboard |
38-
| <kbd>O</kbd> | Open the kafka record in the web browser |
39-
| <kbd>E</kbd> | Export kafka record to the file |
40-
| <kbd>F</kbd> | Keep selecting the last consumed kafka record |
41-
| <kbd>Enter</kbd> | Open the selected record |
42-
| <kbd>↑</kbd> or <kbd>↓</kbd> | Previous/next record |
35+
| Keybinding | Description |
36+
| ------------------------------ | :-------------------------------------------- |
37+
| <kbd>C</kbd> | Copy kafka record to clipboard |
38+
| <kbd>O</kbd> | Open the kafka record in the web browser |
39+
| <kbd>E</kbd> | Export kafka record to the file |
40+
| <kbd>Ctrl</kbd> + <kbd>E</kbd> | Export all records to the file |
41+
| <kbd>F</kbd> | Keep selecting the last consumed kafka record |
42+
| <kbd>Enter</kbd> | Open the selected record |
43+
| <kbd>↑</kbd> or <kbd>↓</kbd> | Previous/next record |
4344

4445

4546
<br />
@@ -68,8 +69,8 @@ The choices I made are completely personal. I use a qwerty apple keyboard for yo
6869

6970

7071
**Search**
71-
| Keybinding | Description |
72-
| ---------------------------- | :-------------------- |
73-
| <kbd>↓</kbd> or <kbd>↑</kbd> | Browse history |
74-
| <kbd>→</kbd> | Accept autocomplete |
75-
| <kbd>Enter</kbd> | Search kafka records |
72+
| Keybinding | Description |
73+
| ---------------------------- | :------------------- |
74+
| <kbd>↓</kbd> or <kbd>↑</kbd> | Browse history |
75+
| <kbd>→</kbd> | Accept autocomplete |
76+
| <kbd>Enter</kbd> | Search kafka records |

0 commit comments

Comments
 (0)