WIP disclaimer
[yt-mango.git] / main.go
blob206d4686b2cbce8c2c71b4c39249d006ef66c839
1 // yt-mango: YT video metadata archiving utility
2 // Copyright (C) 2018 terorie
4 package main
6 import (
7 "github.com/spf13/cobra"
8 "fmt"
9 "os"
10 "github.com/terorie/yt-mango/cmd"
11 "log"
12 "github.com/terorie/yt-mango/api"
13 "github.com/terorie/yt-mango/net"
16 const Version = "v0.1 -- dev"
18 func main() {
19 // All diagnostics (logging) should go to stderr
20 log.SetOutput(os.Stderr)
22 var printVersion bool
23 var forceAPI string
24 var concurrentRequests uint
26 rootCmd := cobra.Command{
27 Use: "yt-mango",
28 Short: "YT-Mango is a scalable video metadata archiver",
29 Long: "YT-Mango is a scalable video metadata archiving utility\n" +
30 "written by terorie for https://the-eye.eu/",
31 PreRun: func(cmd *cobra.Command, args []string) {
32 if printVersion {
33 fmt.Println(Version)
34 os.Exit(0)
37 PersistentPreRun: func(cmd *cobra.Command, args []string) {
38 net.MaxWorkers = uint32(concurrentRequests)
40 switch forceAPI {
41 case "": api.Main = &api.TempAPI
42 case "classic": api.Main = &api.ClassicAPI
43 case "json": api.Main = &api.JsonAPI
44 default:
45 fmt.Fprintln(os.Stderr, "Invalid API specified.\n" +
46 "Valid options are: \"classic\" and \"json\"")
47 os.Exit(1)
52 rootCmd.Flags().BoolVar(&printVersion, "version", false,
53 fmt.Sprintf("Print the version (" + Version +") and exit"))
54 rootCmd.Flags().StringVarP(&forceAPI, "api", "a", "",
55 "Use the specified API for all calls.\n" +
56 "Possible options: \"classic\" and \"json\"")
57 rootCmd.PersistentFlags().UintVarP(&concurrentRequests, "concurrency", "c", 4,
58 "Number of maximum concurrent HTTP requests")
60 rootCmd.AddCommand(&cmd.Channel)
61 rootCmd.AddCommand(&cmd.Video)
63 if err := rootCmd.Execute(); err != nil {
64 fmt.Fprintln(os.Stderr, err)
65 os.Exit(1)