M6: shell completions with dynamic alias lookup
Add ValidArgsFunction to mount and unmount commands that reads config aliases for tab completion. Install zsh, bash, and fish completion scripts via flake postInstall. Update PLAN.md with post-1.0 roadmap. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
25
cmd/completion.go
Normal file
25
cmd/completion.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"git.wntrmute.dev/kyle/arca/internal/config"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// completeDeviceOrAlias provides dynamic completion for device aliases
|
||||
// and device paths from the config file.
|
||||
func completeDeviceOrAlias(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
if len(args) > 0 {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
cfg := config.Load()
|
||||
var completions []string
|
||||
for alias := range cfg.Devices {
|
||||
completions = append(completions, alias)
|
||||
}
|
||||
sort.Strings(completions)
|
||||
|
||||
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
@@ -15,10 +15,11 @@ import (
|
||||
var mountpoint string
|
||||
|
||||
var mountCmd = &cobra.Command{
|
||||
Use: "mount <device|alias>",
|
||||
Short: "Unlock and mount a LUKS volume",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runMount,
|
||||
Use: "mount <device|alias>",
|
||||
Short: "Unlock and mount a LUKS volume",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runMount,
|
||||
ValidArgsFunction: completeDeviceOrAlias,
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
)
|
||||
|
||||
var unmountCmd = &cobra.Command{
|
||||
Use: "unmount <device|alias>",
|
||||
Aliases: []string{"umount"},
|
||||
Short: "Unmount and lock a LUKS volume",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runUnmount,
|
||||
Use: "unmount <device|alias>",
|
||||
Aliases: []string{"umount"},
|
||||
Short: "Unmount and lock a LUKS volume",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runUnmount,
|
||||
ValidArgsFunction: completeDeviceOrAlias,
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user