Skip to content

Commit bc41f09

Browse files
Create simple version command (#174)
1 parent 5fe8259 commit bc41f09

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ $ pg-schema-diff plan --dsn "postgres://postgres:postgres@localhost:5432/postgre
9191
# Install
9292
## CLI
9393
```bash
94-
go install github.com/stripe/pg-schema-diff/cmd/pg-schema-diff
94+
go install github.com/stripe/pg-schema-diff/cmd/pg-schema-diff@latest
9595
```
9696

9797
## Library
9898
```bash
99-
go get -u github.com/stripe/pg-schema-diff
99+
go get -u github.com/stripe/pg-schema-diff@latest
100100
```
101101
# Using CLI
102102
## 1. Apply schema to fresh database

cmd/pg-schema-diff/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var rootCmd = &cobra.Command{
1515
func init() {
1616
rootCmd.AddCommand(buildPlanCmd())
1717
rootCmd.AddCommand(buildApplyCmd())
18+
rootCmd.AddCommand(buildVersionCmd())
1819
}
1920

2021
func main() {

cmd/pg-schema-diff/version_cmd.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"runtime/debug"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func buildVersionCmd() *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "version",
13+
Short: "Get the version of pg-schema-diff",
14+
}
15+
cmd.RunE = func(_ *cobra.Command, _ []string) error {
16+
buildInfo, ok := debug.ReadBuildInfo()
17+
if !ok {
18+
return fmt.Errorf("build information not available")
19+
}
20+
fmt.Printf("version=%s\n", buildInfo.Main.Version)
21+
22+
return nil
23+
}
24+
return cmd
25+
}

0 commit comments

Comments
 (0)