Refactor; update README

This commit is contained in:
Jeffrey Serio 2024-07-26 03:14:41 -05:00
parent 841120a26b
commit 51ef14ac54
4 changed files with 73 additions and 41 deletions

View File

@ -1,34 +0,0 @@
# go-torrent-helper
This is a helper program to add and remove torrents from a transmission-daemon instance.
To use, make sure `TRANSMISSION_RPC_URL` is exported in the shell:
``` bash
export TRANSMISSION_RPC_URL=10.0.0.42
```
Install with Go:
``` bash
go install git.hyperreal.coffee/go-torrent-helper@latest
```
## Usage
``` bash
# Add Fedora torrents
go-torrent-helper add -distro fedora -relver 38
# Remove NixOS torrents
go-torrent-helper remove -distro nixos
# Add Rocky Linux torrents
go-torrent-helper add -distro rocky -relver 9.2
# Remove older Rocky Linux torrents
go-torrent-helper remove -distro rocky -relver 8.1
# If not -relver flag is supplied for the remove subcommand, remove all torrents for given distro
go-torrent-helper remove -distro debian
```

31
README.org Normal file
View File

@ -0,0 +1,31 @@
* go-torrent-helper
This is a helper program to add and remove torrents from a transmission-daemon instance.
** Installation
#+BEGIN_SRC shell
go install codeberg.org/hyperreal/go-torrent-helper@latest
#+END_SRC
** Usage
#+BEGIN_SRC shell
export TX_RPC_URL=localhost
export TX_RPC_USER="cat"
export TX_RPC_PASS="meow"
export TX_RPC_PORT="9091"
export TX_RPC_USE_HTTPS="True"
#+END_SRC
*** Add torrents
#+BEGIN_SRC shell
go-torrent-helper add -distro fedora -relver 50
go-torrent-helper add -distro nixos -relver *
go-torrent-helper add -distro almalinux -relver 12.4
#+END_SRC
*** Remove torrents
#+BEGIN_SRC shell
go-torrent-helper remove -distro almalinux -relver 12.4
go-torrent-helper remove -distro nixos -relver *
go-torrent-helper remove -distro fedora -relver 50
#+END_SRC

View File

@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"os"
"strconv"
"codeberg.org/hyperreal/go-torrent-helper/almalinux"
"codeberg.org/hyperreal/go-torrent-helper/debian"
@ -101,7 +102,24 @@ func (l *ListCmd) Init(args []string) error {
}
func (a *AddCmd) Run(d Distro) error {
client, err := transmissionrpc.New(os.Getenv("TRANSMISSION_RPC_URL"), os.Getenv("TRANSMISSION_RPC_USER"), os.Getenv("TRANSMISSION_RPC_PASSWD"), nil)
txRpcUrl := os.Getenv("TX_RPC_URL")
txRpcUser := os.Getenv("TX_RPC_USER")
txRpcPass := os.Getenv("TX_RPC_PASS")
txRpcPort, err := strconv.ParseUint(os.Getenv("TX_RPC_PORT"), 10, 16)
if err != nil {
return err
}
txRpcUseHTTPS, err := strconv.ParseBool(os.Getenv("TX_RPC_USE_HTTPS"))
if err != nil {
return err
}
client, err := transmissionrpc.New(txRpcUrl, txRpcUser, txRpcPass,
&transmissionrpc.AdvancedConfig{
HTTPS: txRpcUseHTTPS,
Port: uint16(txRpcPort),
},
)
if err != nil {
return err
}
@ -114,7 +132,24 @@ func (a *AddCmd) Run(d Distro) error {
}
func (r *RemoveCmd) Run(d Distro) error {
client, err := transmissionrpc.New(os.Getenv("TRANSMISSION_RPC_URL"), os.Getenv("TRANSMISSION_RPC_USER"), os.Getenv("TRANSMISSION_RPC_PASSWD"), nil)
txRpcUrl := os.Getenv("TX_RPC_URL")
txRpcUser := os.Getenv("TX_RPC_USER")
txRpcPass := os.Getenv("TX_RPC_PASS")
txRpcPort, err := strconv.ParseUint(os.Getenv("TX_RPC_PORT"), 10, 16)
if err != nil {
return err
}
txRpcUseHTTPS, err := strconv.ParseBool(os.Getenv("TX_RPC_USE_HTTPS"))
if err != nil {
return err
}
client, err := transmissionrpc.New(txRpcUrl, txRpcUser, txRpcPass,
&transmissionrpc.AdvancedConfig{
HTTPS: txRpcUseHTTPS,
Port: uint16(txRpcPort),
},
)
if err != nil {
return err
}
@ -158,7 +193,7 @@ type Runner interface {
func Root(args []string) error {
if len(args) < 1 {
return errors.New("You must pass a sub-command")
return errors.New("you must pass a sub-command")
}
cmds := []Runner{
@ -179,7 +214,7 @@ func Root(args []string) error {
var distro, relver string
if len(os.Args[2:]) == 0 {
return fmt.Errorf("See -h for usage options")
return fmt.Errorf("see -h for usage options")
}
cmd.Init(os.Args[2:])
@ -187,7 +222,7 @@ func Root(args []string) error {
if len(os.Args[4:]) == 0 && subcmd == "remove" {
relver = "*"
} else if len(os.Args[4:]) == 0 && subcmd == "add" {
return fmt.Errorf("Please enter a release version")
return fmt.Errorf("please enter a release version")
} else {
relver = os.Args[5]
}
@ -244,10 +279,10 @@ func Root(args []string) error {
return cmd.Run(t)
default:
return fmt.Errorf("Unknown distro: %s", distro)
return fmt.Errorf("unknown distro: %s", distro)
}
}
}
return fmt.Errorf("Unknown subcommand: %s", subcmd)
return fmt.Errorf("unknown subcommand: %s", subcmd)
}

BIN
go-torrent-helper Executable file

Binary file not shown.