Skip to content

Commit a465646

Browse files
committed
[#98] Return installed binary path along with name
1 parent f78de8b commit a465646

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

iceoryx2-cli/iox2/src/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ use clap::Parser;
1313
pub struct Cli {
1414
#[arg(short, long, help = "List all installed commands")]
1515
pub list: bool,
16+
17+
#[arg(short, long, help = "Run development commands")]
18+
pub dev: bool,
1619
}
1720

1821
fn help_template() -> &'static str {

iceoryx2-cli/iox2/src/commands.rs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,64 @@ pub fn list() {
77
println!("Installed Commands:");
88
let installed_commands = find();
99
for command in installed_commands {
10-
println!(" {}", command.bold());
10+
println!(
11+
" {}",
12+
format!(
13+
"{}{}",
14+
command.name.bold(),
15+
if command.is_development { " (dev)" } else { "" }
16+
)
17+
);
1118
}
1219
}
1320

14-
fn find() -> Vec<String> {
15-
let mut commands = find_command_binaries_in_development_dirs();
16-
if commands.is_empty() {
17-
commands = find_command_binaries_in_system_path();
18-
}
19-
commands
21+
#[derive(Clone, Debug)]
22+
struct CommandInfo {
23+
name: String,
24+
path: PathBuf,
25+
is_development: bool,
26+
}
27+
28+
fn find() -> Vec<CommandInfo> {
29+
let development_commands = find_command_binaries_in_development_dirs();
30+
let installed_commands = find_command_binaries_in_system_path();
31+
32+
let mut all_commands = development_commands;
33+
all_commands.extend(installed_commands.iter().cloned());
34+
all_commands
2035
}
2136

22-
fn find_command_binaries_in_development_dirs() -> Vec<String> {
37+
fn find_command_binaries_in_development_dirs() -> Vec<CommandInfo> {
2338
let mut commands = Vec::new();
2439
let current_exe = match env::current_exe() {
2540
Ok(exe) => exe,
2641
Err(_) => return commands,
2742
};
28-
let target_dir_name = if cfg!(debug_assertions) {
43+
let build_type = if cfg!(debug_assertions) {
2944
"debug"
3045
} else {
3146
"release"
3247
};
33-
let target_dir = current_exe
48+
49+
// Get the location of the binary directory for the build
50+
let binary_dir = current_exe
3451
.parent()
3552
.unwrap()
3653
.parent()
3754
.unwrap()
38-
.join(target_dir_name);
55+
.join(build_type);
3956

40-
if let Ok(entries) = fs::read_dir(&target_dir) {
57+
if let Ok(entries) = fs::read_dir(&binary_dir) {
4158
for entry in entries.filter_map(Result::ok) {
4259
let path = entry.path();
4360
if is_valid_command_binary(&path) {
4461
if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) {
4562
let stripped = command_name.strip_prefix("iox2-").unwrap_or(command_name);
46-
commands.push(stripped.to_string());
63+
commands.push(CommandInfo {
64+
name: stripped.to_string(),
65+
path,
66+
is_development: true,
67+
});
4768
}
4869
}
4970
}
@@ -52,7 +73,7 @@ fn find_command_binaries_in_development_dirs() -> Vec<String> {
5273
commands
5374
}
5475

55-
fn find_command_binaries_in_system_path() -> Vec<String> {
76+
fn find_command_binaries_in_system_path() -> Vec<CommandInfo> {
5677
let mut commands = Vec::new();
5778
if let Ok(path_var) = env::var("PATH") {
5879
for path in env::split_paths(&path_var) {
@@ -61,7 +82,11 @@ fn find_command_binaries_in_system_path() -> Vec<String> {
6182
let path = entry.path();
6283
if is_valid_command_binary(&path) {
6384
if let Some(command_name) = path.file_name().and_then(|n| n.to_str()) {
64-
commands.push(command_name.to_string());
85+
commands.push(CommandInfo {
86+
name: command_name.to_string(),
87+
path,
88+
is_development: false,
89+
});
6590
}
6691
}
6792
}

0 commit comments

Comments
 (0)