Skip to content

Commit

Permalink
add some aliases for command with pre-defined args or flags
Browse files Browse the repository at this point in the history
  • Loading branch information
sagan committed Aug 29, 2023
1 parent 4991288 commit 1b897bf
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/qbittorrent/qbittorrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ func (qbclient *Client) GetTorrentContents(infoHash string) ([]client.TorrentCon
for _, qbTorrentContent := range qbTorrentContents {
torrentContents = append(torrentContents, client.TorrentContentFile{
Index: qbTorrentContent.Index,
Path: strings.ReplaceAll(qbTorrentContent.Name, "\\", "/"),
Path: strings.ReplaceAll(qbTorrentContent.Name, `\`, "/"),
Size: qbTorrentContent.Size,
Ignored: qbTorrentContent.Priority == 0,
Complete: qbTorrentContent.Is_seed,
Expand Down
11 changes: 11 additions & 0 deletions cmd/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func init() {
command.Flags().StringVarP(&defaultSite, "site", "", "", "Set default site of torrents")
command.Flags().StringVarP(&addTags, "add-tags", "", "", "Add tags to added torrent (comma-separated)")
cmd.RootCmd.AddCommand(command)
command2.Flags().AddFlagSet(command.Flags())
cmd.RootCmd.AddCommand(command2)
}

func add(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -145,3 +147,12 @@ func add(cmd *cobra.Command, args []string) error {
}
return nil
}

var command2 = &cobra.Command{
Use: "add2 [args]",
Short: `Alias of "add --add-category-auto [args]"`,
RunE: func(cmd *cobra.Command, args []string) error {
addCategoryAuto = true
return command.RunE(cmd, args)
},
}
13 changes: 13 additions & 0 deletions cmd/addlocal/addlocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func init() {
command.Flags().StringVarP(&rename, "rename", "", "", "Rename added torrent (for dev/test only)")
command.Flags().StringVarP(&addTags, "add-tags", "", "", "Set tags of added torrent (comma-separated)")
cmd.RootCmd.AddCommand(command)
command2.Flags().AddFlagSet(command.Flags())
cmd.RootCmd.AddCommand(command2)
}

func addlocal(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -155,3 +157,14 @@ func addlocal(cmd *cobra.Command, args []string) error {
}
return nil
}

var command2 = &cobra.Command{
Use: "addlocal2 {client}",
Short: `Alias of "addlocal --add-category-auto --delete-added {client} *.torrent"`,
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: func(cmd *cobra.Command, args []string) error {
addCategoryAuto = true
args = append(args, "*.torrent")
return command.RunE(cmd, args)
},
}
16 changes: 15 additions & 1 deletion cmd/batchdl/batchdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func init() {
cmd.AddEnumFlagP(command, &sortFlag, "sort", "", common.SiteTorrentSortFlag)
cmd.AddEnumFlagP(command, &orderFlag, "order", "", common.OrderFlag)
cmd.RootCmd.AddCommand(command)
command2.Flags().AddFlagSet(command.Flags())
cmd.RootCmd.AddCommand(command2)
}

func batchdl(command *cobra.Command, args []string) error {
Expand All @@ -121,7 +123,6 @@ func batchdl(command *cobra.Command, args []string) error {
sortFlag = "time"
orderFlag = "desc"
onePage = true
startPage = "0"
}
var includesList [][]string
var excludesList []string
Expand Down Expand Up @@ -428,3 +429,16 @@ mainloop:
doneHandle()
return nil
}

var command2 = &cobra.Command{
Use: "batchdl2 {client} [args]",
Short: `Alias of "batchdl --action=add --add-client={client} --add-category-auto [args]"`,
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
RunE: func(cmd *cobra.Command, args []string) error {
action = "add"
addClient = args[0]
addCategoryAuto = true
args = args[1:]
return command.RunE(cmd, args)
},
}
2 changes: 1 addition & 1 deletion cmd/createcategory/createcategory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
)

func init() {
command.Flags().StringVarP(&savePath, "save-path", "", "", "Set the save path of the category. Can use \"none\" to set it back to default empty value")
command.Flags().StringVarP(&savePath, "save-path", "", "", `Set the save path of the category. Can use "none" to set it back to default empty value`)
cmd.RootCmd.AddCommand(command)
}

Expand Down
1 change: 1 addition & 0 deletions cmd/partialdownload/partialdownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Chunk struct {

var command = &cobra.Command{
Use: "partialdownload {client} {infoHash} --chunk-size {size_str} {-a | --chunk-index index}",
Aliases: []string{"partialdl"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "partialdownload"},
Short: "Partially download a (large) torrent in client.",
Long: `Partially download a (large) torrent in client.
Expand Down
4 changes: 2 additions & 2 deletions util/torrentutil/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ func (meta *TorrentMeta) Verify(savePath string, contentPath string, checkHash b
if err == nil {
if meta.SingleFileTorrent {
if fileStats.Name() != meta.Files[0].Path {
log.Warnf("This is single-file torrent. The torrent file on disk \"%s\" has same content with torrent info, "+
log.Warnf(`This is single-file torrent. The torrent file on disk "%s" has same content with torrent info, `+
"but they have DIFFERENT file name. Be careful if you would add this torrent to local client to xseed.",
contentPath)
}
} else {
if fileStats.Name() != meta.RootDir {
log.Warnf("This is multiple-file torrent. The torrent content folder on disk \"%s\" has same contents with torrent info, "+
log.Warnf(`This is multiple-file torrent. The torrent content folder on disk "%s" has same contents with torrent info, `+
"but they have DIFFERENT root folder name. Be careful if you would add this torrent to local client to xseed.",
contentPath)
}
Expand Down

0 comments on commit 1b897bf

Please sign in to comment.