Transmission BitTorrent client completions (#2319)

* Added completer for transmission-cli

* Added completer for transmission-edit

* Added completer for transmission-show

* Added completer for transmission-create

* Added completer for transmission-daemon

* Added completer for transmission-remote

* Addressed code review
	- Refatored transmission.ActionIds to take []string instead of cobra command
	- Fixed typos of "magnet"
	- Removed unneccary batching of ActionFiles and ActionDirectories
	- Removed no-op call to style.ForKeyword
	- Removed shared action for `.Chdir("/")`
	- Renamed ActionFilter to ActionFilters
	- Removed micro-optimization that avoided append(...)
	- Fixed multiword completion in transmission-edit
This commit is contained in:
aftix 2024-04-02 10:00:13 -05:00 committed by GitHub
parent 14253df5c6
commit f4ecee8c3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 621 additions and 0 deletions

View File

@ -0,0 +1,56 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/transmission"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "transmission-cli [flags] torrent-file",
Short: "A fast and easy BitTorrent client",
Long: "https://transmissionbt.com/",
Run: func(cmd *cobra.Command, args []string) {},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().BoolP("blocklist", "b", false, "Enable peer blocklists")
rootCmd.Flags().StringP("config-dir", "g", "", "Directory to look for configuratinon files in")
rootCmd.Flags().IntP("downlimit", "d", 0, "Set the maximum download speed in KB/s")
rootCmd.Flags().StringP("download-dir", "w", "", "Where to save downloaded data")
rootCmd.Flags().BoolP("encryption-preferred", "ep", false, "Prefer encrypted peer connections")
rootCmd.Flags().BoolP("encryption-required", "er", false, "Encrypt all peer connections")
rootCmd.Flags().BoolP("encryption-tolerated", "et", false, "Prefer unencrypted peer connections")
rootCmd.Flags().StringP("finish", "f", "", "Set a script to run when the torrent finishes")
rootCmd.Flags().BoolP("help", "h", false, "Prints a short usage summary")
rootCmd.Flags().BoolP("no-blocklist", "B", false, "Disable peer blocklists")
rootCmd.Flags().BoolP("no-downlimit", "D", true, "Don't limit the download speed")
rootCmd.Flags().BoolP("no-portmap", "M", true, "Disable portmapping")
rootCmd.Flags().BoolP("no-uplimit", "U", true, "Don't limit the upload speed")
rootCmd.Flags().IntP("port", "p", 51413, "Set the port to listen for incoming peers")
rootCmd.Flags().BoolP("portmap", "m", false, "Enable port mapping via NAT-PMP or UPnP")
rootCmd.Flags().String("tos", "", "Use a ToS or DSCP name or value from 0-255 to set the peer socket service type")
rootCmd.Flags().IntP("uplimit", "u", 0, "Set the maximum upload speed in KB/s")
rootCmd.Flags().BoolP("verify", "v", true, "Verify the torrent's downloaded data")
rootCmd.Flags().BoolP("version", "V", false, "Show version number and exit")
rootCmd.MarkFlagsMutuallyExclusive("blocklist", "no-blocklist")
rootCmd.MarkFlagsMutuallyExclusive("downlimit", "no-downlimit")
rootCmd.MarkFlagsMutuallyExclusive("encryption-required", "encryption-preferred", "encryption-tolerated")
rootCmd.MarkFlagsMutuallyExclusive("portmap", "no-portmap")
rootCmd.MarkFlagsMutuallyExclusive("uplimit", "no-uplimit")
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"config-dir": carapace.ActionDirectories().Chdir("/"),
"download-dir": carapace.ActionDirectories().Chdir("/"),
"finish": carapace.ActionFiles().Chdir("/"),
"tos": transmission.ActionTOS(),
})
carapace.Gen(rootCmd).PositionalCompletion(carapace.ActionFiles(".torrent", ".magnet"))
}

View File

@ -0,0 +1,7 @@
package main
import "github.com/carapace-sh/carapace-bin/completers/transmission-cli_completer/cmd"
func main() {
cmd.Execute()
}

View File

@ -0,0 +1,42 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "transmission-create [flags] PATH",
Short: "A command-line utility to create .torrent files",
Long: "https://transmissionbt.com/",
Run: func(cmd *cobra.Command, args []string) {},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().Bool("anonymize", false, "Omit the optional \"created by\" and \"created date\" keys")
rootCmd.Flags().StringArrayP("comment", "c", nil, "Add a comment to the torrent file")
rootCmd.Flags().BoolP("help", "h", false, "Show a short help page and exit")
rootCmd.Flags().StringP("outfile", "o", "", "Name of output torrent file")
rootCmd.Flags().IntP("piecesize", "s", 0, "Set the size of the torrent pieces in KiB")
rootCmd.Flags().BoolP("private", "p", false, "Flag the torrent as intended for use on private trackers")
rootCmd.Flags().StringP("source", "r", "", "Set the torrent's source for private trackers")
rootCmd.Flags().StringArrayP("tracker", "t", nil, "Add a tracker's announce URL to the torrent")
rootCmd.Flags().BoolP("version", "V", false, "Show version number and exit")
rootCmd.Flags().StringArrayP("webseed", "w", nil, "Add a webseed URL")
rootCmd.MarkFlagsMutuallyExclusive("source", "tracker")
rootCmd.MarkFlagsOneRequired("source", "tracker")
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"outfile": carapace.ActionFiles(".torrent"),
})
carapace.Gen(rootCmd).PositionalCompletion(
carapace.ActionFiles(),
)
}

View File

@ -0,0 +1,7 @@
package main
import "github.com/carapace-sh/carapace-bin/completers/transmission-create_completer/cmd"
func main() {
cmd.Execute()
}

View File

@ -0,0 +1,87 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/net"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "transmission-daemon [flags]",
Short: "A daemon-based BitTorrent client",
Long: "https://transmissionbt.com/",
Run: func(cmd *cobra.Command, args []string) {},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().StringSliceP("allowed", "a", []string{"127.0.0.1", "::1"}, "Allow RPC access to a comma-delimited whiteliste of IP addresses")
rootCmd.Flags().BoolP("auth", "t", false, "Require clients to authenticate themselves")
rootCmd.Flags().StringP("bind-address-ipv4", "i", "0.0.0.0", "Listen for IPv4 connections on a specific address")
rootCmd.Flags().StringP("bind-address-ipv6", "I", "::/0", "Listen for IPv6 connections on a specific address")
rootCmd.Flags().BoolP("blocklist", "b", false, "Enable peer blocklists")
rootCmd.Flags().StringP("config-dir", "g", "", "Directory to look for configuratinon files in")
rootCmd.Flags().BoolP("dht", "o", false, "Enable distributed hash table")
rootCmd.Flags().StringP("download-dir", "w", "", "Where to save downloaded data")
rootCmd.Flags().BoolP("dump", "d", false, "Dump transmission-daemon's settings to stderr")
rootCmd.Flags().BoolP("encryption-preferred", "ep", false, "Prefer encrypted peer connections")
rootCmd.Flags().BoolP("encryption-required", "er", false, "Encrypt all peer connections")
rootCmd.Flags().BoolP("encryption-tolerated", "et", false, "Prefer unencrypted peer connections")
rootCmd.Flags().BoolP("foreground", "f", false, "Run in the foreground and print errors to stderr")
rootCmd.Flags().StringS("watch", "c", "", "Directory to watch for new .torrent files to be added")
rootCmd.Flags().Float64S("global-seedratio", "gsr", 0, "All torrents, unless overriden by a per-torrent setting, should seed until this ratio")
rootCmd.Flags().BoolP("help", "h", false, "Prints a short usage summary")
rootCmd.Flags().String("incomplete-dir", "", "When adding new torrents, store their contents in directory until torrent is done")
rootCmd.Flags().Bool("log-debug", false, "Show error, info, and debug messages")
rootCmd.Flags().Bool("log-error", false, "Show error messages")
rootCmd.Flags().Bool("log-info", false, "Show error and info messages")
rootCmd.Flags().StringP("logfile", "e", "", "Where to send log output")
rootCmd.Flags().BoolP("no-auth", "T", false, "Don't require authentication from clients")
rootCmd.Flags().BoolP("no-blocklist", "B", false, "Disable peer blocklists")
rootCmd.Flags().BoolP("no-dht", "O", false, "Disable distributed hash table")
rootCmd.Flags().BoolP("no-global-seedratio", "GSR", false, "All torrents, unless overriden by a per-torrent setting, should seed regardless of ratio")
rootCmd.Flags().Bool("no-incomplete-dir", false, "Don't store incomplete torrents in a different directory")
rootCmd.Flags().BoolP("no-portmap", "M", true, "Disable portmapping")
rootCmd.Flags().Bool("no-utp", false, "Disable uTP for peer connections")
rootCmd.Flags().BoolS("no-watch", "C", false, "Do not watch for new .torrent files")
rootCmd.Flags().StringP("password", "v", "", "Client authentication password")
rootCmd.Flags().Bool("paused", false, "Pause all torrents on startup")
rootCmd.Flags().IntP("peerport", "P", 51413, "Set the port to listen for incoming peers")
rootCmd.Flags().IntP("peerlimit-global", "L", 240, "Overall peer limit")
rootCmd.Flags().IntP("peerlimit-torrent", "l", 60, "Peer limit per torrent")
rootCmd.Flags().StringP("pid-file", "x", "", "Name of the daemon PID file")
rootCmd.Flags().IntP("port", "p", 9091, "Port to open and listen for RPC requests on")
rootCmd.Flags().BoolP("portmap", "m", false, "Enable port mapping via NAT-PMP or UPnP")
rootCmd.Flags().StringP("rpc-bind-address", "r", "0.0.0.0", "Listen for RPC connections on a specific IPv4 or IPv6 address")
rootCmd.Flags().StringP("username", "u", "", "Client authentication username")
rootCmd.Flags().Bool("utp", false, "Enable uTP for peer connections")
rootCmd.Flags().BoolP("version", "V", false, "Show version number and exit")
rootCmd.MarkFlagsMutuallyExclusive("auth", "no-auth")
rootCmd.MarkFlagsMutuallyExclusive("blocklist", "no-blocklist")
rootCmd.MarkFlagsMutuallyExclusive("dht", "no-dht")
rootCmd.MarkFlagsMutuallyExclusive("encryption-required", "encryption-preferred", "encryption-tolerated")
rootCmd.MarkFlagsMutuallyExclusive("global-seedratio", "no-global-seedratio")
rootCmd.MarkFlagsMutuallyExclusive("incomplete-dir", "no-incomplete-dir")
rootCmd.MarkFlagsMutuallyExclusive("log-error", "log-info", "log-debug")
rootCmd.MarkFlagsMutuallyExclusive("portmap", "no-portmap")
rootCmd.MarkFlagsMutuallyExclusive("utp", "no-utp")
rootCmd.MarkFlagsMutuallyExclusive("watch", "no-watch")
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"allowed": net.ActionIpv4Addresses(),
"bind-address-ipv4": net.ActionIpv4Addresses(),
"bind-address-ipv6": carapace.ActionValues("::0/0", "fe80::/10"),
"config-dir": carapace.ActionDirectories().Chdir("/"),
"download-dir": carapace.ActionDirectories().Chdir("/"),
"logfile": carapace.ActionFiles().Chdir("/"),
"pid-file": carapace.ActionFiles().Chdir("/"),
"rpc-bind-address": net.ActionIpv4Addresses(),
"watch": carapace.ActionDirectories().Chdir("/"),
})
}

View File

@ -0,0 +1,7 @@
package main
import "github.com/carapace-sh/carapace-bin/completers/transmission-daemon_completer/cmd"
func main() {
cmd.Execute()
}

View File

@ -0,0 +1,32 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "transmission-edit [flags] torrentfile...",
Short: "A command-line utility to modify .torrent files' announce URLs",
Long: "https://transmissionbt.com/",
Run: func(cmd *cobra.Command, args []string) {},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().StringP("add", "a", "", "Add an announce URL to the torrent's announce-list")
rootCmd.Flags().StringP("delete", "d", "", "Remove an announce URL from the torrent's announce-list")
rootCmd.Flags().BoolP("help", "h", false, "Show a short help page and exit")
rootCmd.Flags().StringSliceP("replace", "r", nil, "Substring search-and-replace inside a torrent's announce-list URLs")
rootCmd.Flags().StringP("source", "s", "", "Sets the source tag within a torrent")
rootCmd.Flags().BoolP("version", "V", false, "Show version number and exit")
rootCmd.Flag("replace").Nargs = 2
carapace.Gen(rootCmd).PositionalAnyCompletion(carapace.ActionFiles(".torrent"))
}

View File

@ -0,0 +1,7 @@
package main
import "github.com/carapace-sh/carapace-bin/completers/transmission-edit_completer/cmd"
func main() {
cmd.Execute()
}

View File

@ -0,0 +1,212 @@
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/carapace-sh/carapace/pkg/style"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "transmission-remote [host[:port]] [flags]",
Short: "A remote control utility for transmission-daemon and transmission",
Long: "https://transmissionbt.com/",
Run: func(cmd *cobra.Command, args []string) {},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().StringArrayP("add", "a", nil, "Add torrents")
rootCmd.Flags().BoolP("alt-speed", "as", false, "Use the alternate limits")
rootCmd.Flags().StringSlice("alt-speed-days", nil, "Set the numbers days on which to enable the alternate speed scheduler (e.g. \"2\", \"2,4-6\")")
rootCmd.Flags().IntP("alt-speed-downlimit", "asd", 0, "Limit the alternate download speed in KB/s")
rootCmd.Flags().BoolP("alt-speed-scheduler", "asc", false, "Use the alternate scheduled on/off times")
rootCmd.Flags().Int("alt-speed-time-begin", 0, "Time to start using the alt speed limits (hhmm)")
rootCmd.Flags().Int("alt-speed-time-end", 0, "Time to stop using the alt speed limits (hhmm)")
rootCmd.Flags().IntP("alt-speed-uplimit", "asu", 0, "Limit the alternate upload speed in KB/s")
rootCmd.Flags().StringP("auth", "n", "", "Set the username:password for authentication")
rootCmd.Flags().BoolP("authenv", "ne", false, "Use the TR_AUTH environment variable for authentication")
rootCmd.Flags().BoolP("bandwidth-high", "Bh", false, "Give this torrent first chance at available bandwith")
rootCmd.Flags().BoolP("bandwidth-low", "Bl", false, "Give this torrent the bandwith leftover after high and normal priority torrents")
rootCmd.Flags().BoolP("bandwidth-normal", "Bn", false, "Give this torrent the bandwidth leftover after high priority torrents")
rootCmd.Flags().Bool("blocklist-update", false, "Update blocklist from URL in remote client's settings")
rootCmd.Flags().IntP("cache", "e", 0, "Set the session's maximum memory cache size in MiB")
rootCmd.Flags().BoolP("debug", "b", false, "Enable debugging mode")
rootCmd.Flags().BoolP("dht", "o", false, "Enable distributed hash table")
rootCmd.Flags().IntP("downlimit", "d", 0, "Limit the maximum download speed in KB/s")
rootCmd.Flags().StringP("download-dir", "w", "", "Where to save downloaded data")
rootCmd.Flags().BoolP("encryption-preferred", "ep", false, "Prefer encrypted peer connections")
rootCmd.Flags().BoolP("encryption-required", "er", false, "Encrypt all peer connections")
rootCmd.Flags().BoolP("encryption-tolerated", "et", false, "Prefer unencrypted peer connections")
rootCmd.Flags().Bool("exit", false, "Initiate a shutdown")
rootCmd.Flags().BoolP("files", "f", false, "Get a file list for the current torrent(s)")
rootCmd.Flags().StringArrayP("filter", "F", []string{}, "Filter selected torrents (may be specified more than once)")
rootCmd.Flags().String("find", "", "Tell transmission where to look for the current torrent's data")
rootCmd.Flags().StringSliceP("get", "g", nil, "Mark file(s) for download. (e.g. \"all\", \"1\", \"1,3-5\")")
rootCmd.Flags().Float64S("global-seedratio", "gsr", 0, "All torrents, unless overriden by a per-torrent setting, should seed until this ratio")
rootCmd.Flags().BoolP("help", "h", false, "Prints a short usage summary")
rootCmd.Flags().BoolP("honor-session", "hl", false, "Make the current torrent(s) honor the session limits")
rootCmd.Flags().IntP("peers", "pr", 0, "Set the maximum number of peers globally, or on current torrents if selected")
rootCmd.Flags().String("incomplete-dir", "c", "When adding new torrents, store their contents in directory until torrent is done")
rootCmd.Flags().BoolP("info", "i", false, "Show details of current torrent(s)")
rootCmd.Flags().BoolP("info-files", "if", false, "List the specified torrent's files")
rootCmd.Flags().BoolP("info-peers", "ip", false, "List the specified torrent's peers")
rootCmd.Flags().BoolP("info-pieces", "ic", false, "List the specified torrent's pieces")
rootCmd.Flags().BoolP("info-trackers", "it", false, "List the specified torrent's trackers")
rootCmd.Flags().BoolP("json", "j", false, "Return the RPC response as JSON")
rootCmd.Flags().StringArrayP("labels", "L", nil, "Set the specified torrent's labels")
rootCmd.Flags().BoolP("lds", "y", false, "Enable local peer discovery (LPD)")
rootCmd.Flags().BoolP("list", "l", false, "List all torrents")
rootCmd.Flags().String("move", "", "Move the current torrent's data to the specified directory")
rootCmd.Flags().StringP("netrc", "N", "", "Use the specified netrc file for authentication")
rootCmd.Flags().BoolP("no-alt-speed", "AS", false, "Don't use the alternate limits")
rootCmd.Flags().BoolP("no-alt-speed-scheduler", "ASC", false, "Don't use the alternate scheduled on/off times")
rootCmd.Flags().BoolP("no-dht", "O", false, "Disable distributed hash table")
rootCmd.Flags().BoolP("no-downlimit", "D", false, "Don't limit the maximum download speed")
rootCmd.Flags().StringSliceP("no-get", "G", nil, "Marke file(s) for not downloading (e.g. \"all\", \"1\", \"1,3-5\")")
rootCmd.Flags().BoolS("no-global-seedratio", "GSR", false, "All torrents, unless overriden by a per-torrent setting, should seed regardless of ratio")
rootCmd.Flags().BoolP("no-honor-session", "HL", false, "Make the current torrent(s) not honor the session limits")
rootCmd.Flags().BoolP("no-incomplete-dir", "C", false, "Don't store incomplete torrents in a different directory")
rootCmd.Flags().BoolP("no-lds", "Y", false, "Disable local peer discovery (LPD)")
rootCmd.Flags().BoolP("no-pex", "X", false, "Disable peer exchange (PEX)")
rootCmd.Flags().BoolP("no-portmap", "M", true, "Disable portmapping")
rootCmd.Flags().BoolP("no-seedratio", "SR", false, "Let the current torrent(s) seed regardless of ratio")
rootCmd.Flags().Bool("no-torrent-done-script", false, "Don't run any script when a torrent finishes")
rootCmd.Flags().Bool("no-trash-torrent", false, "Don't delete torrent files after adding")
rootCmd.Flags().BoolP("no-uplimit", "U", true, "Don't limit the upload speed")
rootCmd.Flags().Bool("no-utp", false, "Disable uTP for peer connections")
rootCmd.Flags().String("path", "", "Provide original path for the rename command")
rootCmd.Flags().BoolP("peer-info", "pi", false, "List the current torrent's connected peers")
rootCmd.Flags().BoolP("pex", "x", false, "Enable peer exchange (PEX)")
rootCmd.Flags().BoolP("print-ids", "ids", false, "Print a list of the specified torrent's ids in a format suitable for -t")
rootCmd.Flags().StringSliceP("priority-high", "ph", nil, "Try to download the specified file(s) first (e.g. \"all\", \"1\", \"1,3-5\")")
rootCmd.Flags().StringSliceP("priority-low", "pl", nil, "Try to download the specified file(s) last (e.g. \"all\", \"1\", \"1,3-5\")")
rootCmd.Flags().StringSliceP("priority-normal", "pn", nil, "Try to download the specified file(s) normally (e.g. \"all\", \"1\", \"1,3-5\")")
rootCmd.Flags().IntP("port", "p", 51413, "Set the port to listen for incoming peers")
rootCmd.Flags().BoolP("portmap", "m", false, "Enable port mapping via NAT-PMP or UPnP")
rootCmd.Flags().Bool("reannounce", false, "Reannounce the current torrent(s)")
rootCmd.Flags().BoolP("remove", "r", false, "Remove the current torrent(s) without deleting their downloaded data")
rootCmd.Flags().BoolP("remove-and-delete", "rad", false, "Remove the current torrent(s) and delete their downloaded data")
rootCmd.Flags().String("rename", "", "Rename files or root folder of a torrent")
rootCmd.Flags().Float64P("seedratio", "sr", 0, "Let the current torrent(s) seed until a specific ratio")
rootCmd.Flags().Bool("no-start-paused", false, "Start added torrents unpaused")
rootCmd.Flags().BoolP("seedratio-default", "srd", false, "Let the current torrent(s) seed until the global seedratio")
rootCmd.Flags().BoolP("session-info", "si", false, "List sessions from the server")
rootCmd.Flags().BoolP("session-stats", "st", false, "List statistical information from the server")
rootCmd.Flags().BoolP("start", "s", false, "Start the current torrent(s)")
rootCmd.Flags().Bool("start-paused", false, "Start added torrents paused")
rootCmd.Flags().BoolP("stop", "S", false, "Stop the current torrent(s) from downloading or seeding")
rootCmd.Flags().StringSliceP("torrent", "t", nil, "Set the current torrent(s) for use by subsequent options")
rootCmd.Flags().String("torrent-done-script", "", "Specify a file to run each time a torrent finishes")
rootCmd.Flags().Bool("trash-torrent", false, "Delete torrent files after adding")
rootCmd.Flags().IntP("uplimit", "u", 0, "Set the maximum upload speed in KB/s")
rootCmd.Flags().Bool("utp", false, "Enable uTP for peer connections")
rootCmd.Flags().BoolP("verify", "v", true, "Verify the torrent's downloaded data")
rootCmd.Flags().BoolP("version", "V", false, "Show version number and exit")
rootCmd.MarkFlagsRequiredTogether("path", "rename")
rootCmd.MarkFlagsMutuallyExclusive("alt-speed", "no-alt-speed")
rootCmd.MarkFlagsMutuallyExclusive("alt-speed-scheduler", "no-alt-speed-scheduler")
rootCmd.MarkFlagsMutuallyExclusive("auth", "authenv", "netrc")
rootCmd.MarkFlagsMutuallyExclusive("bandwidth-high", "bandwidth-low", "bandwidth-normal")
rootCmd.MarkFlagsMutuallyExclusive("dht", "no-dht")
rootCmd.MarkFlagsMutuallyExclusive("downlimit", "no-downlimit")
rootCmd.MarkFlagsMutuallyExclusive("encryption-required", "encryption-preferred", "encryption-tolerated")
rootCmd.MarkFlagsMutuallyExclusive("global-seedratio", "no-global-seedratio")
rootCmd.MarkFlagsMutuallyExclusive("incomplete-dir", "no-incomplete-dir")
rootCmd.MarkFlagsMutuallyExclusive("info", "info-files", "info-peers", "info-pieces", "info-trackers")
rootCmd.MarkFlagsMutuallyExclusive("lds", "no-lds")
rootCmd.MarkFlagsMutuallyExclusive("pex", "no-pex")
rootCmd.MarkFlagsMutuallyExclusive("portmap", "no-portmap")
rootCmd.MarkFlagsMutuallyExclusive("priority-high", "priority-low", "priority-normal")
rootCmd.MarkFlagsMutuallyExclusive("seedratio", "no-seedratio", "seedratio-default")
rootCmd.MarkFlagsMutuallyExclusive(
"honor-session", "no-honor-session",
"move",
"peers",
"reannounce",
"remove", "remove-and-delete",
"rename",
"start",
"stop",
"uplimit", "no-uplimit",
)
rootCmd.MarkFlagsMutuallyExclusive("start-paused", "no-start-paused")
rootCmd.MarkFlagsMutuallyExclusive("torrent-done-script", "no-torrent-done-script")
rootCmd.MarkFlagsMutuallyExclusive("trash-torrent", "no-trash-torrent")
rootCmd.MarkFlagsMutuallyExclusive("utp", "no-utp")
markFlagsNoCurrentTorret(
"add",
"alt-speed",
"alt-speed-days",
"alt-speed-downlimit",
"alt-speed-scheduler",
"alt-speed-time-begin",
"alt-speed-time-end",
"alt-speed-uplimit",
"blocklist-update",
"cache",
"dht",
"download-dir",
"exit",
"encryption-preferred",
"encryption-required",
"encryption-tolerated",
"global-seedratio",
"pex",
"incomplete-dir",
"lds",
"no-alt-speed",
"no-alt-speed-scheduler",
"no-dht",
"no-global-seedratio",
"no-incomplete-dir",
"no-lds",
"no-pex",
"no-portmap",
"no-torrent-done-script",
"no-trash-torrent",
"no-utp",
"port",
"portmap",
"session-info",
"session-stats",
"torrent-done-script",
"trash-torrent",
"utp",
"verify",
"version",
)
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"add": carapace.ActionFiles(".torrent", ".magnet"),
"filter": transmission.ActionFilters(),
"find": carapace.ActionDirectories().Chdir("/"),
"get": carapace.ActionValuesDescribed("all", "Get all files").StyleF(style.ForKeyword),
"incomplete-dir": carapace.ActionDirectories().Chdir("/"),
"move": carapace.ActionDirectories().Chdir("/"),
"netrc": carapace.ActionFiles(),
"no-get": carapace.ActionValuesDescribed("all", "Get all files").StyleF(style.ForKeyword),
"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())
}
// Marks the flags so they're exclusive with --torrent
func markFlagsNoCurrentTorret(flags ...string) {
for _, flag := range flags {
rootCmd.MarkFlagsMutuallyExclusive(flag, "torrent")
}
}

View File

@ -0,0 +1,7 @@
package main
import "github.com/carapace-sh/carapace-bin/completers/transmission-remote_completer/cmd"
func main() {
cmd.Execute()
}

View File

@ -0,0 +1,28 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "transmission-show [flags] torrentfile",
Short: "A command-line utility to show .torrent file metadata",
Long: "https://transmissionbt.com/",
Run: func(cmd *cobra.Command, args []string) {},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().BoolP("help", "h", false, "Show a short help page and exit")
rootCmd.Flags().BoolP("magnet", "m", false, "Show a magnet link for the specified .torrent file")
rootCmd.Flags().BoolP("scrape", "s", false, "Ask the torrent's trackers how many peers are in the torrent's swarm")
rootCmd.Flags().BoolP("version", "V", false, "Show version number and exit")
carapace.Gen(rootCmd).PositionalCompletion(carapace.ActionFiles(".torrent"))
}

View File

@ -0,0 +1,7 @@
package main
import "github.com/carapace-sh/carapace-bin/completers/transmission-show_completer/cmd"
func main() {
cmd.Execute()
}

View File

@ -0,0 +1,84 @@
package transmission
import (
"strings"
"github.com/carapace-sh/carapace"
)
// ActionFilters completes filters
func ActionFilters() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
actionFilterConditions(),
actionFilterConditions().Prefix("~"),
carapace.ActionValuesDescribed("~", "Negate the following filter"),
).ToA()
})
}
// Available filters for torrents
func actionFilterConditions() carapace.Action {
return carapace.Batch(
carapace.ActionValuesDescribed(
"i", "currently idle",
"u", "currently uploading",
"d", "currently downloading",
"w", "torrent has unwanted files",
),
carapace.ActionMultiPartsN(":", 2, func(c carapace.Context) carapace.Action {
if len(c.Parts) == 0 {
return carapace.ActionValuesDescribed(
"n:", "torrent name includes the string following :",
"l:", "torrent has the label following :",
"r:", "torrent has an upload ratio greater than or equal to the ratio following :",
)
}
return carapace.ActionValues()
}),
).ToA()
}
// ActionIds completes torrent IDs, accounting for previously applied filters
func ActionIds(filters []string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.Batch(
actionIdsValues(),
getIdsDescribed(filters),
).ToA()
})
}
func actionIdsValues() carapace.Action {
return carapace.ActionValuesDescribed(
"all", "select all filtered torrents",
"active", "select active filtered torrents",
)
}
// Call into transmission-remote to the list of ids resulting from the filters
func getIdsDescribed(rawFilters []string) carapace.Action {
filters := make([]string, 0)
for _, f := range rawFilters {
filters = append(filters, "-F", f)
}
filters = append(filters, "-l")
// Can't use --print-ids flag to get ids since it doesn't give descriptions and doesn't always return numeric ids
return carapace.ActionExecCommand("transmission-remote", filters...)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
idsDescribed := make([]string, 0)
// The first and last lines are always additional information, not torrents
for _, line := range lines[1 : len(lines)-2] {
fields := strings.Fields(line)
if len(fields) <= 9 {
idsDescribed = append(idsDescribed, fields[0], "")
} else {
idsDescribed = append(idsDescribed, fields[0], strings.Join(fields[9:], " "))
}
}
return carapace.ActionValuesDescribed(idsDescribed...)
})
}

View File

@ -0,0 +1,38 @@
package transmission
import (
"github.com/carapace-sh/carapace"
)
// ActionTOS Completes a name for ToS values
func ActionTOS() carapace.Action {
return carapace.ActionValues(
"af11",
"af12",
"af13",
"af21",
"af22",
"af23",
"af31",
"af32",
"af33",
"af41",
"af42",
"af43",
"cs0",
"cs1",
"cs2",
"cs3",
"cs4",
"cs5",
"cs6",
"cs7",
"ef",
"le",
"default",
"lowcost",
"lowdelay",
"reliability",
"throughput",
)
}