Skip to content

Commit

Permalink
feat: add version only flag to show command (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
corang authored Oct 16, 2024
1 parent 2870a16 commit efb7e61
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
)

var boolOutput bool
var checkBoolOutput bool

// checkCmd represents the check command
var checkCmd = &cobra.Command{
Expand All @@ -50,14 +50,14 @@ var checkCmd = &cobra.Command{
return err
}
if tagExists {
if boolOutput {
if checkBoolOutput {
fmt.Println("false")
} else {
fmt.Printf("Version %s is already tagged\n", versionAndFlavor)
return errors.New("no release necessary")
}
} else {
if boolOutput {
if checkBoolOutput {
fmt.Println("true")
} else {
fmt.Printf("Version %s is not tagged\n", versionAndFlavor)
Expand All @@ -68,6 +68,6 @@ var checkCmd = &cobra.Command{
}

func init() {
checkCmd.Flags().BoolVarP(&boolOutput, "boolean", "b", false, "Switch the output string to a true/false based on if a release is necessary. True if a release is necessary, false if not.")
checkCmd.Flags().BoolVarP(&checkBoolOutput, "boolean", "b", false, "Switch the output string to a true/false based on if a release is necessary. True if a release is necessary, false if not.")
rootCmd.AddCommand(checkCmd)
}
9 changes: 8 additions & 1 deletion src/cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/spf13/cobra"
)

var showVersionOnly bool

// showCmd represents the show command
var showCmd = &cobra.Command{
Use: "show flavor",
Expand All @@ -40,12 +42,17 @@ var showCmd = &cobra.Command{

rootCmd.SilenceUsage = true

fmt.Printf("%s-%s\n", currentFlavor.Version, currentFlavor.Name)
if showVersionOnly {
fmt.Printf("%s\n", currentFlavor.Version)
} else {
fmt.Printf("%s-%s\n", currentFlavor.Version, currentFlavor.Name)
}

return nil
},
}

func init() {
rootCmd.AddCommand(showCmd)
showCmd.Flags().BoolVarP(&showVersionOnly, "version-only", "v", false, "Show only the version without flavor appended")
}
7 changes: 7 additions & 0 deletions src/test/e2e/00_show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ func TestShowCommand(t *testing.T) {

require.Equal(t, "1.0.0-uds.0-base\n", stdout)
}

func TestShowCommandVersionFlag(t *testing.T) {
stdout, stderr, err := e2e.UDSReleaserDir("src/test", "show", "base", "--version-only")
require.NoError(t, err, stdout, stderr)

require.Equal(t, "1.0.0-uds.0\n", stdout)
}
3 changes: 0 additions & 3 deletions tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

includes:
- test: tasks/tests.yaml

tasks:
# build tasks
- name: build-all
Expand Down

0 comments on commit efb7e61

Please sign in to comment.