diff --git a/README.md b/README.md index ed32cc7..4c9a49c 100644 --- a/README.md +++ b/README.md @@ -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] [] -Default output is very close to "git describe --tags": - If HEAD is not tagged: -- (example: v1.0.4-1-5227b593) - If HEAD is tagged: (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: - (example: main-63380731) + If HEAD is tagged: - (example: v1.0.4-63380731) + If HEAD is tagged but has commits after latest tag: -- (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 --. +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 -[-]-. 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: ``` @@ -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 diff --git a/main.go b/main.go index 631fc24..96faeda 100644 --- a/main.go +++ b/main.go @@ -16,10 +16,10 @@ 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. @@ -27,11 +27,13 @@ func main() { flag.Usage = func() { fmt.Fprintf(flag.CommandLine.Output(), "Usage of tagver: [-t] [-b] [-c] []\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: -- (example: v1.0.4-1-5227b593)\n") - fmt.Fprint(flag.CommandLine.Output(), "\tIf HEAD is tagged: (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 --.\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: - (example: main-63380731)\n") + fmt.Fprint(flag.CommandLine.Output(), "\tIf HEAD is tagged: - (example: v1.0.4-63380731)\n") + fmt.Fprint(flag.CommandLine.Output(), "\tIf HEAD is tagged but has commits after latest tag: -- (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 -[-]-.\n\n") fmt.Fprintln(flag.CommandLine.Output(), "Set one or more flags.") flag.PrintDefaults()