Skip to content

Commit

Permalink
Merge pull request #4 from socialviolation/feature/latestlean
Browse files Browse the repository at this point in the history
Adding SHORT to latest, rename lean to SHORT
  • Loading branch information
0xNFANZ authored May 17, 2024
2 parents 00cc882 + 65bd244 commit fc25385
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
16 changes: 9 additions & 7 deletions cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
changelog bool
autoIncrement bool
autoIncrementFlag bool
lean bool
short bool
)

var latestTagCmd = &cobra.Command{
Expand All @@ -32,7 +32,7 @@ var latestTagCmd = &cobra.Command{
return
}

tag.Print(os.Stdout, noColour)
tag.Print(os.Stdout, noColour, short)
},
}

Expand All @@ -44,7 +44,7 @@ var nextTagCommand = &cobra.Command{
tag, err := cv.Version(time.Now())
CheckIfError(err)

if lean {
if short {
fmt.Println(tag)
} else {
fmt.Printf("Will create tag '%s' (hash %s)\n", colour.LightGreen.Sprintf(tag), hash)
Expand All @@ -67,7 +67,7 @@ var listTagCmd = &cobra.Command{
}

for _, tag := range tags {
tag.Print(os.Stdout, noColour)
tag.Print(os.Stdout, noColour, short)
}
},
}
Expand Down Expand Up @@ -97,7 +97,7 @@ var tagCmd = &cobra.Command{
Tag: tag,
})
CheckIfError(err)
if lean {
if short {
fmt.Println(tag)
} else {
fmt.Printf("Created tag '%s' (hash %s)\n", tag, commit)
Expand Down Expand Up @@ -171,16 +171,18 @@ func init() {
listTagCmd.Flags().BoolVar(&noColour, "no-colour", false, "Disable colour output")
listTagCmd.Flags().BoolVar(&changelog, "changeLog", true, "Include changelog")
listTagCmd.Flags().IntVarP(&limit, "limit", "l", 5, "Limit number of results (based on hashes)")
listTagCmd.Flags().BoolVarP(&short, "short", "s", false, "Output the version number only")

rootCmd.AddCommand(latestTagCmd)
latestTagCmd.Flags().BoolVar(&noColour, "no-colour", false, "Disable colour output")
latestTagCmd.Flags().BoolVar(&changelog, "changeLog", true, "Include changelog")
latestTagCmd.Flags().BoolVarP(&short, "short", "s", false, "Output the version number only")

rootCmd.AddCommand(tagCmd)
tagCmd.Flags().BoolVarP(&push, "push", "p", false, "Push tag after create")
tagCmd.Flags().BoolVarP(&autoIncrementFlag, "auto-increment", "i", false, "Adds an auto-incremented modifier, based off previous latest release")
tagCmd.Flags().StringVar(&hash, "hash", "", "Override Hash")
tagCmd.Flags().BoolVarP(&lean, "lean", "l", false, "Output the version number only")
tagCmd.Flags().BoolVarP(&short, "short", "s", false, "Output the version number only")

rootCmd.AddCommand(retagCmd)
retagCmd.Flags().BoolVarP(&push, "push", "p", false, "Push tag after update")
Expand All @@ -192,6 +194,6 @@ func init() {

rootCmd.AddCommand(nextTagCommand)
nextTagCommand.Flags().StringVar(&hash, "hash", "HEAD", "Override Hash")
nextTagCommand.Flags().BoolVarP(&lean, "lean", "l", false, "Output the version number only")
nextTagCommand.Flags().BoolVarP(&short, "short", "s", false, "Output the version number only")
nextTagCommand.Flags().BoolVarP(&autoIncrementFlag, "auto-increment", "i", false, "Adds an auto-incremented modifier, based off previous latest release")
}
9 changes: 8 additions & 1 deletion ver/calvertaggroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type CalVerTagGroup struct {
Commit *object.Commit
Refs []*plumbing.Reference
Latest bool
LatestTag string
ChangeLog []*object.Commit
}

Expand All @@ -41,10 +42,16 @@ func (cvt *CalVerTagGroup) printTags() string {
return result
}

func (cvt *CalVerTagGroup) Print(w io.Writer, noColour bool) {
func (cvt *CalVerTagGroup) Print(w io.Writer, noColour bool, lean bool) {
if noColour {
colour.Disable()
}

if lean {
_, _ = w.Write([]byte(cvt.LatestTag + "\n"))
return
}

headline := colour.Yellow.Sprint(cvt.Hash) + " - "
if cvt.Latest {
headline += colour.HEX("#af5fff").Sprint(cvt.printTags())
Expand Down
1 change: 1 addition & 0 deletions ver/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func ListTags(reg *regexp.Regexp, limit int, changelog bool) ([]*CalVerTagGroup,
for i, tag := range tags {
if i == 0 {
tagMap[tag].Latest = true
tagMap[tag].LatestTag = tag
}
if i >= limit {
break
Expand Down

0 comments on commit fc25385

Please sign in to comment.