/
translate.go
35 lines (30 loc) · 928 Bytes
/
translate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var phrase string
// translateCmd represents the translate command
var translateCmd = &cobra.Command{
Use: "translate",
Short: "Translates a phrase to a gif",
Long: `Translates phrases to gifs using a weirdness factor.
Uses Giphy API and stores the gif in the folder specified by the --folder flag.`,
Run: func(cmd *cobra.Command, args [] string) {
gif, err := giphyClient.TranslateGif(phrase)
if err != nil {
cmd.PrintErrln( fmt.Sprintf("Error: did not find a gif for your phrase: %s \n %s", phrase, err))
return
}
file, err := downloader.StoreFile(gif.Url, gif.Id)
if err != nil {
cmd.PrintErrln( "Error: could not store gif \n", err)
return
}
fmt.Println(file)
},
}
func init() {
rootCmd.AddCommand(translateCmd)
translateCmd.Flags().StringVarP(&phrase, "phrase", "p", "", "defines phrase to search for in giphy translate")
}