-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathget.go
More file actions
58 lines (51 loc) · 1.68 KB
/
get.go
File metadata and controls
58 lines (51 loc) · 1.68 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Copyright © 2022 AssemblyAI support@assemblyai.com
*/
package cmd
import (
"errors"
S "github.com/AssemblyAI/assemblyai-cli/schemas"
U "github.com/AssemblyAI/assemblyai-cli/utils"
"github.com/spf13/cobra"
)
var getCmd = &cobra.Command{
Use: "get [transcription_id]",
Short: "Get a transcription",
Long: `After submitting a file for transcription, you can fetch it by passing its ID.`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
printErrorProps := S.PrintErrorProps{
Error: errors.New("No transcription ID provided."),
Message: "You must provide a transcription ID.",
}
U.PrintError(printErrorProps)
return
}
id := args[0]
U.Token = U.GetStoredToken()
if U.Token == "" {
printErrorProps := S.PrintErrorProps{
Error: errors.New("No token found."),
Message: "Please start by running \033[1m\033[34massemblyai config [token]\033[0m",
}
U.PrintError(printErrorProps)
return
}
if flags.Csv != "" && !flags.Poll {
printErrorProps := S.PrintErrorProps{
Error: errors.New("CSV output is only supported with polling"),
Message: "CSV output is only supported with polling.",
}
U.PrintError(printErrorProps)
return
}
U.PollTranscription(id, flags)
},
}
func init() {
rootCmd.AddCommand(getCmd)
getCmd.PersistentFlags().BoolVarP(&flags.Poll, "poll", "p", true, "The CLI will poll the transcription until it's complete.")
getCmd.PersistentFlags().BoolVarP(&flags.Json, "json", "j", false, "If true, the CLI will output the JSON.")
getCmd.PersistentFlags().StringVar(&flags.Csv, "csv", "", "Specify the filename to save the transcript result onto a .CSV file extension")
}