commit 2
This commit is contained in:
		
							
								
								
									
										61
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,61 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"flag"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gitea.layla.gg/layla/gsquash/git"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						// Set flags
 | 
				
			||||||
 | 
						flagset := flag.NewFlagSet("git", flag.ExitOnError)
 | 
				
			||||||
 | 
						pull := flagset.Bool("pull", false, "Pull the latest changes from the remote")
 | 
				
			||||||
 | 
						message := flagset.String("m", "", "The commit message")
 | 
				
			||||||
 | 
						version := flagset.Bool("version", false, "Print the version")
 | 
				
			||||||
 | 
						help := flagset.Bool("h", false, "Print the help")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Parse flags
 | 
				
			||||||
 | 
						flagset.Parse(os.Args[1:])
 | 
				
			||||||
 | 
						args := flagset.Args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Print version
 | 
				
			||||||
 | 
						if *version {
 | 
				
			||||||
 | 
							println("gsquash v0.0.1")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Help
 | 
				
			||||||
 | 
						if *help || len(args) == 0 {
 | 
				
			||||||
 | 
							println("Usage: gsquash [options] [message]")
 | 
				
			||||||
 | 
							flagset.PrintDefaults()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Set up git
 | 
				
			||||||
 | 
						g := git.NewGit(&git.NewGitInput{
 | 
				
			||||||
 | 
							Executable: "git",
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Pull
 | 
				
			||||||
 | 
						if *pull {
 | 
				
			||||||
 | 
							err := g.Pull()
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								panic(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						squashInput := git.SquashInput{}
 | 
				
			||||||
 | 
						if message != nil && *message != "" {
 | 
				
			||||||
 | 
							squashInput.Message = message
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Squash
 | 
				
			||||||
 | 
						if len(args) > 0 {
 | 
				
			||||||
 | 
							err := g.Squash(squashInput)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								panic(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user