Skip to content

Commit

Permalink
feat: Add command to print version
Browse files Browse the repository at this point in the history
Restore Makefile and update .goreleaser.yaml

Restored Makefile to previous version and then updated
.goreleaser.yaml to use the ldflag with the tag and short hash.

Also ran make docgen to update documentation.

Actually run make docgen this time
  • Loading branch information
hooksie1 authored and mikhailswift committed Feb 22, 2022
1 parent 674d9c5 commit 9c95b23
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ builds:
- "-s -w"
- "-extldflags=-zrelro"
- "-extldflags=-znow"
- "-extldflags -w -X 'github.com/testifysec/witness/cmd/witness/cmd.Version={{.Tag}}-{{.ShortCommit}}'"
env:
- "CGO_ENABLED=0"
- "GO111MODULE=on"
Expand Down
1 change: 1 addition & 0 deletions cmd/witness/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func New() *cobra.Command {
cmd.AddCommand(VerifyCmd())
cmd.AddCommand(RunCmd())
cmd.AddCommand(CompletionCmd())
cmd.AddCommand(versionCmd())
cobra.OnInitialize(func() { preRoot(cmd, ro) })
return cmd
}
Expand Down
38 changes: 38 additions & 0 deletions cmd/witness/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022 The Witness Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var Version = "dev"

// versionCmd represents the version command
func versionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Prints out the witness version",
Long: `Prints out the witness version`,
SilenceErrors: true,
SilenceUsage: true,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("witness %s\n", Version)
},
}
}
1 change: 1 addition & 0 deletions docs/witness.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Collect and verify attestations about your build environments
* [witness run](witness_run.md) - Runs the provided command and records attestations about the execution
* [witness sign](witness_sign.md) - Signs a file
* [witness verify](witness_verify.md) - Verifies a witness policy
* [witness version](witness_version.md) - Prints out the witness version

29 changes: 29 additions & 0 deletions docs/witness_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## witness version

Prints out the witness version

### Synopsis

Prints out the witness version

```
witness version [flags]
```

### Options

```
-h, --help help for version
```

### Options inherited from parent commands

```
-c, --config string Path to the witness config file (default ".witness.yaml")
-l, --log-level string Level of logging to output (debug, info, warn, error) (default "info")
```

### SEE ALSO

* [witness](witness.md) - Collect and verify attestations about your build environments

0 comments on commit 9c95b23

Please sign in to comment.