diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index bf1ffb8..53d8dbb 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -68,5 +68,5 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o build/pizza-${{ matrix.goos }}-${{ matrix.goarch }} + GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w -X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=1.2.3' -X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" -o build/pizza-${{ matrix.goos }}-${{ matrix.goarch }} gh release upload ${{ needs.release.outputs.release-tag }} build/pizza-${{ matrix.goos }}-${{ matrix.goarch }} diff --git a/README.md b/README.md index e0aba3f..75c2ea2 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,15 @@ Available Commands: help Help about any command login Log into the CLI application via GitHub repo-query Ask questions about a GitHub repository + version Displays the build version of the CLI Flags: - -h, --help help for pizza + --beta Shorthand for using the beta OpenSauced API endpoint + ("https://beta.api.opensauced.pizza/v1"). Superceds the + '--endpoint' flag + -e, --endpoint string The API endpoint to send requests to (default + "https://api.opensauced.pizza/v1") + -h, --help help for pizza Use "pizza [command] --help" for more information about a command. ``` diff --git a/cmd/root/root.go b/cmd/root/root.go index 4ad6e77..733bdb9 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -9,6 +9,7 @@ import ( "github.com/open-sauced/pizza-cli/cmd/auth" "github.com/open-sauced/pizza-cli/cmd/bake" repoquery "github.com/open-sauced/pizza-cli/cmd/repo-query" + "github.com/open-sauced/pizza-cli/cmd/version" "github.com/open-sauced/pizza-cli/pkg/api" ) @@ -27,6 +28,7 @@ func NewRootCommand() (*cobra.Command, error) { cmd.AddCommand(bake.NewBakeCommand()) cmd.AddCommand(repoquery.NewRepoQueryCommand()) cmd.AddCommand(auth.NewLoginCommand()) + cmd.AddCommand(version.NewVersionCommand()) return cmd, nil } diff --git a/cmd/version/version.go b/cmd/version/version.go new file mode 100644 index 0000000..1f99c75 --- /dev/null +++ b/cmd/version/version.go @@ -0,0 +1,18 @@ +package version + +import ( + "fmt" + + "github.com/open-sauced/pizza-cli/pkg/utils" + "github.com/spf13/cobra" +) + +func NewVersionCommand() *cobra.Command { + return &cobra.Command{ + Use: "version", + Short: "Displays the build version of the CLI", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("Version: %s\nSha: %s\n", utils.Version, utils.Sha) + }, + } +} diff --git a/pkg/utils/version.go b/pkg/utils/version.go new file mode 100644 index 0000000..fd18874 --- /dev/null +++ b/pkg/utils/version.go @@ -0,0 +1,6 @@ +package utils + +var ( + Version string = "dev" + Sha string = "HEAD" +)