github.com/developest/gtm-enhanced@v1.0.4-0.20220111132249-cc80a3372c3f/command/uninit.go (about) 1 // Copyright 2016 Michael Schenk. All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package command 6 7 import ( 8 "flag" 9 "strings" 10 11 "github.com/DEVELOPEST/gtm-core/project" 12 "github.com/mitchellh/cli" 13 ) 14 15 // UninitCmd contains methods for uninit command 16 type UninitCmd struct { 17 UI cli.Ui 18 } 19 20 // NewUninit returns new UninitCmd struct 21 func NewUninit() (cli.Command, error) { 22 return UninitCmd{}, nil 23 } 24 25 // Help returns help for uninit command 26 func (c UninitCmd) Help() string { 27 helpText := ` 28 Usage: gtm uninit [options] 29 30 Turn off time tracking for git repository (does not remove committed time data). 31 32 Options: 33 34 -yes Turn off without asking for confirmation. 35 ` 36 return strings.TrimSpace(helpText) 37 } 38 39 // Run executes uninit command with args 40 func (c UninitCmd) Run(args []string) int { 41 var yes bool 42 cmdFlags := flag.NewFlagSet("uninit", flag.ContinueOnError) 43 cmdFlags.BoolVar(&yes, "yes", false, "") 44 cmdFlags.Usage = func() { c.UI.Output(c.Help()) } 45 if err := cmdFlags.Parse(args); err != nil { 46 return 1 47 } 48 49 confirm := yes 50 if !confirm { 51 var response string 52 response, err := c.UI.Ask("Remove GTM tracking for the current git repository (y/n)?") 53 if err != nil { 54 c.UI.Error(err.Error()) 55 return 1 56 } 57 confirm = strings.TrimSpace(strings.ToLower(response)) == "y" 58 } 59 60 if confirm { 61 var ( 62 m string 63 err error 64 ) 65 if m, err = project.Uninitialize(); err != nil { 66 c.UI.Error(err.Error()) 67 return 1 68 } 69 c.UI.Output(m) 70 } 71 return 0 72 } 73 74 // Synopsis returns help for uninit command 75 func (c UninitCmd) Synopsis() string { 76 return "Turn off time tracking for git repository" 77 }