commands

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2022 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeleteCmd = &cobra.Command{
	Use:                   "delete <delete hash>",
	Short:                 "Delete image from Imgur by Delete Hash",
	Args:                  cobra.MinimumNArgs(1),
	DisableFlagsInUseLine: true,
	Example:               "imgur delete DSdXVa0PZwsUJgB",
	RunE: func(cmd *cobra.Command, args []string) error {
		client := utils.CreateClient()

		_, _, err := client.DeleteImageUnAuthed(args[0])
		if err != nil {
			log.Fatal("Error delete image: " + err.Error())
		}

		fmt.Println("Deleted image!")

		notify := notificator.New(notificator.Options{
			AppName: "Imgur",
		})

		notify.Push("Deleted!", "", "", notificator.UR_NORMAL)

		return nil
	},
}
View Source
var UploadCmd = &cobra.Command{
	Use:                   "upload <path to file or url>",
	Short:                 "Upload image to Imgur",
	Args:                  cobra.MinimumNArgs(1),
	DisableFlagsInUseLine: true,
	Example:               "imgur upload Pictures/Screenshot.png",
	RunE: func(cmd *cobra.Command, args []string) error {
		client := utils.CreateClient()

		f, err := os.Stat(args[0])

		if err == nil {
			if f.IsDir() {
				log.Fatalf("%s is dir!", args[0])
			}

			data, _, err := client.UploadImageFromFile(args[0], "")
			if err != nil {
				log.Fatal("Error upload image to Imgur: " + err.Error())
			}

			printLink(data)
		} else {
			data, _, err := client.UploadImageFromURL(args[0], "")
			if err != nil {
				log.Fatal("Error upload image to Imgur: " + err.Error())
			}

			printLink(data)
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL