Merge branch '19092-upload-crunchstat_summary-to-pypi'
[arvados-dev.git] / cmd / art / root.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package main
6
7 import (
8         "fmt"
9         "os"
10
11         "github.com/spf13/cobra"
12         "github.com/spf13/viper"
13 )
14
15 var (
16         conf config
17 )
18
19 type config struct {
20         Endpoint string `json:"endpoint"` // https://dev-dev.arvados.org
21         Apikey   string `json:"apikey"`   // abcde...
22 }
23
24 func loadConfig() config {
25         var c config
26
27         Viper := viper.New()
28         Viper.SetEnvPrefix("redmine") // will be uppercased automatically
29         Viper.BindEnv("endpoint")
30         Viper.BindEnv("apikey")
31
32         c.Endpoint = Viper.GetString("endpoint")
33         c.Apikey = Viper.GetString("apikey")
34
35         return c
36 }
37
38 func init() {
39         rootCmd.PersistentFlags().StringP("output", "o", "", "Output format. Empty for human-readable, 'json' or 'json-line'")
40         rootCmd.PersistentFlags().BoolP("help", "h", false, "Print help")
41         rootCmd.PersistentFlags().BoolP("debug", "d", false, "Print debug output")
42 }
43
44 var rootCmd = &cobra.Command{
45         Use:   "art",
46         Short: "art - Arvados Release Tool",
47         Long: `
48 art (Arvados Release Tool) supports the Arvados development process
49
50 https://git.arvados.org/arvados-dev.git/cmd/art`,
51         PreRunE: func(cmd *cobra.Command, args []string) error {
52                 return nil
53         },
54 }
55
56 func Execute() {
57         conf = loadConfig()
58         if err := rootCmd.Execute(); err != nil {
59                 fmt.Fprintln(os.Stderr, err)
60                 os.Exit(1)
61         }
62 }