Skip to content

Commit a43243f

Browse files
authored
Merge pull request #53 from clarabennettdev/add-version-flag
feat: add --version flag
2 parents 3b8ee5d + 4e607bd commit a43243f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cmd/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ var rootCmd = &cobra.Command{
8181
},
8282
}
8383

84+
// SetVersionInfo sets the version information for the root command.
85+
func SetVersionInfo(version, buildDate string) {
86+
rootCmd.Version = version
87+
rootCmd.SetVersionTemplate(fmt.Sprintf("nomore403 version %s (built %s)\n", version, buildDate))
88+
}
89+
8490
// Execute adds all child commands to the root command and sets flags appropriately.
8591
// This is called by main.main(). It only needs to happen once to the rootCmd.
8692
func Execute() {

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ package main
44

55
import "github.com/devploit/nomore403/cmd"
66

7+
// Version and BuildDate are set via ldflags at build time.
8+
var (
9+
Version = "dev"
10+
BuildDate = "unknown"
11+
)
12+
713
func main() {
14+
cmd.SetVersionInfo(Version, BuildDate)
815
cmd.Execute()
916
}

0 commit comments

Comments
 (0)