mirror of
https://github.com/chenasraf/tx.git
synced 2026-05-17 17:28:08 +00:00
feat: add version flag
This commit is contained in:
@@ -10,6 +10,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// Version is set by main.go from embedded version.txt
|
||||
Version string
|
||||
|
||||
// Global flags
|
||||
verbose bool
|
||||
dry bool
|
||||
@@ -66,6 +69,7 @@ func initConfig(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately
|
||||
func Execute() {
|
||||
rootCmd.Version = Version
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error:", err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
11
main.go
11
main.go
@@ -1,7 +1,16 @@
|
||||
package main
|
||||
|
||||
import "github.com/chenasraf/tx/internal/cli"
|
||||
import (
|
||||
_ "embed"
|
||||
"strings"
|
||||
|
||||
"github.com/chenasraf/tx/internal/cli"
|
||||
)
|
||||
|
||||
//go:embed version.txt
|
||||
var version string
|
||||
|
||||
func main() {
|
||||
cli.Version = strings.TrimSpace(version)
|
||||
cli.Execute()
|
||||
}
|
||||
|
||||
1
version.txt
Normal file
1
version.txt
Normal file
@@ -0,0 +1 @@
|
||||
1.0.1
|
||||
Reference in New Issue
Block a user