From 194a1beb165773d4365885d85bfddff4b323be2d Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Sun, 21 Jan 2024 18:19:08 +0100 Subject: [PATCH 01/17] [#98] Skeleton for iceoryx2-cli --- Cargo.toml | 8 ++++++++ iceoryx2-cli/iox2-introspect/Cargo.toml | 15 +++++++++++++++ iceoryx2-cli/iox2-introspect/src/main.rs | 3 +++ iceoryx2-cli/iox2-processes/Cargo.toml | 15 +++++++++++++++ iceoryx2-cli/iox2-processes/src/main.rs | 3 +++ iceoryx2-cli/iox2-pub/Cargo.toml | 15 +++++++++++++++ iceoryx2-cli/iox2-pub/src/main.rs | 3 +++ iceoryx2-cli/iox2-rpc/Cargo.toml | 15 +++++++++++++++ iceoryx2-cli/iox2-rpc/src/main.rs | 3 +++ iceoryx2-cli/iox2-services/Cargo.toml | 15 +++++++++++++++ iceoryx2-cli/iox2-services/src/main.rs | 5 +++++ iceoryx2-cli/iox2-sub/Cargo.toml | 15 +++++++++++++++ iceoryx2-cli/iox2-sub/src/main.rs | 3 +++ iceoryx2-cli/iox2/Cargo.toml | 15 +++++++++++++++ iceoryx2-cli/iox2/src/main.rs | 3 +++ 15 files changed, 136 insertions(+) create mode 100644 iceoryx2-cli/iox2-introspect/Cargo.toml create mode 100644 iceoryx2-cli/iox2-introspect/src/main.rs create mode 100644 iceoryx2-cli/iox2-processes/Cargo.toml create mode 100644 iceoryx2-cli/iox2-processes/src/main.rs create mode 100644 iceoryx2-cli/iox2-pub/Cargo.toml create mode 100644 iceoryx2-cli/iox2-pub/src/main.rs create mode 100644 iceoryx2-cli/iox2-rpc/Cargo.toml create mode 100644 iceoryx2-cli/iox2-rpc/src/main.rs create mode 100644 iceoryx2-cli/iox2-services/Cargo.toml create mode 100644 iceoryx2-cli/iox2-services/src/main.rs create mode 100644 iceoryx2-cli/iox2-sub/Cargo.toml create mode 100644 iceoryx2-cli/iox2-sub/src/main.rs create mode 100644 iceoryx2-cli/iox2/Cargo.toml create mode 100644 iceoryx2-cli/iox2/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index abf0c6a50..3c9e108c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,14 @@ members = [ "iceoryx2-pal/posix/", "iceoryx2-pal/configuration/", + "iceoryx2-cli/iox2", + "iceoryx2-cli/iox2-introspect", + "iceoryx2-cli/iox2-processes", + "iceoryx2-cli/iox2-pub", + "iceoryx2-cli/iox2-rpc", + "iceoryx2-cli/iox2-services", + "iceoryx2-cli/iox2-sub", + "examples", "benchmarks/publish-subscribe", diff --git a/iceoryx2-cli/iox2-introspect/Cargo.toml b/iceoryx2-cli/iox2-introspect/Cargo.toml new file mode 100644 index 000000000..dbab0d185 --- /dev/null +++ b/iceoryx2-cli/iox2-introspect/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "iox2-introspect" +description = "Iceoryx2: CLI for introspecting iceoryx 2 internals" +categories = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/iceoryx2-cli/iox2-introspect/src/main.rs b/iceoryx2-cli/iox2-introspect/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/iceoryx2-cli/iox2-introspect/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/iceoryx2-cli/iox2-processes/Cargo.toml b/iceoryx2-cli/iox2-processes/Cargo.toml new file mode 100644 index 000000000..7d69df5de --- /dev/null +++ b/iceoryx2-cli/iox2-processes/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "iox2-processes" +description = "Iceoryx2: CLI for managing iceoryx2 processes" +categories = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/iceoryx2-cli/iox2-processes/src/main.rs b/iceoryx2-cli/iox2-processes/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/iceoryx2-cli/iox2-processes/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/iceoryx2-cli/iox2-pub/Cargo.toml b/iceoryx2-cli/iox2-pub/Cargo.toml new file mode 100644 index 000000000..89ab86ea0 --- /dev/null +++ b/iceoryx2-cli/iox2-pub/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "iox2-pub" +description = "Iceoryx2: CLI for publishing to iceoryx2" +categories = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/iceoryx2-cli/iox2-pub/src/main.rs b/iceoryx2-cli/iox2-pub/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/iceoryx2-cli/iox2-pub/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/iceoryx2-cli/iox2-rpc/Cargo.toml b/iceoryx2-cli/iox2-rpc/Cargo.toml new file mode 100644 index 000000000..0bddfb8e1 --- /dev/null +++ b/iceoryx2-cli/iox2-rpc/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "iox2-rpc" +description = "Iceoryx2: CLI for rpc operations" +categories = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/iceoryx2-cli/iox2-rpc/src/main.rs b/iceoryx2-cli/iox2-rpc/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/iceoryx2-cli/iox2-rpc/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/iceoryx2-cli/iox2-services/Cargo.toml b/iceoryx2-cli/iox2-services/Cargo.toml new file mode 100644 index 000000000..f787a5a57 --- /dev/null +++ b/iceoryx2-cli/iox2-services/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "iox2-services" +description = "Iceoryx2: CLI for managing iceoryx2 services" +categories = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/iceoryx2-cli/iox2-services/src/main.rs b/iceoryx2-cli/iox2-services/src/main.rs new file mode 100644 index 000000000..85aad77fc --- /dev/null +++ b/iceoryx2-cli/iox2-services/src/main.rs @@ -0,0 +1,5 @@ +fn main() { + println!("Hello, world!"); +} + + diff --git a/iceoryx2-cli/iox2-sub/Cargo.toml b/iceoryx2-cli/iox2-sub/Cargo.toml new file mode 100644 index 000000000..8fdb6c736 --- /dev/null +++ b/iceoryx2-cli/iox2-sub/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "iox2-sub" +description = "Iceoryx2: CLI for subscribing to iceoryx2" +categories = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/iceoryx2-cli/iox2-sub/src/main.rs b/iceoryx2-cli/iox2-sub/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/iceoryx2-cli/iox2-sub/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/iceoryx2-cli/iox2/Cargo.toml b/iceoryx2-cli/iox2/Cargo.toml new file mode 100644 index 000000000..dd94c3e07 --- /dev/null +++ b/iceoryx2-cli/iox2/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "iox2" +description = "Iceoryx2: CLI entry-point" +categories = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } +version = { workspace = true } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/iceoryx2-cli/iox2/src/main.rs b/iceoryx2-cli/iox2/src/main.rs new file mode 100644 index 000000000..6686bd0e3 --- /dev/null +++ b/iceoryx2-cli/iox2/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!") +} From dd09a8e6ba96116d5e6d579ae27c69ee46bb6d71 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Sun, 21 Jan 2024 20:23:47 +0100 Subject: [PATCH 02/17] [#98] List available cli commands --- iceoryx2-cli/iox2-introspect/src/main.rs | 2 +- iceoryx2-cli/iox2-processes/src/main.rs | 2 +- iceoryx2-cli/iox2-pub/src/main.rs | 2 +- iceoryx2-cli/iox2-rpc/src/main.rs | 2 +- iceoryx2-cli/iox2-services/src/main.rs | 4 +- iceoryx2-cli/iox2-sub/src/main.rs | 2 +- iceoryx2-cli/iox2/Cargo.toml | 2 - iceoryx2-cli/iox2/src/main.rs | 79 +++++++++++++++++++++++- 8 files changed, 84 insertions(+), 11 deletions(-) diff --git a/iceoryx2-cli/iox2-introspect/src/main.rs b/iceoryx2-cli/iox2-introspect/src/main.rs index e7a11a969..271c1ee2e 100644 --- a/iceoryx2-cli/iox2-introspect/src/main.rs +++ b/iceoryx2-cli/iox2-introspect/src/main.rs @@ -1,3 +1,3 @@ fn main() { - println!("Hello, world!"); + println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-processes/src/main.rs b/iceoryx2-cli/iox2-processes/src/main.rs index e7a11a969..271c1ee2e 100644 --- a/iceoryx2-cli/iox2-processes/src/main.rs +++ b/iceoryx2-cli/iox2-processes/src/main.rs @@ -1,3 +1,3 @@ fn main() { - println!("Hello, world!"); + println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-pub/src/main.rs b/iceoryx2-cli/iox2-pub/src/main.rs index e7a11a969..271c1ee2e 100644 --- a/iceoryx2-cli/iox2-pub/src/main.rs +++ b/iceoryx2-cli/iox2-pub/src/main.rs @@ -1,3 +1,3 @@ fn main() { - println!("Hello, world!"); + println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-rpc/src/main.rs b/iceoryx2-cli/iox2-rpc/src/main.rs index e7a11a969..271c1ee2e 100644 --- a/iceoryx2-cli/iox2-rpc/src/main.rs +++ b/iceoryx2-cli/iox2-rpc/src/main.rs @@ -1,3 +1,3 @@ fn main() { - println!("Hello, world!"); + println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-services/src/main.rs b/iceoryx2-cli/iox2-services/src/main.rs index 85aad77fc..271c1ee2e 100644 --- a/iceoryx2-cli/iox2-services/src/main.rs +++ b/iceoryx2-cli/iox2-services/src/main.rs @@ -1,5 +1,3 @@ fn main() { - println!("Hello, world!"); + println!("Not implemented. Stay tuned !"); } - - diff --git a/iceoryx2-cli/iox2-sub/src/main.rs b/iceoryx2-cli/iox2-sub/src/main.rs index e7a11a969..271c1ee2e 100644 --- a/iceoryx2-cli/iox2-sub/src/main.rs +++ b/iceoryx2-cli/iox2-sub/src/main.rs @@ -1,3 +1,3 @@ fn main() { - println!("Hello, world!"); + println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2/Cargo.toml b/iceoryx2-cli/iox2/Cargo.toml index dd94c3e07..4cd3c8fe7 100644 --- a/iceoryx2-cli/iox2/Cargo.toml +++ b/iceoryx2-cli/iox2/Cargo.toml @@ -10,6 +10,4 @@ repository = { workspace = true } rust-version = { workspace = true } version = { workspace = true } -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] diff --git a/iceoryx2-cli/iox2/src/main.rs b/iceoryx2-cli/iox2/src/main.rs index 6686bd0e3..51453a435 100644 --- a/iceoryx2-cli/iox2/src/main.rs +++ b/iceoryx2-cli/iox2/src/main.rs @@ -1,3 +1,80 @@ +use std::env; +use std::fs; +use std::path::PathBuf; + +fn find_command_binaries_in_development_dirs() -> Vec { + let mut commands = Vec::new(); + let current_exe = match env::current_exe() { + Ok(exe) => exe, + Err(_) => return commands, + }; + let target_dir_name = if cfg!(debug_assertions) { + "debug" + } else { + "release" + }; + let target_dir = current_exe + .parent() + .unwrap() + .parent() + .unwrap() + .join(target_dir_name); + + if let Ok(entries) = fs::read_dir(&target_dir) { + for entry in entries.filter_map(Result::ok) { + let path = entry.path(); + if is_valid_command_binary(&path) { + if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { + let stripped = command_name.strip_prefix("iox2-").unwrap_or(command_name); + commands.push(stripped.to_string()); + } + } + } + } + + commands +} + +fn find_command_binaries_in_system_path() -> Vec { + let mut commands = Vec::new(); + if let Ok(path_var) = env::var("PATH") { + for path in env::split_paths(&path_var) { + if let Ok(entries) = fs::read_dir(path) { + for entry in entries.filter_map(Result::ok) { + let path = entry.path(); + if is_valid_command_binary(&path) { + if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { + commands.push(command_name.to_string()); + } + } + } + } + } + } + + commands +} + +fn is_valid_command_binary(path: &PathBuf) -> bool { + path.is_file() + && path + .file_stem() + .unwrap() + .to_str() + .unwrap() + .starts_with("iox2-") + && path.extension().is_none() // Exclude files with extensions (e.g. '.d') +} + fn main() { - println!("Hello, world!") + let mut commands = find_command_binaries_in_development_dirs(); + if commands.is_empty() { + commands = find_command_binaries_in_system_path(); + } + + println!("Available commands:"); + for command in commands { + println!("- {}", command); + } } + From d3a1f58a4ade972f8805c86b631dbfe2f0d45e81 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Sun, 21 Jan 2024 21:38:20 +0100 Subject: [PATCH 03/17] [#98] Move methods to find commands into a separate module --- iceoryx2-cli/iox2/Cargo.toml | 2 + iceoryx2-cli/iox2/src/commands.rs | 75 ++++++++++++++++++++++++++ iceoryx2-cli/iox2/src/main.rs | 87 +++++++------------------------ 3 files changed, 95 insertions(+), 69 deletions(-) create mode 100644 iceoryx2-cli/iox2/src/commands.rs diff --git a/iceoryx2-cli/iox2/Cargo.toml b/iceoryx2-cli/iox2/Cargo.toml index 4cd3c8fe7..6e8161eb1 100644 --- a/iceoryx2-cli/iox2/Cargo.toml +++ b/iceoryx2-cli/iox2/Cargo.toml @@ -11,3 +11,5 @@ rust-version = { workspace = true } version = { workspace = true } [dependencies] +human-panic = "1.2.3" +better-panic = "0.3.0" diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs new file mode 100644 index 000000000..99749de9a --- /dev/null +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -0,0 +1,75 @@ +use std::env; +use std::fs; +use std::path::PathBuf; + +pub fn find() -> Vec { + let mut commands = find_command_binaries_in_development_dirs(); + if commands.is_empty() { + commands = find_command_binaries_in_system_path(); + } + commands +} + +fn find_command_binaries_in_development_dirs() -> Vec { + let mut commands = Vec::new(); + let current_exe = match env::current_exe() { + Ok(exe) => exe, + Err(_) => return commands, + }; + let target_dir_name = if cfg!(debug_assertions) { + "debug" + } else { + "release" + }; + let target_dir = current_exe + .parent() + .unwrap() + .parent() + .unwrap() + .join(target_dir_name); + + if let Ok(entries) = fs::read_dir(&target_dir) { + for entry in entries.filter_map(Result::ok) { + let path = entry.path(); + if is_valid_command_binary(&path) { + if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { + let stripped = command_name.strip_prefix("iox2-").unwrap_or(command_name); + commands.push(stripped.to_string()); + } + } + } + } + + commands +} + +fn find_command_binaries_in_system_path() -> Vec { + let mut commands = Vec::new(); + if let Ok(path_var) = env::var("PATH") { + for path in env::split_paths(&path_var) { + if let Ok(entries) = fs::read_dir(path) { + for entry in entries.filter_map(Result::ok) { + let path = entry.path(); + if is_valid_command_binary(&path) { + if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { + commands.push(command_name.to_string()); + } + } + } + } + } + } + + commands +} + +fn is_valid_command_binary(path: &PathBuf) -> bool { + path.is_file() + && path + .file_stem() + .unwrap() + .to_str() + .unwrap() + .starts_with("iox2-") + && path.extension().is_none() // Exclude files with extensions (e.g. '.d') +} diff --git a/iceoryx2-cli/iox2/src/main.rs b/iceoryx2-cli/iox2/src/main.rs index 51453a435..49df03974 100644 --- a/iceoryx2-cli/iox2/src/main.rs +++ b/iceoryx2-cli/iox2/src/main.rs @@ -1,80 +1,29 @@ -use std::env; -use std::fs; -use std::path::PathBuf; +#[cfg(not(debug_assertions))] +use human_panic::setup_panic; -fn find_command_binaries_in_development_dirs() -> Vec { - let mut commands = Vec::new(); - let current_exe = match env::current_exe() { - Ok(exe) => exe, - Err(_) => return commands, - }; - let target_dir_name = if cfg!(debug_assertions) { - "debug" - } else { - "release" - }; - let target_dir = current_exe - .parent() - .unwrap() - .parent() - .unwrap() - .join(target_dir_name); +#[cfg(debug_assertions)] +extern crate better_panic; - if let Ok(entries) = fs::read_dir(&target_dir) { - for entry in entries.filter_map(Result::ok) { - let path = entry.path(); - if is_valid_command_binary(&path) { - if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { - let stripped = command_name.strip_prefix("iox2-").unwrap_or(command_name); - commands.push(stripped.to_string()); - } - } - } - } - - commands -} - -fn find_command_binaries_in_system_path() -> Vec { - let mut commands = Vec::new(); - if let Ok(path_var) = env::var("PATH") { - for path in env::split_paths(&path_var) { - if let Ok(entries) = fs::read_dir(path) { - for entry in entries.filter_map(Result::ok) { - let path = entry.path(); - if is_valid_command_binary(&path) { - if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { - commands.push(command_name.to_string()); - } - } - } - } - } - } - - commands -} - -fn is_valid_command_binary(path: &PathBuf) -> bool { - path.is_file() - && path - .file_stem() - .unwrap() - .to_str() - .unwrap() - .starts_with("iox2-") - && path.extension().is_none() // Exclude files with extensions (e.g. '.d') -} +mod commands; fn main() { - let mut commands = find_command_binaries_in_development_dirs(); - if commands.is_empty() { - commands = find_command_binaries_in_system_path(); + #[cfg(not(debug_assertions))] + { + setup_panic!(); } + #[cfg(debug_assertions)] + { + better_panic::Settings::debug() + .most_recent_first(false) + .lineno_suffix(true) + .verbosity(better_panic::Verbosity::Full) + .install(); + } + + let commands = commands::find(); println!("Available commands:"); for command in commands { println!("- {}", command); } } - From ab1db6a51feb226c581f0876fb9003fbaa12c058 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Sun, 28 Jan 2024 18:35:25 +0100 Subject: [PATCH 04/17] [#98] Define entrypoint cli using clap --- iceoryx2-cli/iox2/Cargo.toml | 2 ++ iceoryx2-cli/iox2/src/cli.rs | 24 ++++++++++++++++++++++++ iceoryx2-cli/iox2/src/commands.rs | 11 ++++++++++- iceoryx2-cli/iox2/src/main.rs | 10 ++++++---- 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 iceoryx2-cli/iox2/src/cli.rs diff --git a/iceoryx2-cli/iox2/Cargo.toml b/iceoryx2-cli/iox2/Cargo.toml index 6e8161eb1..7e630195c 100644 --- a/iceoryx2-cli/iox2/Cargo.toml +++ b/iceoryx2-cli/iox2/Cargo.toml @@ -13,3 +13,5 @@ version = { workspace = true } [dependencies] human-panic = "1.2.3" better-panic = "0.3.0" +clap = { version = "4.4.18", features = ["derive"] } +colored = "2.0" diff --git a/iceoryx2-cli/iox2/src/cli.rs b/iceoryx2-cli/iox2/src/cli.rs new file mode 100644 index 000000000..6de69fa84 --- /dev/null +++ b/iceoryx2-cli/iox2/src/cli.rs @@ -0,0 +1,24 @@ +use clap::Parser; + +#[derive(Parser, Debug)] +#[command( + name = "iox2", + about = "The command-line interface to iceoryx2", + long_about = None, + version = env!("CARGO_PKG_VERSION"), + disable_help_subcommand = true, + arg_required_else_help = true, + help_template = help_template(), +)] +pub struct Cli { + #[arg(short, long, help = "List all installed commands")] + pub list: bool, +} + +fn help_template() -> &'static str { + "\ + USAGE: iox2 [OPTIONS] \n\n\ + OPTIONS:\n{options}\n\n\ + COMMANDS:\n{subcommands}\n\ + \u{00A0}\u{00A0}... See all installed commands with --list" +} diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index 99749de9a..2106946b2 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -1,8 +1,17 @@ +use colored::*; use std::env; use std::fs; use std::path::PathBuf; -pub fn find() -> Vec { +pub fn list() { + println!("Installed Commands:"); + let installed_commands = find(); + for command in installed_commands { + println!(" {}", command.bold()); + } +} + +fn find() -> Vec { let mut commands = find_command_binaries_in_development_dirs(); if commands.is_empty() { commands = find_command_binaries_in_system_path(); diff --git a/iceoryx2-cli/iox2/src/main.rs b/iceoryx2-cli/iox2/src/main.rs index 49df03974..44cfcd1b2 100644 --- a/iceoryx2-cli/iox2/src/main.rs +++ b/iceoryx2-cli/iox2/src/main.rs @@ -4,8 +4,11 @@ use human_panic::setup_panic; #[cfg(debug_assertions)] extern crate better_panic; +mod cli; mod commands; +use clap::Parser; + fn main() { #[cfg(not(debug_assertions))] { @@ -20,10 +23,9 @@ fn main() { .install(); } - let commands = commands::find(); + let cli = cli::Cli::parse(); - println!("Available commands:"); - for command in commands { - println!("- {}", command); + if cli.list { + commands::list(); } } From d36e2c2d7533f8f118b610dd58dc843040aecd3d Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Sun, 28 Jan 2024 19:05:38 +0100 Subject: [PATCH 05/17] [#98] Return installed binary path along with name --- iceoryx2-cli/iox2/src/cli.rs | 3 ++ iceoryx2-cli/iox2/src/commands.rs | 55 ++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/iceoryx2-cli/iox2/src/cli.rs b/iceoryx2-cli/iox2/src/cli.rs index 6de69fa84..14ce10000 100644 --- a/iceoryx2-cli/iox2/src/cli.rs +++ b/iceoryx2-cli/iox2/src/cli.rs @@ -13,6 +13,9 @@ use clap::Parser; pub struct Cli { #[arg(short, long, help = "List all installed commands")] pub list: bool, + + #[arg(short, long, help = "Run development commands")] + pub dev: bool, } fn help_template() -> &'static str { diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index 2106946b2..5bea9544e 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -7,43 +7,64 @@ pub fn list() { println!("Installed Commands:"); let installed_commands = find(); for command in installed_commands { - println!(" {}", command.bold()); + println!( + " {}", + format!( + "{}{}", + command.name.bold(), + if command.is_development { " (dev)" } else { "" } + ) + ); } } -fn find() -> Vec { - let mut commands = find_command_binaries_in_development_dirs(); - if commands.is_empty() { - commands = find_command_binaries_in_system_path(); - } - commands +#[derive(Clone, Debug)] +struct CommandInfo { + name: String, + path: PathBuf, + is_development: bool, +} + +fn find() -> Vec { + let development_commands = find_command_binaries_in_development_dirs(); + let installed_commands = find_command_binaries_in_system_path(); + + let mut all_commands = development_commands; + all_commands.extend(installed_commands.iter().cloned()); + all_commands } -fn find_command_binaries_in_development_dirs() -> Vec { +fn find_command_binaries_in_development_dirs() -> Vec { let mut commands = Vec::new(); let current_exe = match env::current_exe() { Ok(exe) => exe, Err(_) => return commands, }; - let target_dir_name = if cfg!(debug_assertions) { + let build_type = if cfg!(debug_assertions) { "debug" } else { "release" }; - let target_dir = current_exe + + // Get the location of the binary directory for the build + let binary_dir = current_exe .parent() .unwrap() .parent() .unwrap() - .join(target_dir_name); + .join(build_type); - if let Ok(entries) = fs::read_dir(&target_dir) { + if let Ok(entries) = fs::read_dir(&binary_dir) { for entry in entries.filter_map(Result::ok) { let path = entry.path(); if is_valid_command_binary(&path) { if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { let stripped = command_name.strip_prefix("iox2-").unwrap_or(command_name); - commands.push(stripped.to_string()); + commands.push(CommandInfo { + name: stripped.to_string(), + path, + is_development: true, + }); } } } @@ -52,7 +73,7 @@ fn find_command_binaries_in_development_dirs() -> Vec { commands } -fn find_command_binaries_in_system_path() -> Vec { +fn find_command_binaries_in_system_path() -> Vec { let mut commands = Vec::new(); if let Ok(path_var) = env::var("PATH") { for path in env::split_paths(&path_var) { @@ -61,7 +82,11 @@ fn find_command_binaries_in_system_path() -> Vec { let path = entry.path(); if is_valid_command_binary(&path) { if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { - commands.push(command_name.to_string()); + commands.push(CommandInfo { + name: command_name.to_string(), + path, + is_development: false, + }); } } } From 9961cacf23f6ed26abce44243aeeee3a08bfe1e0 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Sun, 28 Jan 2024 21:04:10 +0100 Subject: [PATCH 06/17] [#98] Execute commands found in separate binaries --- iceoryx2-cli/iox2/Cargo.toml | 1 + iceoryx2-cli/iox2/src/cli.rs | 3 ++ iceoryx2-cli/iox2/src/commands.rs | 67 +++++++++++++++++++++++++++---- iceoryx2-cli/iox2/src/main.rs | 15 +++++++ 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/iceoryx2-cli/iox2/Cargo.toml b/iceoryx2-cli/iox2/Cargo.toml index 7e630195c..a945b2bf1 100644 --- a/iceoryx2-cli/iox2/Cargo.toml +++ b/iceoryx2-cli/iox2/Cargo.toml @@ -15,3 +15,4 @@ human-panic = "1.2.3" better-panic = "0.3.0" clap = { version = "4.4.18", features = ["derive"] } colored = "2.0" +thiserror = "1.0.56" diff --git a/iceoryx2-cli/iox2/src/cli.rs b/iceoryx2-cli/iox2/src/cli.rs index 14ce10000..d891eb0e4 100644 --- a/iceoryx2-cli/iox2/src/cli.rs +++ b/iceoryx2-cli/iox2/src/cli.rs @@ -16,6 +16,9 @@ pub struct Cli { #[arg(short, long, help = "Run development commands")] pub dev: bool, + + #[arg(hide = true, required = false)] + pub external_command: Vec, } fn help_template() -> &'static str { diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index 5bea9544e..7ca1c4d7f 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -2,6 +2,23 @@ use colored::*; use std::env; use std::fs; use std::path::PathBuf; +use std::process::{Command, Stdio}; +use thiserror::Error; + +#[derive(Clone, Debug)] +struct CommandInfo { + name: String, + path: PathBuf, + is_development: bool, +} + +#[derive(Error, Debug)] +pub enum ExecutionError { + #[error("Command not found: {0}")] + NotFound(String), + #[error("Execution failed: {0}")] + Failed(String), +} pub fn list() { println!("Installed Commands:"); @@ -11,20 +28,13 @@ pub fn list() { " {}", format!( "{}{}", + if command.is_development { "(dev) " } else { "" }, command.name.bold(), - if command.is_development { " (dev)" } else { "" } ) ); } } -#[derive(Clone, Debug)] -struct CommandInfo { - name: String, - path: PathBuf, - is_development: bool, -} - fn find() -> Vec { let development_commands = find_command_binaries_in_development_dirs(); let installed_commands = find_command_binaries_in_system_path(); @@ -107,3 +117,44 @@ fn is_valid_command_binary(path: &PathBuf) -> bool { .starts_with("iox2-") && path.extension().is_none() // Exclude files with extensions (e.g. '.d') } + +pub fn execute_external_command( + command_name: &str, + args: &[String], + dev_flag_present: bool, +) -> Result<(), ExecutionError> { + let available_commands = find(); + if let Some(command_info) = available_commands.into_iter().find(|c| { + &c.name == command_name + && if dev_flag_present { + c.is_development == true + } else { + if c.is_development { + println!( + "Development version of {} found but --dev flag is not set.", + command_name + ) + } + false + } + }) { + execute(&command_info, Some(args)) + } else { + Err(ExecutionError::NotFound(command_name.to_string())) + } +} + +fn execute(command_info: &CommandInfo, args: Option<&[String]>) -> Result<(), ExecutionError> { + let mut command = Command::new(&command_info.path); + command.stdout(Stdio::inherit()).stderr(Stdio::inherit()); + if let Some(arguments) = args { + command.args(arguments); + } + match command.status() { + Ok(_) => Ok(()), + Err(e) => Err(ExecutionError::Failed(format!( + "Failed to execute command: {}", + e + ))), + } +} diff --git a/iceoryx2-cli/iox2/src/main.rs b/iceoryx2-cli/iox2/src/main.rs index 44cfcd1b2..43bc1c5ab 100644 --- a/iceoryx2-cli/iox2/src/main.rs +++ b/iceoryx2-cli/iox2/src/main.rs @@ -27,5 +27,20 @@ fn main() { if cli.list { commands::list(); + } else if !cli.external_command.is_empty() { + let command_name = &cli.external_command[0]; + let command_args = &cli.external_command[1..]; + match commands::execute_external_command(command_name, command_args, cli.dev) { + Ok(()) => { + // Command executed successfully, nothing to do + } + Err(commands::ExecutionError::NotFound(_)) => { + // Command not found, print help + println!("Command not found. See all installed commands with --list."); + } + Err(commands::ExecutionError::Failed(_)) => { + println!("Command found but execution failed ..."); + } + } } } From bd61106cffeb05c0938ac78c378e366d656b4a35 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Wed, 22 May 2024 22:53:07 +0200 Subject: [PATCH 07/17] [#98] Change C++-style parsing of system path to Rust functional style --- iceoryx2-cli/iox2/src/commands.rs | 43 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index 7ca1c4d7f..3336aad48 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -84,27 +84,30 @@ fn find_command_binaries_in_development_dirs() -> Vec { } fn find_command_binaries_in_system_path() -> Vec { - let mut commands = Vec::new(); - if let Ok(path_var) = env::var("PATH") { - for path in env::split_paths(&path_var) { - if let Ok(entries) = fs::read_dir(path) { - for entry in entries.filter_map(Result::ok) { - let path = entry.path(); - if is_valid_command_binary(&path) { - if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { - commands.push(CommandInfo { - name: command_name.to_string(), - path, - is_development: false, - }); - } - } - } + env::var("PATH") + .ok() + .into_iter() + .flat_map(|path_var| env::split_paths(&path_var).collect::>()) + .flat_map(|path: PathBuf| { + fs::read_dir(path) + .into_iter() + .flat_map(|read_dir| read_dir.filter_map(Result::ok)) + }) + .filter_map(|entry| { + let path = entry.path(); + if is_valid_command_binary(&path) { + path.file_name() + .and_then(|n| n.to_str()) + .map(|command_name| CommandInfo { + name: command_name.to_string(), + path: path.clone(), + is_development: false, + }) + } else { + None } - } - } - - commands + }) + .collect() } fn is_valid_command_binary(path: &PathBuf) -> bool { From d4176d57bf6d71ab06d67b0848b9d05600edda61 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Wed, 22 May 2024 23:50:20 +0200 Subject: [PATCH 08/17] [#98] Change console output to more closely resemble cargo --- iceoryx2-cli/iox2/Cargo.toml | 2 +- iceoryx2-cli/iox2/src/cli.rs | 24 ++++++++---- iceoryx2-cli/iox2/src/commands.rs | 61 ++++++++++++++++++------------- 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/iceoryx2-cli/iox2/Cargo.toml b/iceoryx2-cli/iox2/Cargo.toml index a945b2bf1..bdf2de5d1 100644 --- a/iceoryx2-cli/iox2/Cargo.toml +++ b/iceoryx2-cli/iox2/Cargo.toml @@ -14,5 +14,5 @@ version = { workspace = true } human-panic = "1.2.3" better-panic = "0.3.0" clap = { version = "4.4.18", features = ["derive"] } -colored = "2.0" +colored = "2.1" thiserror = "1.0.56" diff --git a/iceoryx2-cli/iox2/src/cli.rs b/iceoryx2-cli/iox2/src/cli.rs index d891eb0e4..a826c59da 100644 --- a/iceoryx2-cli/iox2/src/cli.rs +++ b/iceoryx2-cli/iox2/src/cli.rs @@ -1,4 +1,5 @@ use clap::Parser; +use colored::*; #[derive(Parser, Debug)] #[command( @@ -14,17 +15,26 @@ pub struct Cli { #[arg(short, long, help = "List all installed commands")] pub list: bool, - #[arg(short, long, help = "Run development commands")] + #[arg( + short, + long, + help = "Specify to execute development versions of commands if they exist" + )] pub dev: bool, #[arg(hide = true, required = false)] pub external_command: Vec, } -fn help_template() -> &'static str { - "\ - USAGE: iox2 [OPTIONS] \n\n\ - OPTIONS:\n{options}\n\n\ - COMMANDS:\n{subcommands}\n\ - \u{00A0}\u{00A0}... See all installed commands with --list" +fn help_template() -> String { + format!( + "{}{}{}\n\n{}\n{{options}}\n\n{}\n{{subcommands}}{}{}", + "Usage: ".bright_green().bold(), + "iox2 ".bold(), + "[OPTIONS] [COMMAND]", + "Options:".bright_green().bold(), + "Commands:".bright_green().bold(), + " ... ".bold(), + "See all installed commands with --list" + ) } diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index 3336aad48..e022626b7 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -21,18 +21,26 @@ pub enum ExecutionError { } pub fn list() { - println!("Installed Commands:"); - let installed_commands = find(); - for command in installed_commands { - println!( - " {}", + println!("{}", "Installed Commands:".bright_green().bold()); + let mut installed_commands = find(); + installed_commands.sort_by_key(|command| command.name.clone()); + installed_commands + .iter() + .map(|command| { format!( - "{}{}", - if command.is_development { "(dev) " } else { "" }, - command.name.bold(), + " {}", + format!( + "{} {}", + command.name.bold(), + if command.is_development { + "(dev) ".italic() + } else { + "".italic() + }, + ) ) - ); - } + }) + .for_each(|formatted_command| println!("{}", formatted_command)); } fn find() -> Vec { @@ -45,10 +53,9 @@ fn find() -> Vec { } fn find_command_binaries_in_development_dirs() -> Vec { - let mut commands = Vec::new(); let current_exe = match env::current_exe() { Ok(exe) => exe, - Err(_) => return commands, + Err(_) => return Vec::new(), }; let build_type = if cfg!(debug_assertions) { "debug" @@ -64,23 +71,25 @@ fn find_command_binaries_in_development_dirs() -> Vec { .unwrap() .join(build_type); - if let Ok(entries) = fs::read_dir(&binary_dir) { - for entry in entries.filter_map(Result::ok) { - let path = entry.path(); - if is_valid_command_binary(&path) { - if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) { + fs::read_dir(binary_dir) + .ok() + .into_iter() + .flat_map(|entries| entries.filter_map(Result::ok)) + .map(|entry| entry.path()) + .filter(|path| is_valid_command_binary(path)) + .filter_map(|path| { + path.file_name() + .and_then(|n| n.to_str()) + .map(|command_name| { let stripped = command_name.strip_prefix("iox2-").unwrap_or(command_name); - commands.push(CommandInfo { + CommandInfo { name: stripped.to_string(), - path, + path: path.clone(), is_development: true, - }); - } - } - } - } - - commands + } + }) + }) + .collect() } fn find_command_binaries_in_system_path() -> Vec { From e594ad10ed341986893527c3669d93fef381a826 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Thu, 23 May 2024 00:36:55 +0200 Subject: [PATCH 09/17] [#98] Add command to display paths searched for command binaries --- iceoryx2-cli/iox2/src/cli.rs | 7 +++ iceoryx2-cli/iox2/src/commands.rs | 83 ++++++++++++++++++++++--------- iceoryx2-cli/iox2/src/main.rs | 2 + 3 files changed, 68 insertions(+), 24 deletions(-) diff --git a/iceoryx2-cli/iox2/src/cli.rs b/iceoryx2-cli/iox2/src/cli.rs index a826c59da..beeba2161 100644 --- a/iceoryx2-cli/iox2/src/cli.rs +++ b/iceoryx2-cli/iox2/src/cli.rs @@ -15,6 +15,13 @@ pub struct Cli { #[arg(short, long, help = "List all installed commands")] pub list: bool, + #[arg( + short, + long, + help = "Display paths that will be checked for installed commands" + )] + pub paths: bool, + #[arg( short, long, diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index e022626b7..2162f87d9 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -1,6 +1,7 @@ use colored::*; use std::env; use std::fs; +use std::io; use std::path::PathBuf; use std::process::{Command, Stdio}; use thiserror::Error; @@ -43,35 +44,52 @@ pub fn list() { .for_each(|formatted_command| println!("{}", formatted_command)); } +fn get_build_path_dirs() -> Result { + let current_exe = env::current_exe()?; + + let build_type = if cfg!(debug_assertions) { + "debug" + } else { + "release" + }; + + let build_path = current_exe + .parent() + .and_then(|p| p.parent()) + .map(|p| p.join(build_type)) + .ok_or_else(|| { + io::Error::new( + io::ErrorKind::Other, + "Failed to construct path of development dir", + ) + })?; + + Ok(build_path) +} + +fn get_install_path_dirs() -> impl Iterator { + env::var("PATH") + .ok() + .into_iter() + .flat_map(|path_var| env::split_paths(&path_var).collect::>()) +} + fn find() -> Vec { - let development_commands = find_command_binaries_in_development_dirs(); - let installed_commands = find_command_binaries_in_system_path(); + let development_commands = find_development_command_binaries(); + let installed_commands = find_installed_command_binaries(); let mut all_commands = development_commands; all_commands.extend(installed_commands.iter().cloned()); all_commands } -fn find_command_binaries_in_development_dirs() -> Vec { - let current_exe = match env::current_exe() { - Ok(exe) => exe, +fn find_development_command_binaries() -> Vec { + let development_binaries_dir = match get_build_path_dirs() { + Ok(location) => location, Err(_) => return Vec::new(), }; - let build_type = if cfg!(debug_assertions) { - "debug" - } else { - "release" - }; - - // Get the location of the binary directory for the build - let binary_dir = current_exe - .parent() - .unwrap() - .parent() - .unwrap() - .join(build_type); - fs::read_dir(binary_dir) + fs::read_dir(development_binaries_dir) .ok() .into_iter() .flat_map(|entries| entries.filter_map(Result::ok)) @@ -92,11 +110,8 @@ fn find_command_binaries_in_development_dirs() -> Vec { .collect() } -fn find_command_binaries_in_system_path() -> Vec { - env::var("PATH") - .ok() - .into_iter() - .flat_map(|path_var| env::split_paths(&path_var).collect::>()) +fn find_installed_command_binaries() -> Vec { + get_install_path_dirs() .flat_map(|path: PathBuf| { fs::read_dir(path) .into_iter() @@ -130,6 +145,26 @@ fn is_valid_command_binary(path: &PathBuf) -> bool { && path.extension().is_none() // Exclude files with extensions (e.g. '.d') } +pub fn paths() { + let mut development_binaries_dirs = Vec::new(); + development_binaries_dirs.extend(get_build_path_dirs().ok()); + + let mut installed_binaries_dirs = Vec::new(); + installed_binaries_dirs.extend(get_install_path_dirs()); + + println!("{}", "Development Binary Paths:".bright_green().bold()); + for dir in &development_binaries_dirs { + println!(" {}", dir.display().to_string().bold()); + } + + println!(); + + println!("{}", "Installed Binary Paths:".bright_green().bold()); + for dir in &installed_binaries_dirs { + println!(" {}", dir.display().to_string().bold()); + } +} + pub fn execute_external_command( command_name: &str, args: &[String], diff --git a/iceoryx2-cli/iox2/src/main.rs b/iceoryx2-cli/iox2/src/main.rs index 43bc1c5ab..363fc2aa7 100644 --- a/iceoryx2-cli/iox2/src/main.rs +++ b/iceoryx2-cli/iox2/src/main.rs @@ -27,6 +27,8 @@ fn main() { if cli.list { commands::list(); + } else if cli.paths { + commands::paths(); } else if !cli.external_command.is_empty() { let command_name = &cli.external_command[0]; let command_args = &cli.external_command[1..]; From 41cb4ec7e7e1591ebe2064c49b85b19c7ab43373 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Thu, 23 May 2024 01:23:52 +0200 Subject: [PATCH 10/17] [#98] Fix linting --- iceoryx2-cli/iox2/src/commands.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index 2162f87d9..fd7777c9c 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -2,6 +2,7 @@ use colored::*; use std::env; use std::fs; use std::io; +use std::path::Path; use std::path::PathBuf; use std::process::{Command, Stdio}; use thiserror::Error; @@ -29,16 +30,13 @@ pub fn list() { .iter() .map(|command| { format!( - " {}", - format!( - "{} {}", - command.name.bold(), - if command.is_development { - "(dev) ".italic() - } else { - "".italic() - }, - ) + " {} {}", + command.name.bold(), + if command.is_development { + "(dev) ".italic() + } else { + "".italic() + }, ) }) .for_each(|formatted_command| println!("{}", formatted_command)); @@ -94,7 +92,7 @@ fn find_development_command_binaries() -> Vec { .into_iter() .flat_map(|entries| entries.filter_map(Result::ok)) .map(|entry| entry.path()) - .filter(|path| is_valid_command_binary(path)) + .filter(|path_buf: &PathBuf| is_valid_command_binary(path_buf.as_path())) .filter_map(|path| { path.file_name() .and_then(|n| n.to_str()) @@ -134,7 +132,7 @@ fn find_installed_command_binaries() -> Vec { .collect() } -fn is_valid_command_binary(path: &PathBuf) -> bool { +fn is_valid_command_binary(path: &Path) -> bool { path.is_file() && path .file_stem() @@ -172,9 +170,9 @@ pub fn execute_external_command( ) -> Result<(), ExecutionError> { let available_commands = find(); if let Some(command_info) = available_commands.into_iter().find(|c| { - &c.name == command_name + c.name == command_name && if dev_flag_present { - c.is_development == true + c.is_development } else { if c.is_development { println!( From 6fc0c1aabf82e212ee938f64ec5cca090fbb9d02 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Thu, 23 May 2024 01:39:36 +0200 Subject: [PATCH 11/17] [#98] Add copyright header --- iceoryx2-cli/iox2-introspect/src/main.rs | 12 ++++++++++++ iceoryx2-cli/iox2-processes/src/main.rs | 12 ++++++++++++ iceoryx2-cli/iox2-pub/src/main.rs | 12 ++++++++++++ iceoryx2-cli/iox2-rpc/src/main.rs | 12 ++++++++++++ iceoryx2-cli/iox2-services/src/main.rs | 12 ++++++++++++ iceoryx2-cli/iox2-sub/src/main.rs | 12 ++++++++++++ iceoryx2-cli/iox2/src/cli.rs | 12 ++++++++++++ iceoryx2-cli/iox2/src/commands.rs | 12 ++++++++++++ iceoryx2-cli/iox2/src/main.rs | 12 ++++++++++++ 9 files changed, 108 insertions(+) diff --git a/iceoryx2-cli/iox2-introspect/src/main.rs b/iceoryx2-cli/iox2-introspect/src/main.rs index 271c1ee2e..3a00e264d 100644 --- a/iceoryx2-cli/iox2-introspect/src/main.rs +++ b/iceoryx2-cli/iox2-introspect/src/main.rs @@ -1,3 +1,15 @@ +// 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 + fn main() { println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-processes/src/main.rs b/iceoryx2-cli/iox2-processes/src/main.rs index 271c1ee2e..3a00e264d 100644 --- a/iceoryx2-cli/iox2-processes/src/main.rs +++ b/iceoryx2-cli/iox2-processes/src/main.rs @@ -1,3 +1,15 @@ +// 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 + fn main() { println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-pub/src/main.rs b/iceoryx2-cli/iox2-pub/src/main.rs index 271c1ee2e..3a00e264d 100644 --- a/iceoryx2-cli/iox2-pub/src/main.rs +++ b/iceoryx2-cli/iox2-pub/src/main.rs @@ -1,3 +1,15 @@ +// 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 + fn main() { println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-rpc/src/main.rs b/iceoryx2-cli/iox2-rpc/src/main.rs index 271c1ee2e..3a00e264d 100644 --- a/iceoryx2-cli/iox2-rpc/src/main.rs +++ b/iceoryx2-cli/iox2-rpc/src/main.rs @@ -1,3 +1,15 @@ +// 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 + fn main() { println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-services/src/main.rs b/iceoryx2-cli/iox2-services/src/main.rs index 271c1ee2e..3a00e264d 100644 --- a/iceoryx2-cli/iox2-services/src/main.rs +++ b/iceoryx2-cli/iox2-services/src/main.rs @@ -1,3 +1,15 @@ +// 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 + fn main() { println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2-sub/src/main.rs b/iceoryx2-cli/iox2-sub/src/main.rs index 271c1ee2e..3a00e264d 100644 --- a/iceoryx2-cli/iox2-sub/src/main.rs +++ b/iceoryx2-cli/iox2-sub/src/main.rs @@ -1,3 +1,15 @@ +// 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 + fn main() { println!("Not implemented. Stay tuned !"); } diff --git a/iceoryx2-cli/iox2/src/cli.rs b/iceoryx2-cli/iox2/src/cli.rs index beeba2161..75d2e1a46 100644 --- a/iceoryx2-cli/iox2/src/cli.rs +++ b/iceoryx2-cli/iox2/src/cli.rs @@ -1,3 +1,15 @@ +// 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 colored::*; diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index fd7777c9c..1ef0973f9 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -1,3 +1,15 @@ +// 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 colored::*; use std::env; use std::fs; diff --git a/iceoryx2-cli/iox2/src/main.rs b/iceoryx2-cli/iox2/src/main.rs index 363fc2aa7..02e20b69b 100644 --- a/iceoryx2-cli/iox2/src/main.rs +++ b/iceoryx2-cli/iox2/src/main.rs @@ -1,3 +1,15 @@ +// 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 + #[cfg(not(debug_assertions))] use human_panic::setup_panic; From 1368001a7e91189834795dbef58cdebca5d76abc Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Thu, 23 May 2024 23:15:34 +0200 Subject: [PATCH 12/17] [#98] Move CLI dependencies to workspace Cargo.toml --- Cargo.toml | 4 ++++ iceoryx2-cli/iox2/Cargo.toml | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3c9e108c1..b311ecf8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,10 @@ cc = { version = "1.0.98" } cdr = { version = "0.2.4" } clap = { version = "4.5.4", features = ["derive"] } enum-iterator = { version = "2.1.0" } +better-panic = { version = "0.3.0" } +colored = { version = "2.1" } generic-tests = { version = "0.1.2" } +human-panic = { version = "1.2.3" } lazy_static = { version = "1.4.0" } log = { version = "0.4.21" } once_cell = { version = "1.19.0" } @@ -90,6 +93,7 @@ serde_test = { version = "1.0.176" } sha1_smol = { version = "1.0.0" } syn = { version = "2.0.66", features = ["full"] } termsize = { version = "0.1.6" } +thiserror = { version = "1.0.56" } tiny-fn = { version = "0.1.5" } toml = { version = "0.8.13" } tracing = { version = "0.1.40" } diff --git a/iceoryx2-cli/iox2/Cargo.toml b/iceoryx2-cli/iox2/Cargo.toml index bdf2de5d1..dd6c84189 100644 --- a/iceoryx2-cli/iox2/Cargo.toml +++ b/iceoryx2-cli/iox2/Cargo.toml @@ -11,8 +11,8 @@ rust-version = { workspace = true } version = { workspace = true } [dependencies] -human-panic = "1.2.3" -better-panic = "0.3.0" -clap = { version = "4.4.18", features = ["derive"] } -colored = "2.1" -thiserror = "1.0.56" +human-panic = { workspace = true } +better-panic = { workspace = true } +clap = { workspace = true } +colored = { workspace = true } +thiserror = { workspace = true } From 00db235d55596294280fb9bd610ce2b7c5e22f37 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Thu, 23 May 2024 23:43:13 +0200 Subject: [PATCH 13/17] [#98] Add release notes --- doc/release-notes/iceoryx2-unreleased.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release-notes/iceoryx2-unreleased.md b/doc/release-notes/iceoryx2-unreleased.md index 73b3641ef..d4f04c9d7 100644 --- a/doc/release-notes/iceoryx2-unreleased.md +++ b/doc/release-notes/iceoryx2-unreleased.md @@ -9,6 +9,8 @@ * Subscriber buffer size can be reduced [#19](https://github.com/eclipse-iceoryx/iceoryx2/issues/19) + * CLI for iox2 [#98](https://github.com/eclipse-iceoryx/iceoryx2/issues/98) + * Add entrypoint CLI `iox2` in preparation for adding additional CLI commands * Introduce Nodes [#102](https://github.com/eclipse-iceoryx/iceoryx2/issues/102) * Implement Serialize,Deserialize for * `SemanticString` From 5c8f9ba5dc65ba7cc2be75f496a1abd1e15a68ea Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Sun, 23 Jun 2024 21:46:18 +0200 Subject: [PATCH 14/17] [#98] Remove duplicate logic in identifying command binaries --- iceoryx2-cli/iox2/src/commands.rs | 255 ++++++++++++++++-------------- 1 file changed, 134 insertions(+), 121 deletions(-) diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index 1ef0973f9..c08ac1fb5 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -12,18 +12,23 @@ use colored::*; use std::env; +use std::ffi::OsStr; use std::fs; use std::io; -use std::path::Path; use std::path::PathBuf; use std::process::{Command, Stdio}; use thiserror::Error; +#[derive(Clone, Debug, PartialEq)] +enum CommandType { + Installed, + Development, +} + #[derive(Clone, Debug)] struct CommandInfo { - name: String, path: PathBuf, - is_development: bool, + command_type: CommandType, } #[derive(Error, Debug)] @@ -36,25 +41,42 @@ pub enum ExecutionError { pub fn list() { println!("{}", "Installed Commands:".bright_green().bold()); - let mut installed_commands = find(); - installed_commands.sort_by_key(|command| command.name.clone()); - installed_commands - .iter() - .map(|command| { - format!( - " {} {}", - command.name.bold(), - if command.is_development { - "(dev) ".italic() - } else { - "".italic() - }, - ) - }) - .for_each(|formatted_command| println!("{}", formatted_command)); + + if let Ok(mut commands) = find_command_binaries() { + commands.sort_by_key(|command| { + command + .path + .file_name() + .expect("Could not extract file name from command binary path") + .to_os_string() + }); + commands + .iter() + .map(|command| { + format!( + " {} {}", + // TODO: Simplify logic for extracting name to remove this duplication + command + .path + .file_name() + .and_then(|os_str| os_str.to_str()) + .and_then(|command_name| command_name.strip_prefix("iox2-")) + .expect("Unable to extract command name from command path") + .bold(), + if command.command_type == CommandType::Development { + "(dev) ".italic() + } else { + "".italic() + }, + ) + }) + .for_each(|formatted_command| println!("{}", formatted_command)); + } else { + // handle error ... + } } -fn get_build_path_dirs() -> Result { +fn build_dirs() -> Result, std::io::Error> { let current_exe = env::current_exe()?; let build_type = if cfg!(debug_assertions) { @@ -63,115 +85,100 @@ fn get_build_path_dirs() -> Result { "release" }; - let build_path = current_exe + let paths = current_exe .parent() .and_then(|p| p.parent()) .map(|p| p.join(build_type)) + .filter(|p| p.is_dir()) .ok_or_else(|| { io::Error::new( - io::ErrorKind::Other, - "Failed to construct path of development dir", + io::ErrorKind::NotFound, + "Unable to determine build path from executable path", ) })?; - Ok(build_path) + Ok(vec![paths]) } -fn get_install_path_dirs() -> impl Iterator { +fn install_dirs() -> Result, std::io::Error> { env::var("PATH") - .ok() - .into_iter() - .flat_map(|path_var| env::split_paths(&path_var).collect::>()) -} - -fn find() -> Vec { - let development_commands = find_development_command_binaries(); - let installed_commands = find_installed_command_binaries(); - - let mut all_commands = development_commands; - all_commands.extend(installed_commands.iter().cloned()); - all_commands + .map(|paths| { + paths + .split(':') + .map(PathBuf::from) + .filter(|p| p.is_dir()) + .collect() + }) + .map_err(|_| { + std::io::Error::new( + std::io::ErrorKind::NotFound, + "Unable to determine install path from environment", + ) + }) } -fn find_development_command_binaries() -> Vec { - let development_binaries_dir = match get_build_path_dirs() { - Ok(location) => location, - Err(_) => return Vec::new(), - }; - - fs::read_dir(development_binaries_dir) - .ok() - .into_iter() - .flat_map(|entries| entries.filter_map(Result::ok)) +fn find_command_binaries_in_path(dirs: Vec) -> Vec { + dirs.into_iter() + .flat_map(|dir| fs::read_dir(dir).into_iter().flatten()) + .filter_map(|entry| entry.ok()) .map(|entry| entry.path()) - .filter(|path_buf: &PathBuf| is_valid_command_binary(path_buf.as_path())) - .filter_map(|path| { + .filter(|path| path.is_file()) // filter out dirs + .filter(|path| path.extension().is_none()) // valid binaries have no extension (e.g. '.d') + .filter(|path| { path.file_name() - .and_then(|n| n.to_str()) - .map(|command_name| { - let stripped = command_name.strip_prefix("iox2-").unwrap_or(command_name); - CommandInfo { - name: stripped.to_string(), - path: path.clone(), - is_development: true, - } - }) - }) - .collect() -} - -fn find_installed_command_binaries() -> Vec { - get_install_path_dirs() - .flat_map(|path: PathBuf| { - fs::read_dir(path) - .into_iter() - .flat_map(|read_dir| read_dir.filter_map(Result::ok)) - }) - .filter_map(|entry| { - let path = entry.path(); - if is_valid_command_binary(&path) { - path.file_name() - .and_then(|n| n.to_str()) - .map(|command_name| CommandInfo { - name: command_name.to_string(), - path: path.clone(), - is_development: false, - }) - } else { - None - } + .and_then(OsStr::to_str) + .filter(|name| name.starts_with("iox2-")) // iox2 command start with 'iox2-' + .is_some() }) .collect() } -fn is_valid_command_binary(path: &Path) -> bool { - path.is_file() - && path - .file_stem() - .unwrap() - .to_str() - .unwrap() - .starts_with("iox2-") - && path.extension().is_none() // Exclude files with extensions (e.g. '.d') +fn find_command_binaries() -> Result, io::Error> { + let mut command_binaries: Vec = Vec::new(); + + // Find binaries in both build dirs and the install path + command_binaries.extend( + find_command_binaries_in_path(build_dirs()?) + .into_iter() + .map(|path| CommandInfo { + path, + command_type: CommandType::Development, + }), + ); + command_binaries.extend( + find_command_binaries_in_path(install_dirs()?) + .into_iter() + .map(|path| CommandInfo { + path, + command_type: CommandType::Installed, + }), + ); + + Ok(command_binaries) } pub fn paths() { - let mut development_binaries_dirs = Vec::new(); - development_binaries_dirs.extend(get_build_path_dirs().ok()); - - let mut installed_binaries_dirs = Vec::new(); - installed_binaries_dirs.extend(get_install_path_dirs()); - - println!("{}", "Development Binary Paths:".bright_green().bold()); - for dir in &development_binaries_dirs { - println!(" {}", dir.display().to_string().bold()); + match build_dirs() { + Ok(dirs) => { + println!("{}", "Development Binary Paths:".bright_green().bold()); + for dir in dirs { + println!(" {}", dir.display().to_string().bold()); + } + } + Err(e) => { + println!("Error retrieving build dirs: {e}"); + } } - - println!(); - - println!("{}", "Installed Binary Paths:".bright_green().bold()); - for dir in &installed_binaries_dirs { - println!(" {}", dir.display().to_string().bold()); + match install_dirs() { + Ok(dirs) => { + println!("{}", "Installed Binary Paths:".bright_green().bold()); + for dir in dirs { + println!(" {}", dir.display().to_string().bold()); + } + } + Err(e) => { + println!("Error retrieving install dirs: {e}"); + } } } @@ -180,22 +187,28 @@ pub fn execute_external_command( args: &[String], dev_flag_present: bool, ) -> Result<(), ExecutionError> { - let available_commands = find(); - if let Some(command_info) = available_commands.into_iter().find(|c| { - c.name == command_name - && if dev_flag_present { - c.is_development - } else { - if c.is_development { - println!( - "Development version of {} found but --dev flag is not set.", - command_name - ) + if let Ok(commands) = find_command_binaries() { + let command_info = commands + .into_iter() + .filter(|command| { + if dev_flag_present { + command.command_type == CommandType::Development + } else { + command.command_type == CommandType::Installed } - false - } - }) { - execute(&command_info, Some(args)) + }) + .find(|command| { + command + // TODO: Simplify logic for extracting name to remove this duplication + .path + .file_name() + .and_then(|os_str| os_str.to_str()) + .and_then(|command_name| command_name.strip_prefix("iox2-")) + .expect("Unable to extract command name from command path") + == command_name + }) + .ok_or_else(|| ExecutionError::NotFound(command_name.to_string()))?; + execute(&command_info, Some(args)) // TODO: Remove Some() } else { Err(ExecutionError::NotFound(command_name.to_string())) } From 41f522f53cd3f546f85ee0a71d7b24cdb71c3898 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Mon, 24 Jun 2024 21:18:57 +0200 Subject: [PATCH 15/17] [#98] Print message if failing to parse command with CLI --- iceoryx2-cli/iox2/src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iceoryx2-cli/iox2/src/main.rs b/iceoryx2-cli/iox2/src/main.rs index 02e20b69b..cbef62217 100644 --- a/iceoryx2-cli/iox2/src/main.rs +++ b/iceoryx2-cli/iox2/src/main.rs @@ -56,5 +56,7 @@ fn main() { println!("Command found but execution failed ..."); } } + } else { + println!("No CLI command detected. Exiting."); } } From 6ea8f1b569ed77d6b91003a8af78ed4683c93b6b Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Mon, 24 Jun 2024 21:25:24 +0200 Subject: [PATCH 16/17] [#98] Fix some grammar --- iceoryx2-cli/iox2-introspect/src/main.rs | 2 +- iceoryx2-cli/iox2-processes/src/main.rs | 2 +- iceoryx2-cli/iox2-pub/src/main.rs | 2 +- iceoryx2-cli/iox2-rpc/src/main.rs | 2 +- iceoryx2-cli/iox2-services/src/main.rs | 2 +- iceoryx2-cli/iox2-sub/src/main.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iceoryx2-cli/iox2-introspect/src/main.rs b/iceoryx2-cli/iox2-introspect/src/main.rs index 3a00e264d..6cacb56d6 100644 --- a/iceoryx2-cli/iox2-introspect/src/main.rs +++ b/iceoryx2-cli/iox2-introspect/src/main.rs @@ -11,5 +11,5 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT fn main() { - println!("Not implemented. Stay tuned !"); + println!("Not implemented. Stay tuned!"); } diff --git a/iceoryx2-cli/iox2-processes/src/main.rs b/iceoryx2-cli/iox2-processes/src/main.rs index 3a00e264d..6cacb56d6 100644 --- a/iceoryx2-cli/iox2-processes/src/main.rs +++ b/iceoryx2-cli/iox2-processes/src/main.rs @@ -11,5 +11,5 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT fn main() { - println!("Not implemented. Stay tuned !"); + println!("Not implemented. Stay tuned!"); } diff --git a/iceoryx2-cli/iox2-pub/src/main.rs b/iceoryx2-cli/iox2-pub/src/main.rs index 3a00e264d..6cacb56d6 100644 --- a/iceoryx2-cli/iox2-pub/src/main.rs +++ b/iceoryx2-cli/iox2-pub/src/main.rs @@ -11,5 +11,5 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT fn main() { - println!("Not implemented. Stay tuned !"); + println!("Not implemented. Stay tuned!"); } diff --git a/iceoryx2-cli/iox2-rpc/src/main.rs b/iceoryx2-cli/iox2-rpc/src/main.rs index 3a00e264d..6cacb56d6 100644 --- a/iceoryx2-cli/iox2-rpc/src/main.rs +++ b/iceoryx2-cli/iox2-rpc/src/main.rs @@ -11,5 +11,5 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT fn main() { - println!("Not implemented. Stay tuned !"); + println!("Not implemented. Stay tuned!"); } diff --git a/iceoryx2-cli/iox2-services/src/main.rs b/iceoryx2-cli/iox2-services/src/main.rs index 3a00e264d..6cacb56d6 100644 --- a/iceoryx2-cli/iox2-services/src/main.rs +++ b/iceoryx2-cli/iox2-services/src/main.rs @@ -11,5 +11,5 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT fn main() { - println!("Not implemented. Stay tuned !"); + println!("Not implemented. Stay tuned!"); } diff --git a/iceoryx2-cli/iox2-sub/src/main.rs b/iceoryx2-cli/iox2-sub/src/main.rs index 3a00e264d..6cacb56d6 100644 --- a/iceoryx2-cli/iox2-sub/src/main.rs +++ b/iceoryx2-cli/iox2-sub/src/main.rs @@ -11,5 +11,5 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT fn main() { - println!("Not implemented. Stay tuned !"); + println!("Not implemented. Stay tuned!"); } From ccbd452222a2b57a70120a10011758d0484e1d11 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Mon, 24 Jun 2024 21:30:20 +0200 Subject: [PATCH 17/17] [#98] Add TODOs for follow-up work --- iceoryx2-cli/iox2/src/commands.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iceoryx2-cli/iox2/src/commands.rs b/iceoryx2-cli/iox2/src/commands.rs index c08ac1fb5..8413a6abd 100644 --- a/iceoryx2-cli/iox2/src/commands.rs +++ b/iceoryx2-cli/iox2/src/commands.rs @@ -43,7 +43,7 @@ pub fn list() { println!("{}", "Installed Commands:".bright_green().bold()); if let Ok(mut commands) = find_command_binaries() { - commands.sort_by_key(|command| { + commands.sort_by_cached_key(|command| { command .path .file_name() @@ -64,7 +64,7 @@ pub fn list() { .expect("Unable to extract command name from command path") .bold(), if command.command_type == CommandType::Development { - "(dev) ".italic() + "(dev)".italic() } else { "".italic() }, @@ -72,7 +72,7 @@ pub fn list() { }) .for_each(|formatted_command| println!("{}", formatted_command)); } else { - // handle error ... + // TODO: handle error ... } } @@ -208,7 +208,7 @@ pub fn execute_external_command( == command_name }) .ok_or_else(|| ExecutionError::NotFound(command_name.to_string()))?; - execute(&command_info, Some(args)) // TODO: Remove Some() + execute(&command_info, Some(args)) // TODO: Remove Some() - pass optional directly } else { Err(ExecutionError::NotFound(command_name.to_string())) }