@@ -15,26 +15,38 @@ import (
1515func RunTorrentPause () * cobra.Command {
1616 var (
1717 pauseAll bool
18- names bool
1918 hashes []string
2019 )
2120
2221 var command = & cobra.Command {
2322 Use : "pause" ,
2423 Short : "Pause specified torrent(s)" ,
25- Long : `Pauses torrents indicated by hash, name or a prefix of either. Whitespace indicates next prefix unless argument is surrounded by quotes` ,
24+ Long : `Pause the torrent(s) indicated by the supplied hash(es), or pause every torrent with --all.` ,
25+ Example : ` qbt torrent pause --all
26+ qbt torrent pause HASH1 HASH2
27+ qbt torrent pause --hashes HASH1,HASH2` ,
2628 }
2729
2830 command .Flags ().BoolVar (& pauseAll , "all" , false , "Pauses all torrents" )
2931 command .Flags ().StringSliceVar (& hashes , "hashes" , []string {}, "Add hashes as comma separated list" )
30- command .Flags ().BoolVar (& names , "names" , false , "Provided arguments will be read as torrent names" )
3132
3233 command .RunE = func (cmd * cobra.Command , args []string ) error {
33- if len (hashes ) > 0 {
34+ // Treat positional arguments as hashes too, so `qbt torrent pause HASH` works
35+ // alongside the --hashes flag.
36+ hashes = append (hashes , args ... )
37+
38+ if pauseAll {
39+ hashes = []string {"all" }
40+ } else {
41+ if len (hashes ) == 0 {
42+ return errors .New ("no torrents specified: provide hash(es) as arguments or with --hashes, or use --all" )
43+ }
44+
3445 if err := utils .ValidateHash (hashes ); err != nil {
3546 return errors .Wrap (err , "invalid hashes supplied" )
3647 }
3748 }
49+
3850 config .InitConfig ()
3951
4052 qbtSettings := qbittorrent.Config {
@@ -54,19 +66,9 @@ func RunTorrentPause() *cobra.Command {
5466 return errors .Wrap (err , "could not login to qbit" )
5567 }
5668
57- if pauseAll {
58- hashes = []string {"all" }
59- }
60-
61- if len (hashes ) == 0 {
62- log .Printf ("No torrents found to pause with provided hashes. Use --all to pause all torrents." )
63- return nil
64- }
65-
66- err := batchRequests (hashes , func (start , end int ) error {
69+ if err := batchRequests (hashes , func (start , end int ) error {
6770 return qb .PauseCtx (ctx , hashes [start :end ])
68- })
69- if err != nil {
71+ }); err != nil {
7072 return errors .Wrap (err , "could not pause torrents" )
7173 }
7274
0 commit comments