Skip to content

Commit

Permalink
Create simple version command (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
bplunkett-stripe committed Sep 11, 2024
1 parent 5fe8259 commit bc41f09
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/pg-schema-diff/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var rootCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(buildPlanCmd())
rootCmd.AddCommand(buildApplyCmd())
rootCmd.AddCommand(buildVersionCmd())
}

func main() {
Expand Down
25 changes: 25 additions & 0 deletions cmd/pg-schema-diff/version_cmd.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit bc41f09

Please sign in to comment.