diff options
author | Robin Jarry <robin@jarry.cc> | 2023-10-22 23:23:18 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-10-28 19:25:10 +0200 |
commit | abe228b14d97d8d47e8ff4406de387fac45cfe68 (patch) | |
tree | 56117403d1ae32d7253f86bab01a944a3cf225b9 /commands/compose/attach.go | |
parent | 30851656591293ed2e19340ab78c937855a11143 (diff) | |
download | aerc-abe228b14d97d8d47e8ff4406de387fac45cfe68.tar.gz |
commands: use completion from go-opt
Implement command completion with complete struct field tags from the
get-opt library introduced earlier.
Changelog-changed: Improved command completion.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'commands/compose/attach.go')
-rw-r--r-- | commands/compose/attach.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/commands/compose/attach.go b/commands/compose/attach.go index 3acf28c2..49d63bb8 100644 --- a/commands/compose/attach.go +++ b/commands/compose/attach.go @@ -23,7 +23,8 @@ import ( type Attach struct { Menu bool `opt:"-m"` Name string `opt:"-r"` - Path string `opt:"..." metavar:"<path>" required:"false"` + Path string `opt:"path" required:"false" complete:"CompletePath"` + Args string `opt:"..." required:"false"` } func init() { @@ -34,9 +35,8 @@ func (Attach) Aliases() []string { return []string{"attach"} } -func (Attach) Complete(args []string) []string { - path := strings.Join(args, " ") - return commands.CompletePath(path) +func (*Attach) CompletePath(arg string) []string { + return commands.CompletePath(arg) } func (a Attach) Execute(args []string) error { @@ -52,6 +52,9 @@ func (a Attach) Execute(args []string) error { } return a.readCommand() default: + if a.Args != "" { + return errors.New("only a single path is supported") + } return a.addPath(a.Path) } } @@ -186,7 +189,7 @@ func (a Attach) openMenu() error { } func (a Attach) readCommand() error { - cmd := exec.Command("sh", "-c", a.Path) + cmd := exec.Command("sh", "-c", a.Path+" "+a.Args) data, err := cmd.Output() if err != nil { |