github.com/developest/gtm-core@v1.0.4-0.20220111132249-cc80a3372c3f/command/rewrite.go (about) 1 package command 2 3 import ( 4 "bufio" 5 "github.com/DEVELOPEST/gtm-core/project" 6 "github.com/DEVELOPEST/gtm-core/scm" 7 "io" 8 "log" 9 "os" 10 "strings" 11 12 "github.com/mitchellh/cli" 13 ) 14 15 // CommitCmd struct contain methods for commit command 16 type RewriteCmd struct { 17 UI cli.Ui 18 } 19 20 // NewCommit returns new CommitCmd struct 21 func NewRewrite() (cli.Command, error) { 22 return RewriteCmd{}, nil 23 } 24 25 // Help returns help for commit command 26 func (c RewriteCmd) Help() string { 27 helpText := ` 28 Usage: gtm rewrite [options] 29 30 Automatically called on git history rewrite. Do not use manually!. 31 ` 32 return strings.TrimSpace(helpText) 33 } 34 35 // Run executes commit commands with args 36 func (c RewriteCmd) Run(args []string) int { 37 38 reader := bufio.NewReader(os.Stdin) 39 for { 40 input, err := reader.ReadString('\n') 41 if err != nil { 42 if err != io.EOF { 43 log.Fatal(err) 44 } 45 break 46 } 47 input = strings.TrimSpace(input) 48 hashes := strings.Split(input, " ") 49 50 if len(hashes) < 2 { 51 log.Fatal("Unexpected input!") 52 } 53 54 err = scm.RewriteNote(hashes[0], hashes[1], project.NoteNameSpace) 55 56 if err != nil { 57 log.Println(err) 58 } 59 } 60 61 return 0 62 } 63 64 // Synopsis return help for commit command 65 func (c RewriteCmd) Synopsis() string { 66 return "Update git notes on history rewrite" 67 }