Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version only flag to show command #17

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading