Skip to content

Commit

Permalink
Merge pull request #2 from interlynk-io/feature/add-version
Browse files Browse the repository at this point in the history
add version support for binary
  • Loading branch information
riteshnoronha authored Jan 31, 2023
2 parents a00b2a7 + 6e95995 commit f1f99c3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
# Dependency directories (remove the comment below to include it)
vendor/
build/

version.txt
11 changes: 0 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ produce a calculated score that represents a level of “quality”
when using an SBOM. The sbomqs is intended to help customers make
an assessment of a SBOM acceptance risk based on their personal risk tolerance.
`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}

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

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.sbomqs.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
38 changes: 38 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 Interlynk.io
//
// 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 (
_ "embed"
"fmt"

"github.com/spf13/cobra"
)

//go:generate bash version.sh
//go:embed version.txt
var version string

func init() {
rootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of sbomqs",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("sbomqs version %s", version)
},
}
2 changes: 2 additions & 0 deletions cmd/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
git describe --tags --abbrev=0 > version.txt
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
// Copyright 2023 Interlynk.io
//
// 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 main

import "github.com/interlynk-io/sbomqs/cmd"
Expand Down

0 comments on commit f1f99c3

Please sign in to comment.