-
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.
feat: pre-rendered completions, for better testing and assertions
[GA] for fish shell, rest are under-development
- Loading branch information
1 parent
9116b0f
commit 49c3c77
Showing
11 changed files
with
229 additions
and
64 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,4 @@ | ||
.direnv | ||
bin/ | ||
.secrets/ | ||
Taskfile.yml |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
|
||
"github.com/nxtcoder17/runfile/pkg/runfile" | ||
) | ||
|
||
func generateShellCompletion(_ context.Context, writer io.Writer, rfpath string) error { | ||
// if c.NArg() > 0 { | ||
// return nil | ||
// } | ||
|
||
// runfilePath, err := locateRunfile(c) | ||
// if err != nil { | ||
// slog.Error("locating runfile", "err", err) | ||
// panic(err) | ||
// } | ||
|
||
runfile, err := runfile.Parse(rfpath) | ||
if err != nil { | ||
slog.Error("parsing, got", "err", err) | ||
panic(err) | ||
} | ||
|
||
for k := range runfile.Tasks { | ||
fmt.Fprintf(writer, "%s\n", k) | ||
} | ||
|
||
m, err := runfile.ParseIncludes() | ||
if err != nil { | ||
slog.Error("parsing, got", "err", err) | ||
panic(err) | ||
} | ||
|
||
for k, v := range m { | ||
for tn := range v.Runfile.Tasks { | ||
fmt.Fprintf(writer, "%s:%s\n", k, tn) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#! /bin/bash | ||
|
||
: ${PROG:=$(basename ${BASH_SOURCE})} | ||
|
||
# Macs have bash3 for which the bash-completion package doesn't include | ||
# _init_completion. This is a minimal version of that function. | ||
_cli_init_completion() { | ||
COMPREPLY=() | ||
_get_comp_words_by_ref "$@" cur prev words cword | ||
} | ||
|
||
_cli_bash_autocomplete() { | ||
if [[ "${COMP_WORDS[0]}" != "source" ]]; then | ||
local cur opts base words | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
if declare -F _init_completion >/dev/null 2>&1; then | ||
_init_completion -n "=:" || return | ||
else | ||
_cli_init_completion -n "=:" || return | ||
fi | ||
words=("${words[@]:0:$cword}") | ||
if [[ "$cur" == "-"* ]]; then | ||
requestComp="${words[*]} ${cur} completion:gen" | ||
else | ||
requestComp="${words[*]} completion:gen" | ||
fi | ||
opts=$(eval "${requestComp}" 2>/dev/null) | ||
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
return 0 | ||
fi | ||
} | ||
|
||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG | ||
unset PROG |
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,25 +1,35 @@ | ||
# run fish shell completion | ||
set PROGNAME run | ||
|
||
function __fetch_runnable_tasks --description 'fetches all runnable tasks' | ||
function __runfile_list_targets --description 'fetches all runnable tasks' | ||
for i in (commandline -opc) | ||
if contains -- $i help h | ||
return 1 | ||
end | ||
end | ||
|
||
# Grab names and descriptions (if any) of the tasks | ||
set -l output (run --generate-shell-completion | string split0) | ||
echo "$output" > /tmp/test.txt | ||
$PROGNAME --list 2>&1 | read -lz rawOutput | ||
|
||
# RETURN on non-zero exit code (in case of errors) | ||
if test $status -ne 0 | ||
return | ||
end | ||
|
||
set -l output (echo $rawOutput | string split0) | ||
|
||
if test $output | ||
if test "$DEBUG" = "true" | ||
echo "$output" > /tmp/test.txt | ||
end | ||
echo $output | ||
end | ||
|
||
return 0 | ||
end | ||
|
||
complete -c run -d "runs a task with given name" -xa "(__fish_run_no_subcommand)" | ||
complete -c run -n '__fish_run_no_subcommand' -f -l help -s h -d 'show help' | ||
complete -c run -n '__fish_run_no_subcommand' -f -l help -s h -d 'show help' | ||
complete -r -c run -n '__fish_run_no_subcommand' -a 'help h' -d 'Shows a list of commands or help for one command' | ||
complete -c $PROGNAME -d "runs target with given name" -xa "(__runfile_list_targets)" | ||
complete -c $PROGNAME -rF -l file -s f -d 'runs targets from this runfile' | ||
# complete -c $PROGNAME -n '__runfile_list_targets' -f -l help -s h -d 'show help' | ||
# complete -c $PROGNAME -n '__runfile_list_targets' -f -l help -s h -d 'show help' | ||
# complete -r -c $PROGNAME -n '__runfile_list_targets' -a 'help h' -d 'Shows a list of commands or help for one command' | ||
|
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#compdef $PROG | ||
|
||
_cli_zsh_autocomplete() { | ||
local -a opts | ||
local cur | ||
cur=${words[-1]} | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} completion:gen)}") | ||
else | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} completion:gen)}") | ||
fi | ||
|
||
if [[ "${opts[1]}" != "" ]]; then | ||
_describe 'values' opts | ||
else | ||
_files | ||
fi | ||
} | ||
|
||
compdef _cli_zsh_autocomplete $PROG |
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
Oops, something went wrong.