feat main: Add version command
Adds a version command that can have the Kontemplate git hash added to it at build time by using the Go linker's -X flag.
This commit is contained in:
		
							parent
							
								
									9b2d102bbf
								
							
						
					
					
						commit
						d93bc51e86
					
				
					 1 changed files with 17 additions and 0 deletions
				
			
		
							
								
								
									
										17
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								main.go
									
										
									
									
									
								
							| 
						 | 
					@ -11,6 +11,10 @@ import (
 | 
				
			||||||
	"gopkg.in/alecthomas/kingpin.v2"
 | 
						"gopkg.in/alecthomas/kingpin.v2"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const version string = "1.0"
 | 
				
			||||||
 | 
					// This variable will be initialised by the Go linker during the builder
 | 
				
			||||||
 | 
					var gitHash string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type KubeCtlError struct {
 | 
					type KubeCtlError struct {
 | 
				
			||||||
	meep.AllTraits
 | 
						meep.AllTraits
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -38,6 +42,8 @@ var (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	create     = app.Command("create", "Template resources and pass to 'kubectl create'")
 | 
						create     = app.Command("create", "Template resources and pass to 'kubectl create'")
 | 
				
			||||||
	createFile = create.Arg("file", "Cluster configuration file to use").Required().String()
 | 
						createFile = create.Arg("file", "Cluster configuration file to use").Required().String()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						versionCmd = app.Command("version", "Show kontemplate version")
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
| 
						 | 
					@ -58,6 +64,17 @@ func main() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case create.FullCommand():
 | 
						case create.FullCommand():
 | 
				
			||||||
		createCommand()
 | 
							createCommand()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case versionCmd.FullCommand():
 | 
				
			||||||
 | 
							versionCommand()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func versionCommand() {
 | 
				
			||||||
 | 
						if gitHash == "" {
 | 
				
			||||||
 | 
							fmt.Printf("Kontemplate version %s (git commit unknown)\n", version)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							fmt.Printf("Kontemplate version %s (git commit: %s)\n", version, gitHash)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue