Skip to content

Commit

Permalink
refactor: compgen path if no argc script is found for the command (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Nov 12, 2023
1 parent 37a6be7 commit abe741e
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/bin/argc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,17 @@ fn run_compgen(mut args: Vec<String>) -> Option<()> {
args[3] = script_file.to_string_lossy().to_string();
} else if let Ok(script_file) = which(&args[4]) {
args[3] = script_file.to_string_lossy().to_string();
} else {
return None;
}
}
let no_color = if let Ok(v) = std::env::var("NO_COLOR") {
v == "true" || v == "1"
} else {
false
};
let output = if args.len() >= 6
&& &args[4] == "argc"
&& (args[3].is_empty() || args[5].starts_with("--argc"))
{
let no_color = std::env::var("NO_COLOR")
.map(|v| v == "true" || v == "1")
.unwrap_or_default();
let output = if &args[4] == "argc" && (args[3].is_empty() || args[5].starts_with("--argc")) {
let cmd_args = &args[4..];
argc::compgen(shell, "", COMPLETION_SCRIPT, cmd_args, no_color).ok()?
} else if args[3].is_empty() {
let cmd_args = &args[4..];
argc::compgen(shell, "", "# @arg path*", cmd_args, no_color).ok()?
} else {
let (source, cmd_args) = parse_script_args(&args[3..]).ok()?;
argc::compgen(shell, &args[3], &source, &cmd_args[1..], no_color).ok()?
Expand Down

0 comments on commit abe741e

Please sign in to comment.