-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provides a `fvm version` command to print CLI version details. --- ## Demo ![CleanShot 2023-10-25 at 20 08 41](https://github.com/infinyon/fluvio/assets/34756077/1d297464-5b29-4ae6-a2e7-f2b5b81cd92e)
- Loading branch information
1 parent
4c0f1e8
commit 744ee4e
Showing
6 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod install; | |
pub mod itself; | ||
pub mod show; | ||
pub mod switch; | ||
pub mod version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Prints version information to stdout | ||
use anyhow::Result; | ||
use clap::Args; | ||
use current_platform::CURRENT_PLATFORM; | ||
use sha2::{Digest, Sha256}; | ||
use sysinfo::SystemExt; | ||
|
||
use crate::{BINARY_NAME, BINARY_VERSION}; | ||
|
||
#[derive(Debug, Args)] | ||
pub struct VersionOpt; | ||
|
||
impl VersionOpt { | ||
pub fn process(self) -> Result<()> { | ||
println!("{BINARY_NAME} CLI: {BINARY_VERSION}"); | ||
println!("{BINARY_NAME} CLI Arch: {CURRENT_PLATFORM}"); | ||
|
||
if let Some(sha) = self.format_cli_sha() { | ||
println!("{BINARY_NAME} CLI SHA256: {}", sha); | ||
} | ||
|
||
if let Some(info) = os_info() { | ||
println!("OS Details: {info}"); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Read CLI and compute its sha256 | ||
fn format_cli_sha(&self) -> Option<String> { | ||
let path = std::env::current_exe().ok()?; | ||
let bin = std::fs::read(path).ok()?; | ||
let mut hasher = Sha256::new(); | ||
|
||
hasher.update(bin); | ||
|
||
let bin_sha256 = hasher.finalize(); | ||
|
||
Some(format!("{:x}", &bin_sha256)) | ||
} | ||
} | ||
|
||
fn os_info() -> Option<String> { | ||
let sys = sysinfo::System::new_all(); | ||
let info = format!( | ||
"{} {} (kernel {})", | ||
sys.name()?, | ||
sys.os_version()?, | ||
sys.kernel_version()?, | ||
); | ||
|
||
Some(info) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters