Skip to content

Commit f1f99c3

Browse files
Merge pull request #2 from interlynk-io/feature/add-version
add version support for binary
2 parents a00b2a7 + 6e95995 commit f1f99c3

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
# Dependency directories (remove the comment below to include it)
1515
vendor/
1616
build/
17+
18+
version.txt

cmd/root.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ produce a calculated score that represents a level of “quality”
1818
when using an SBOM. The sbomqs is intended to help customers make
1919
an assessment of a SBOM acceptance risk based on their personal risk tolerance.
2020
`,
21-
// Uncomment the following line if your bare application
22-
// has an action associated with it:
23-
// Run: func(cmd *cobra.Command, args []string) { },
2421
}
2522

2623
// Execute adds all child commands to the root command and sets flags appropriately.
@@ -33,13 +30,5 @@ func Execute() {
3330
}
3431

3532
func init() {
36-
// Here you will define your flags and configuration settings.
37-
// Cobra supports persistent flags, which, if defined here,
38-
// will be global for your application.
39-
40-
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.sbomqs.yaml)")
41-
42-
// Cobra also supports local flags, which will only run
43-
// when this action is called directly.
4433
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
4534
}

cmd/version.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2023 Interlynk.io
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cmd
16+
17+
import (
18+
_ "embed"
19+
"fmt"
20+
21+
"github.com/spf13/cobra"
22+
)
23+
24+
//go:generate bash version.sh
25+
//go:embed version.txt
26+
var version string
27+
28+
func init() {
29+
rootCmd.AddCommand(versionCmd)
30+
}
31+
32+
var versionCmd = &cobra.Command{
33+
Use: "version",
34+
Short: "Print the version number of sbomqs",
35+
Run: func(cmd *cobra.Command, args []string) {
36+
fmt.Printf("sbomqs version %s", version)
37+
},
38+
}

cmd/version.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
git describe --tags --abbrev=0 > version.txt

main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
/*
2-
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
1+
// Copyright 2023 Interlynk.io
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
314

4-
*/
515
package main
616

717
import "github.com/interlynk-io/sbomqs/cmd"

0 commit comments

Comments
 (0)