Skip to content

Commit

Permalink
Update usage and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
leosunmo committed Mar 6, 2023
1 parent 46db438 commit e540e98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ Simple Go binary that allows you to get latest Git SHAs/Tags (annotated or light
```
Usage of tagver: [-t] [-b] [-c] [<git dir>]
Default output is very close to "git describe --tags":
If HEAD is not tagged: <tag>-<commits since tag>-<HEAD SHA> (example: v1.0.4-1-5227b593)
If HEAD is tagged: <tag> (example: v1.0.5)
Default output is very close to "git describe --tags" if there's a tag present, otherwise defaults to branch and commit:
If HEAD is not tagged: <branch>-<HEAD SHA> (example: main-63380731)
If HEAD is tagged: <tag>-<HEAD SHA> (example: v1.0.4-63380731)
If HEAD is tagged but has commits after latest tag: <tag>-<commits since tag>-<HEAD SHA> (example: v1.0.4-1-5227b593)
If "-b" or "-c" are provided with "-t", only the tag name will print regardless if it's clean or not.
Print order will be <tag>-<branch>-<SHA>.
If "-b" or "-c" are provided with "-t", it is additive and will include commits since tag if unclean.
The number of commits since tag can be ignored with "-ignore-unclean-tag".
Print order will be <tag>-<branch>[-<commits since tag>]-<SHA>.
Set one or more flags.
-b Return the current branch
-c Return the current commit
-ignore-unclean-tag
Return only tag name even if the latest tag doesn't point to HEAD ("v1.0.4" instead of "v1.0.4-1-89c22b28")
-t Return the latest semver tag (annotated or lightweight Git tag) (default)
Return only tag name even if the latest tag doesn't point to HEAD ("v1.0.4" instead of "v1.0.4-1-5227b593")
-t Return the latest semver tag (annotated or lightweight Git tag)
```

## Output
Default with tag pointing to HEAD:
```
tagver
v1.0.4
v1.0.4-63380731
```
Default with commits after latest tag:
```
Expand All @@ -40,8 +43,14 @@ main-63380731
Default ignoring the fact that there's commits after the latest tag:
```
tagver --ignore-unclean-tag
v1.0.4-5227b593
```
Only display tag, and ignore any commits after the latest tag:
```
tagver -t --ignore-unclean-tag
v1.0.4
```

All options provided (ignores the fact that latest tag doesn't point to HEAD):
```
tagver -t -b -c
Expand Down
16 changes: 9 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ var getDefault bool
var path string

var (
getTag = flag.Bool("t", false, "Return the latest semver tag (annotated or lightweight Git tag) (default)")
getTag = flag.Bool("t", false, "Return the latest semver tag (annotated or lightweight Git tag)")
getBranch = flag.Bool("b", false, "Return the current branch")
getCommit = flag.Bool("c", false, "Return the current commit")
ignoreUncleanTag = flag.Bool("ignore-unclean-tag", false, "Return only tag name even if the latest tag doesn't point to HEAD (\"v1.0.4\" instead of \"v1.0.4-1-89c22b28\")")
ignoreUncleanTag = flag.Bool("ignore-unclean-tag", false, "Return only tag name even if the latest tag doesn't point to HEAD (\"v1.0.4\" instead of \"v1.0.4-1-5227b593\")")
)

// Basic example of how to list tags.
func main() {

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of tagver: [-t] [-b] [-c] [<git dir>]\n\n")
fmt.Fprint(flag.CommandLine.Output(), "Default output is very close to \"git describe --tags\":\n")
fmt.Fprint(flag.CommandLine.Output(), "\tIf HEAD is not tagged: <tag>-<commits since tag>-<HEAD SHA> (example: v1.0.4-1-5227b593)\n")
fmt.Fprint(flag.CommandLine.Output(), "\tIf HEAD is tagged: <tag> (example: v1.0.5)\n\n")
fmt.Fprint(flag.CommandLine.Output(), "If \"-b\" or \"-c\" are provided with \"-t\", only the tag name will print regardless if it's clean or not.\n")
fmt.Fprint(flag.CommandLine.Output(), "Print order will be <tag>-<branch>-<SHA>.\n\n")
fmt.Fprint(flag.CommandLine.Output(), "Default output is very close to \"git describe --tags\" if there's a tag present, otherwise defaults to branch and commit:\n")
fmt.Fprint(flag.CommandLine.Output(), "\tIf HEAD is not tagged: <branch>-<HEAD SHA> (example: main-63380731)\n")
fmt.Fprint(flag.CommandLine.Output(), "\tIf HEAD is tagged: <tag>-<HEAD SHA> (example: v1.0.4-63380731)\n")
fmt.Fprint(flag.CommandLine.Output(), "\tIf HEAD is tagged but has commits after latest tag: <tag>-<commits since tag>-<HEAD SHA> (example: v1.0.4-1-5227b593)\n\n")
fmt.Fprint(flag.CommandLine.Output(), "If \"-b\" or \"-c\" are provided with \"-t\", it is additive and will include commits since tag if unclean.\n")
fmt.Fprint(flag.CommandLine.Output(), "The number of commits since tag can be ignored with \"-ignore-unclean-tag\".\n\n")
fmt.Fprint(flag.CommandLine.Output(), "Print order will be <tag>-<branch>[-<commits since tag>]-<SHA>.\n\n")
fmt.Fprintln(flag.CommandLine.Output(), "Set one or more flags.")

flag.PrintDefaults()
Expand Down

0 comments on commit e540e98

Please sign in to comment.