Skip to content

Commit

Permalink
transmission: added port completion
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Apr 2, 2024
1 parent 9ff97c6 commit 6197382
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions completers/transmission-cli_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/net"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/transmission"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -50,6 +51,7 @@ func init() {
"config-dir": carapace.ActionDirectories().Chdir("/"),
"download-dir": carapace.ActionDirectories().Chdir("/"),
"finish": carapace.ActionFiles().Chdir("/"),
"port": net.ActionPorts(),
"tos": transmission.ActionTOS(),
})
carapace.Gen(rootCmd).PositionalCompletion(carapace.ActionFiles(".torrent", ".magnet"))
Expand Down
1 change: 1 addition & 0 deletions completers/transmission-daemon_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func init() {
"download-dir": carapace.ActionDirectories().Chdir("/"),
"logfile": carapace.ActionFiles().Chdir("/"),
"pid-file": carapace.ActionFiles().Chdir("/"),
"port": net.ActionPorts(),
"rpc-bind-address": net.ActionIpv4Addresses(),
"watch": carapace.ActionDirectories().Chdir("/"),
})
Expand Down
12 changes: 11 additions & 1 deletion completers/transmission-remote_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,23 @@ func init() {
"move": carapace.ActionDirectories().Chdir("/"),
"netrc": carapace.ActionFiles(),
"no-get": carapace.ActionValuesDescribed("all", "Get all files").StyleF(style.ForKeyword),
"port": net.ActionKnownPorts(),
"torrent": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
filters, _ := rootCmd.Flags().GetStringArray("filter")
return transmission.ActionIds(filters)
}),
"torrent-done-script": carapace.ActionDirectories().Chdir("/"),
})
carapace.Gen(rootCmd).PositionalCompletion(net.ActionHosts())
carapace.Gen(rootCmd).PositionalCompletion(
carapace.ActionMultiPartsN(":", 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return net.ActionHosts()
default:
return net.ActionKnownPorts()
}
}),
)
}

// Marks the flags so they're exclusive with --torrent
Expand Down

0 comments on commit 6197382

Please sign in to comment.