tdl/cmd/up.go

44 lines
1.2 KiB
Go
Raw Normal View History

2023-03-29 18:20:23 +08:00
package cmd
import (
"context"
"github.com/gotd/td/telegram"
2023-08-20 21:00:06 +08:00
"github.com/spf13/cobra"
2023-03-29 18:20:23 +08:00
"github.com/iyear/tdl/app/up"
"github.com/iyear/tdl/core/logctx"
"github.com/iyear/tdl/core/storage"
2023-03-29 18:20:23 +08:00
)
func NewUpload() *cobra.Command {
var opts up.Options
cmd := &cobra.Command{
Use: "upload",
Aliases: []string{"up"},
Short: "Upload anything to Telegram",
2024-06-23 17:10:48 +08:00
GroupID: groupTools.ID,
2023-03-29 18:20:23 +08:00
RunE: func(cmd *cobra.Command, args []string) error {
return tRun(cmd.Context(), func(ctx context.Context, c *telegram.Client, kvd storage.Storage) error {
return up.Run(logctx.Named(ctx, "up"), c, kvd, opts)
})
2023-03-29 18:20:23 +08:00
},
}
const (
_chat = "chat"
path = "path"
)
cmd.Flags().StringVarP(&opts.Chat, _chat, "c", "", "chat id or domain, and empty means 'Saved Messages'")
cmd.Flags().StringSliceVarP(&opts.Paths, path, "p", []string{}, "dirs or files")
cmd.Flags().StringSliceVarP(&opts.Excludes, "excludes", "e", []string{}, "exclude the specified file extensions")
2023-05-21 13:51:30 +08:00
cmd.Flags().BoolVar(&opts.Remove, "rm", false, "remove the uploaded files after uploading")
cmd.Flags().BoolVar(&opts.Photo, "photo", false, "upload the image as a photo instead of a file")
2023-03-29 18:20:23 +08:00
// completion and validation
_ = cmd.MarkFlagRequired(path)
2023-03-29 18:20:23 +08:00
return cmd
}