Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#432] Implement CLI iox2-config #468

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
34 changes: 28 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 @@ -102,8 +107,25 @@ thiserror = { version = "1.0.56" }
tiny-fn = { version = "0.1.6" }
toml = { version = "0.8.13" }
tracing = { version = "0.1.40" }
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"] }
dirs = { version = "5.0" }
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ The support levels can be adjusted when required.
<a href="https://github.com/orecham">
<img src="https://avatars.githubusercontent.com/u/8487595" width="120px;" alt="»orecham«"/><br />
<sub><b>»orecham«</b></sub></a></td>
<td align="center" valign="top" width="14.28%">
<a href="https://github.com/brosier01">
<img src="https://avatars.githubusercontent.com/u/71630425?v=4" width="120px;" alt="Bruce »brosier01« Rosier"/><br />
<sub><b>Bruce »brosier01« Rosier</b></sub></a></td>
</tr>
</tbody>
</table>
Expand Down
59 changes: 14 additions & 45 deletions doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,26 @@

### Features

<!--
NOTE: Add new entries sorted by issue number to minimize the possibility of
conflicts when merging.
-->
Create a new CLI for iceoryx2 `iox2-config`

* Add `PeriodicTimer` into POSIX building blocks [#425](https://github.com/eclipse-iceoryx/iceoryx2/issues/425)
`iox2 config` can `show` the configuration of iceoryx currently in use
or `show` the configuration of the sytem and `generate` a new
configuration file at the default location iceoryx2 is looking for.

### Bugfixes

<!--
NOTE: Add new entries sorted by issue number to minimize the possibility of
conflicts when merging.
-->

* Example text [#1](https://github.com/eclipse-iceoryx/iceoryx2/issues/1)
* Add CLI to display complete system configuration [#432](https://github.com/eclipse-iceoryx/iceoryx2/issues/432)

### Refactoring

<!--
NOTE: Add new entries sorted by issue number to minimize the possibility of
conflicts when merging.
-->

* Example text [#1](https://github.com/eclipse-iceoryx/iceoryx2/issues/1)

### Workflow

<!--
NOTE: Add new entries sorted by issue number to minimize the possibility of
conflicts when merging.
-->

* Example text [#1](https://github.com/eclipse-iceoryx/iceoryx2/issues/1)

### New API features

<!--
NOTE: Add new entries sorted by issue number to minimize the possibility of
conflicts when merging.
-->

* Example text [#1](https://github.com/eclipse-iceoryx/iceoryx2/issues/1)
Remove the `print_system_configuration()` function in
`iceoryx2-bb/posix/src/system_configuration.rs` file and move it into the CLI `iox2-config`
[#432](https://github.com/eclipse-iceoryx/iceoryx2/issues/432)

### API Breaking Changes
### New CLI features

1. Example
```bash
iox2-config show system

```rust
// old
let fuu = hello().is_it_me_you_re_looking_for()
iox2-config show current

// new
let fuu = hypnotoad().all_glory_to_the_hypnotoad()
```
iox2-config generate
```
86 changes: 1 addition & 85 deletions iceoryx2-bb/posix/src/system_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! Provides information about the POSIX [`SystemInfo`], [`Limit`]s, available [`SysOption`] and
//! [`Feature`]s.

use enum_iterator::{all, Sequence};
use enum_iterator::Sequence;
use iceoryx2_bb_log::{fatal_panic, warn};
use iceoryx2_pal_posix::posix::Struct;
use iceoryx2_pal_posix::*;
Expand Down Expand Up @@ -294,87 +294,3 @@ impl ProcessResourceLimit {
true
}
}

/// 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!();
println!(" {}system info{}", HEADER_COLOR, COLOR_RESET);
for i in all::<SystemInfo>().collect::<Vec<_>>() {
println!(
" {ENTRY_COLOR}{:<50}{COLOR_RESET} {VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.value(),
);
}

println!();
println!(" {}limits{}", HEADER_COLOR, COLOR_RESET);
for i in all::<Limit>().collect::<Vec<_>>() {
let limit = i.value();
let limit = if limit == 0 {
"[ unlimited ]".to_string()
} else {
limit.to_string()
};
println!(
" {ENTRY_COLOR}{:<50}{COLOR_RESET} {VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
limit,
);
}

println!();
println!(" {}options{}", HEADER_COLOR, COLOR_RESET);
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(),
);
} else {
println!(
" {DISABLED_ENTRY_COLOR}{:<50}{COLOR_RESET} {DISABLED_VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.is_available(),
);
}
}

println!();
println!(" {}features{}", HEADER_COLOR, COLOR_RESET);
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(),
);
} else {
println!(
" {DISABLED_ENTRY_COLOR}{:<50}{COLOR_RESET} {DISABLED_VALUE_COLOR}{}{COLOR_RESET}",
format!("{:?}", i),
i.is_available(),
);
}
}

println!();
println!(" {}process resource limits{}", HEADER_COLOR, COLOR_RESET);
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()
);
}
}
1 change: 1 addition & 0 deletions iceoryx2-cal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ iceoryx2-bb-threadsafe = { workspace = true }
iceoryx2-bb-testing = { workspace = true }
iceoryx2-pal-concurrency-sync = { workspace = true }

dirs = { workspace = true }
once_cell = { workspace = true }
lazy_static = { workspace = true }
serde = { workspace = true }
Expand Down
35 changes: 35 additions & 0 deletions iceoryx2-cal/src/config_path/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! use iceoryx2_cal::config_path::config_dir;
//!
//! let config_dir = config_dir().unwrap();
//! println!("Config dir: {:?}", config_dir);

use dirs;

pub trait ConfigPathProvider {
fn config_dir(&self) -> Option<std::path::PathBuf>;
}

pub struct DirsConfigPathProvider;

impl ConfigPathProvider for DirsConfigPathProvider {
fn config_dir(&self) -> Option<std::path::PathBuf> {
dirs::config_dir()
}
}

pub fn config_dir() -> Option<std::path::PathBuf> {
let provider = DirsConfigPathProvider;
provider.config_dir()
}
1 change: 1 addition & 0 deletions iceoryx2-cal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

pub mod communication_channel;
pub mod config_path;
pub mod dynamic_storage;
pub mod event;
pub mod hash;
Expand Down
14 changes: 13 additions & 1 deletion iceoryx2-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,37 @@ path = "iox2-node/src/main.rs"
name = "iox2-service"
path = "iox2-service/src/main.rs"

[[bin]]
name = "iox2-config"
path = "iox2-config/src/main.rs"

[lib]
name = "iceoryx2_cli"
path = "lib/src/lib.rs"

[dependencies]
iceoryx2 = { workspace = true }
iceoryx2-bb-log = { workspace = true }
iceoryx2-pal-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-cal = { workspace = true }

anyhow = { workspace = true }
better-panic = { workspace = true }
cargo_metadata = { workspace = true }
clap = { workspace = true }
colored = { workspace = true }
enum-iterator = { workspace = true }
human-panic = { workspace = true }
serde = { workspace = true }
serde_yaml = { workspace = true }
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
65 changes: 65 additions & 0 deletions iceoryx2-cli/iox2-config/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

use clap::Parser;
use clap::Subcommand;

use iceoryx2_cli::help_template;

#[derive(Parser)]
#[command(
name = "iox2-config",
about = "Query information about iceoryx2 configuration",
long_about = None,
version = env!("CARGO_PKG_VERSION"),
disable_help_subcommand = true,
arg_required_else_help = false,
help_template = help_template("iox2 config", false),
)]
pub struct Cli {
#[clap(subcommand)]
pub action: Option<Action>,
}

#[derive(Parser)]
#[command(
name = "iox2-config",
about = "Query information about iceoryx2 configuration",
long_about = None,
version = env!("CARGO_PKG_VERSION"),
disable_help_subcommand = true,
arg_required_else_help = false,
help_template = help_template("iox2 config show", false),
)]
pub struct Config {
#[clap(subcommand)]
pub action: Option<ShowSubcommand>,
}

#[derive(Subcommand, Debug)]
pub enum ShowSubcommand {
#[clap(about = "Show system configuration")]
System,
#[clap(about = "Show current iceoryx2 configuration")]
Current,
}

#[derive(Subcommand)]
pub enum Action {
#[clap(about = "Show the currently used configuration")]
Show {
#[clap(subcommand)]
subcommand: Option<ShowSubcommand>,
},
#[clap(about = "Generate a default configuration file")]
Generate,
}
Loading