Skip to content

Commit

Permalink
bugfix: generate autocompletions without the need of shuru.toml file …
Browse files Browse the repository at this point in the history
…to be present
  • Loading branch information
harshdoesdev committed Oct 6, 2024
1 parent 7ebe1ca commit 862dfdd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
22 changes: 11 additions & 11 deletions src/completions/bash.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Bash completion for shuru
_shuru() {
local cur prev words cword
_init_completion -n : || return
local cur prev words cword
_init_completion -n : || return

case "$prev" in
-h|--help)
COMPREPLY=( $( compgen -W "$(shuru --help)" -- "$cur" ) )
return 0
;;
esac
local options="-h --help -V --version --completions --list-commands"

if [[ "$prev" == -* ]]; then
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
return 0
fi

local tasks=$(shuru --list-commands)
COMPREPLY=( $( compgen -W "${tasks}" -- "$cur" ) )
local tasks
tasks=$(shuru --list-commands)
COMPREPLY=( $( compgen -W "$tasks" -- "$cur" ) )
}

complete -F _shuru shuru
6 changes: 2 additions & 4 deletions src/completions/shuru.fish
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ function __fish_shuru_list_commands
end

function __fish_shuru_complete
if test (commandline -t) = "-h" -o (commandline -t) = "--help"
shuru --help
return 0
end
set -l options "-h" "--help" "-V" "--version" "--completions" "--list-commands"

echo $options
__fish_shuru_list_commands
end

Expand Down
14 changes: 14 additions & 0 deletions src/completions/zsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ _shuru() {
local commands
commands=($(shuru --list-commands))

local completions_options
completions_options=(bash zsh fish)

local -a options
options=(
'--completions[The shell to generate completions for]: :($(printf "%s\n" "${completions_options[@]}"))'
'--list-commands[Show available commands]'
'-h[Print help]'
'--help[Print help]'
'-V[Print version]'
'--version[Print version]'
)

_arguments -s $options
_describe -t commands 'shuru commands' commands "$@"
}

Expand Down
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ fn load_config() -> Result<Config, Error> {

fn run() -> Result<std::process::ExitStatus, Error> {
let cli = Cli::parse();
let config = load_config()?;

if cli.list_commands {
for task in &config.tasks {
println!("{}", task.name);
}
std::process::exit(0);
}

if let Some(shell) = cli.completions {
let completion_script = match shell {
Expand All @@ -58,6 +50,15 @@ fn run() -> Result<std::process::ExitStatus, Error> {
std::process::exit(0);
}

let config = load_config()?;

if cli.list_commands {
for task in &config.tasks {
println!("{}", task.name);
}
std::process::exit(0);
}

let runner = CommandRunner::new(config);

match cli.command {
Expand Down

0 comments on commit 862dfdd

Please sign in to comment.