github.com/tilt-dev/wat@v0.0.2-0.20180626175338-9349b638e250/cli/analytics/cli.go (about) 1 package analytics 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 8 "github.com/spf13/cobra" 9 10 "github.com/windmilleng/wat/cli/dirs" 11 ) 12 13 func analyticsStatus(_ *cobra.Command, args []string) error { 14 //fmt.Println("[ for more info: https://windmill.engineering/analytics ]") 15 choice, err := OptStatus() 16 if err != nil { 17 return err 18 } 19 fmt.Printf("current collection strategy: %v\n", choice) 20 21 return nil 22 } 23 24 func analyticsOpt(_ *cobra.Command, args []string) (outerErr error) { 25 defer func() { 26 if outerErr == nil { 27 return 28 } 29 fmt.Printf("choice can be one of {%v, %v}\n", Choices[OptIn], Choices[OptOut]) 30 }() 31 if len(args) == 0 { 32 fmt.Printf("choice can be one of {%v, %v}\n", Choices[OptIn], Choices[OptOut]) 33 return fmt.Errorf("no choice given; pass it as first arg: <tool> analytics opt <choice>") 34 } 35 choiceStr := args[0] 36 err := SetOptStr(choiceStr) 37 if err != nil { 38 return err 39 } 40 d, err := dirs.UseWindmillDir() 41 if err != nil { 42 return err 43 } 44 fmt.Fprintf(os.Stderr, "wrote user collection strategy %q to file %v\n", choiceStr, filepath.Join(d.Root(), choiceFile)) 45 return nil 46 } 47 48 const choiceFile = "analytics/user/choice.txt" 49 50 func initCLI() (*cobra.Command, error) { 51 analytics := &cobra.Command{ 52 Use: "analytics", 53 Short: "info and status about windmill analytics", 54 RunE: analyticsStatus, 55 } 56 57 opt := &cobra.Command{ 58 Use: "opt", 59 Short: "opt-in or -out to windmill analytics collection/upload", 60 RunE: analyticsOpt, 61 } 62 analytics.AddCommand(opt) 63 64 return analytics, nil 65 }