forked from eclipse-iceoryx/iceoryx2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-iceoryx#98] List available cli commands
- Loading branch information
Showing
8 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
println!("Not implemented. Stay tuned !"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
println!("Not implemented. Stay tuned !"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
println!("Not implemented. Stay tuned !"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
println!("Not implemented. Stay tuned !"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
println!("Not implemented. Stay tuned !"); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
println!("Not implemented. Stay tuned !"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,80 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
fn find_command_binaries_in_development_dirs() -> Vec<String> { | ||
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<String> { | ||
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); | ||
} | ||
} | ||
|