-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.go
40 lines (35 loc) · 976 Bytes
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package version
import (
"fmt"
"os"
"github.com/go-git/go-git/v5/plumbing"
"github.com/pulumi/pulumictl/pkg/gitversion"
"github.com/pulumi/pulumictl/pkg/version"
"github.com/spf13/cobra"
)
func Command() *cobra.Command {
command := &cobra.Command{
Use: "version",
Short: "Get the current version",
Long: `Get the current version of pulumictl`,
RunE: func(cmd *cobra.Command, args []string) error {
v := version.Version
// If we haven't set a version with linker flags, use this tool to get the version
if v == "" {
commitish := "HEAD"
workingDir, err := os.Getwd()
if err != nil {
return fmt.Errorf("error obtaining working directory: %w", err)
}
version, err := gitversion.GetLanguageVersions(workingDir, plumbing.Revision(commitish), true, "")
if err != nil {
return fmt.Errorf("error calculating version: %w", err)
}
v = version.SemVer
}
fmt.Println(v)
return nil
},
}
return command
}