Skip to content

Commit

Permalink
[eclipse-iceoryx#432] Implement CLI iox2-config
Browse files Browse the repository at this point in the history
  • Loading branch information
brosier01 committed Nov 26, 2024
1 parent 6f05b7b commit 94c6204
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 130 deletions.
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
58 changes: 12 additions & 46 deletions doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,23 @@

### 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 currently in use 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)

### API Breaking Changes
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)

1. Example
### New CLI features

```rust
// old
let fuu = hello().is_it_me_you_re_looking_for()
```bash
cargo run --bin iox2-config show

// new
let fuu = hypnotoad().all_glory_to_the_hypnotoad()
```
cargo run --bin iox2-config generate
```
84 changes: 0 additions & 84 deletions iceoryx2-bb/posix/src/system_configuration.rs
Original file line number Diff line number Diff line change
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()
);
}
}
9 changes: 9 additions & 0 deletions iceoryx2-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ 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"
Expand All @@ -34,17 +38,22 @@ path = "lib/src/lib.rs"
iceoryx2 = { workspace = true }
iceoryx2-bb-log = { workspace = true }
iceoryx2-pal-posix = {workspace = true}
iceoryx2-bb-posix = {workspace = true}
iceoryx2-bb-system-types = { workspace = true }
iceoryx2-bb-container ={ 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 }

[dev-dependencies]
iceoryx2-bb-testing = { workspace = true }
Expand Down
40 changes: 40 additions & 0 deletions iceoryx2-cli/iox2-config/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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(Subcommand)]
pub enum Action {
#[clap(about = "Show the currently used configuration")]
Show,
#[clap(about = "Generate a default configuration file")]
Generate,
}
124 changes: 124 additions & 0 deletions iceoryx2-cli/iox2-config/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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 anyhow::Result;
use iceoryx2_bb_posix::system_configuration::*;
use enum_iterator::all;
use iceoryx2::config::Config;
use std::fs::File;
use std::io::Write;
use std::path::Path;

/// 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()
);
}
}

pub fn show() -> Result<()> {
print_system_configuration();

Ok(())
}

pub fn generate() -> Result<()> {
let default_file_path = Path::new("config/iceoryx2.toml");

let default_config = Config::default();

let toml_string = toml::to_string_pretty(&default_config)?;

let mut file = File::create(&default_file_path)?;
file.write_all(toml_string.as_bytes())?;

println!("Default configuration is generated at {}", default_file_path.display());

Ok(())
}
Loading

0 comments on commit 94c6204

Please sign in to comment.