Skip to content

Commit

Permalink
[eclipse-iceoryx#432] Fix print_system_configuration for cross-platfo…
Browse files Browse the repository at this point in the history
…rm coloring + implementation of user confirmation required before deleting current configuration file
  • Loading branch information
brosier01 committed Oct 17, 2024
1 parent 973c574 commit 1ba0dcc
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 50 deletions.
33 changes: 27 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ members = [
"examples",

"benchmarks/publish-subscribe",
"benchmarks/event"
"benchmarks/event",
]

[workspace.package]
categories = ["network-programming"]
description = "iceoryx2: Lock-Free Zero-Copy Interprocess Communication"
edition = "2021"
homepage = "https://iceoryx.io"
keywords = ["zero-copy", "communication", "ipc", "publish-subscribe", "request-response"]
keywords = [
"zero-copy",
"communication",
"ipc",
"publish-subscribe",
"request-response",
]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/eclipse-iceoryx/iceoryx2"
Expand Down Expand Up @@ -66,8 +72,7 @@ iceoryx2-ffi-macros = { version = "0.4.1", path = "iceoryx2-ffi/ffi-macros" }

iceoryx2 = { version = "0.4.1", path = "iceoryx2/" }

iceoryx2-cli = { version = "0.4.1", path = "iceoryx2_cli/"}

iceoryx2-cli = { version = "0.4.1", path = "iceoryx2_cli/" }


anyhow = { version = "1.0.86" }
Expand Down Expand Up @@ -103,8 +108,24 @@ tiny-fn = { version = "0.1.6" }
toml = { version = "0.8.13" }
tracing = { version = "0.1.40" }
dirs = { version = "5.0" }
windows-sys = { version = "0.48.0", features = ["Win32_Security", "Win32_Security_Authorization", "Win32_System_Memory", "Win32_System_Threading", "Win32_Foundation", "Win32_System_WindowsProgramming", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Diagnostics_Debug", "Win32_System_SystemInformation", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Console", "Win32_Networking_WinSock",
"Win32_System_SystemServices", "Win32_System_ProcessStatus"] }
dialoguer = { version = "0.8.0" }
windows-sys = { version = "0.48.0", features = [
"Win32_Security",
"Win32_Security_Authorization",
"Win32_System_Memory",
"Win32_System_Threading",
"Win32_Foundation",
"Win32_System_WindowsProgramming",
"Win32_Storage_FileSystem",
"Win32_System_IO",
"Win32_System_Diagnostics_Debug",
"Win32_System_SystemInformation",
"Win32_System_Diagnostics_ToolHelp",
"Win32_System_Console",
"Win32_Networking_WinSock",
"Win32_System_SystemServices",
"Win32_System_ProcessStatus",
] }

[profile.release]
strip = true
Expand Down
7 changes: 4 additions & 3 deletions iceoryx2-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ path = "lib/src/lib.rs"
[dependencies]
iceoryx2 = { workspace = true }
iceoryx2-bb-log = { workspace = true }
iceoryx2-pal-posix = {workspace = true}
iceoryx2-bb-posix = {workspace = true}
iceoryx2-pal-posix = { workspace = true }
iceoryx2-bb-posix = { workspace = true }
iceoryx2-bb-system-types = { workspace = true }
iceoryx2-bb-container ={ workspace = true }
iceoryx2-bb-container = { workspace = true }

anyhow = { workspace = true }
better-panic = { workspace = true }
Expand All @@ -55,6 +55,7 @@ serde_json = { workspace = true }
ron = { workspace = true }
toml = { workspace = true }
dirs = { workspace = true }
dialoguer = { workspace = true }

[dev-dependencies]
iceoryx2-bb-testing = { workspace = true }
Expand Down
99 changes: 58 additions & 41 deletions iceoryx2-cli/iox2-config/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,33 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use anyhow::Result;
use colored::Colorize;
use dialoguer::Confirm;
use enum_iterator::all;
use iceoryx2::config::Config;
use iceoryx2_bb_posix::system_configuration::*;
use std::fs::{self, File};
use std::io::Write;
use std::panic::catch_unwind;

/// Prints the whole system configuration with all limits, features and details to the console.
pub fn print_system_configuration() {
const HEADER_COLOR: &str = "\x1b[4;92m";
const VALUE_COLOR: &str = "\x1b[0;94m";
const DISABLED_VALUE_COLOR: &str = "\x1b[0;90m";
const ENTRY_COLOR: &str = "\x1b[0;37m";
const DISABLED_ENTRY_COLOR: &str = "\x1b[0;90m";
const COLOR_RESET: &str = "\x1b[0m";

println!("{}posix system configuration{}", HEADER_COLOR, COLOR_RESET);
println!(
"{}",
"posix system configuration".underline().bright_green()
);
println!();
println!(" {}system info{}", HEADER_COLOR, COLOR_RESET);
println!(" {}", "system info".underline().bright_green());
for i in all::<SystemInfo>().collect::<Vec<_>>() {
println!(
" {ENTRY_COLOR}{:<50}{COLOR_RESET} {VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.value(),
" {:<50} {}",
format!("{:?}", i).white(),
format!("{}", i.value()).bright_blue(),
);
}

println!();
println!(" {}limits{}", HEADER_COLOR, COLOR_RESET);
println!(" {}", "limit".underline().bright_green());
for i in all::<Limit>().collect::<Vec<_>>() {
let limit = i.value();
let limit = if limit == 0 {
Expand All @@ -47,57 +46,63 @@ pub fn print_system_configuration() {
limit.to_string()
};
println!(
" {ENTRY_COLOR}{:<50}{COLOR_RESET} {VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
limit,
" {:<50} {}",
format!("{:?}", i).white(),
limit.bright_blue(),
);
}

println!();
println!(" {}options{}", HEADER_COLOR, COLOR_RESET);
println!(" {}", "options".underline().bright_green());
for i in all::<SysOption>().collect::<Vec<_>>() {
if i.is_available() {
println!(
" {ENTRY_COLOR}{:<50}{COLOR_RESET} {VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.is_available(),
" {:<50} {}",
format!("{:?}", i).white(),
format!("{}", i.is_available()).bright_blue()
);
} else {
println!(
" {DISABLED_ENTRY_COLOR}{:<50}{COLOR_RESET} {DISABLED_VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.is_available(),
);
println!(" {:<50} {}", format!("{:?}", i), i.is_available(),);
}
}

println!();
println!(" {}features{}", HEADER_COLOR, COLOR_RESET);
println!(" {}", "features".underline().bright_green());
for i in all::<Feature>().collect::<Vec<_>>() {
if i.is_available() {
println!(
" {ENTRY_COLOR}{:<50}{COLOR_RESET} {VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.is_available(),
" {:<50} {}",
format!("{:?}", i).white(),
format!("{}", i.is_available()).bright_blue(),
);
} else {
println!(
" {DISABLED_ENTRY_COLOR}{:<50}{COLOR_RESET} {DISABLED_VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.is_available(),
);
println!(" {:<50} {}", format!("{:?}", i), i.is_available(),);
}
}

println!();
println!(" {}process resource limits{}", HEADER_COLOR, COLOR_RESET);
println!(" {}", "process resource limits".underline().bright_green());
for i in all::<ProcessResourceLimit>().collect::<Vec<_>>() {
println!(
" {ENTRY_COLOR}{:<43}{COLOR_RESET} soft: {VALUE_COLOR}{:<24}{COLOR_RESET} hard: {VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.soft_limit(),
i.hard_limit()
);
let soft_limit_result = catch_unwind(|| i.soft_limit());
let hard_limit_result = catch_unwind(|| i.hard_limit());

match (soft_limit_result, hard_limit_result) {
(Ok(soft), Ok(hard)) => {
println!(
" {:<43} soft: {:<24} hard: {}",
format!("{:?}", i).white(),
format!("{}", soft).bright_blue(),
format!("{}", hard).bright_blue()
);
}
(Err(e), _) | (_, Err(e)) => {
println!(
" {:<43} Error: {}",
format!("{:?}", i).white(),
format!("Unable to acquire limit due to: {:?}", e).red()
);
}
}
}
}

Expand All @@ -113,6 +118,18 @@ pub fn generate() -> Result<()> {

let default_file_path = config_dir.join("config.toml");

if default_file_path.exists() {
let proceed = Confirm::new()
.with_prompt("Configuration file already exists. Do you want to overwrite it?")
.default(false)
.interact()?;

if !proceed {
println!("Operation cancelled. Configuration file was not overwritten.");
return Ok(());
}
}

let toml_string = toml::to_string_pretty(&Config::default())?;

let mut file = File::create(&default_file_path)?;
Expand Down

0 comments on commit 1ba0dcc

Please sign in to comment.