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); + } } +