Add bash and zsh completions
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
8f9bdf69ad
commit
23fd711be2
29
main.go
29
main.go
|
@ -20,15 +20,19 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/genjidb/genji/document"
|
||||||
|
"github.com/genjidb/genji/types"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"go.arsenm.dev/logger"
|
"go.arsenm.dev/logger"
|
||||||
"go.arsenm.dev/logger/log"
|
"go.arsenm.dev/logger/log"
|
||||||
"go.arsenm.dev/lure/internal/config"
|
"go.arsenm.dev/lure/internal/config"
|
||||||
|
"go.arsenm.dev/lure/internal/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate scripts/gen-version.sh
|
//go:generate scripts/gen-version.sh
|
||||||
|
@ -58,6 +62,7 @@ func main() {
|
||||||
Usage: "Install a new package",
|
Usage: "Install a new package",
|
||||||
Aliases: []string{"in"},
|
Aliases: []string{"in"},
|
||||||
Action: installCmd,
|
Action: installCmd,
|
||||||
|
BashComplete: completionInstall,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "remove",
|
Name: "remove",
|
||||||
|
@ -150,6 +155,7 @@ func main() {
|
||||||
After: func(ctx *cli.Context) error {
|
After: func(ctx *cli.Context) error {
|
||||||
return gdb.Close()
|
return gdb.Close()
|
||||||
},
|
},
|
||||||
|
EnableBashCompletion: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := app.RunContext(ctx, os.Args)
|
err := app.RunContext(ctx, os.Args)
|
||||||
|
@ -162,3 +168,26 @@ func displayVersion(c *cli.Context) error {
|
||||||
print(config.Version)
|
print(config.Version)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func completionInstall(c *cli.Context) {
|
||||||
|
result, err := db.GetPkgs(gdb, "true")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error getting packages").Err(err).Send()
|
||||||
|
}
|
||||||
|
defer result.Close()
|
||||||
|
|
||||||
|
err = result.Iterate(func(d types.Document) error {
|
||||||
|
var pkg db.Package
|
||||||
|
err = document.StructScan(d, &pkg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(pkg.Name)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error iterating over packages").Err(err).Send()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
: ${PROG:=$(basename ${BASH_SOURCE})}
|
||||||
|
|
||||||
|
_cli_bash_autocomplete() {
|
||||||
|
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
|
||||||
|
local cur opts base
|
||||||
|
COMPREPLY=()
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
if [[ "$cur" == "-"* ]]; then
|
||||||
|
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
|
||||||
|
else
|
||||||
|
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
|
||||||
|
fi
|
||||||
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
|
||||||
|
unset PROG
|
|
@ -0,0 +1,20 @@
|
||||||
|
#compdef lure
|
||||||
|
|
||||||
|
_cli_zsh_autocomplete() {
|
||||||
|
local -a opts
|
||||||
|
local cur
|
||||||
|
cur=${words[-1]}
|
||||||
|
if [[ "$cur" == "-"* ]]; then
|
||||||
|
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
|
||||||
|
else
|
||||||
|
opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${opts[1]}" != "" ]]; then
|
||||||
|
_describe 'values' opts
|
||||||
|
else
|
||||||
|
_files
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
compdef _cli_zsh_autocomplete lure
|
Loading…
Reference in New Issue