diff --git a/README.md b/README.md index 7f49e72..01074d8 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,12 @@ $ pg-schema-diff plan --dsn "postgres://postgres:postgres@localhost:5432/postgre # Install ## CLI ```bash -go install github.com/stripe/pg-schema-diff/cmd/pg-schema-diff +go install github.com/stripe/pg-schema-diff/cmd/pg-schema-diff@latest ``` ## Library ```bash -go get -u github.com/stripe/pg-schema-diff +go get -u github.com/stripe/pg-schema-diff@latest ``` # Using CLI ## 1. Apply schema to fresh database diff --git a/cmd/pg-schema-diff/main.go b/cmd/pg-schema-diff/main.go index 1e92303..7fa0213 100644 --- a/cmd/pg-schema-diff/main.go +++ b/cmd/pg-schema-diff/main.go @@ -15,6 +15,7 @@ var rootCmd = &cobra.Command{ func init() { rootCmd.AddCommand(buildPlanCmd()) rootCmd.AddCommand(buildApplyCmd()) + rootCmd.AddCommand(buildVersionCmd()) } func main() { diff --git a/cmd/pg-schema-diff/version_cmd.go b/cmd/pg-schema-diff/version_cmd.go new file mode 100644 index 0000000..d3b56b1 --- /dev/null +++ b/cmd/pg-schema-diff/version_cmd.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "runtime/debug" + + "github.com/spf13/cobra" +) + +func buildVersionCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "version", + Short: "Get the version of pg-schema-diff", + } + cmd.RunE = func(_ *cobra.Command, _ []string) error { + buildInfo, ok := debug.ReadBuildInfo() + if !ok { + return fmt.Errorf("build information not available") + } + fmt.Printf("version=%s\n", buildInfo.Main.Version) + + return nil + } + return cmd +}