-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose existing functionality behind a next command (#13)
- Loading branch information
1 parent
1d09bce
commit e2723e9
Showing
5 changed files
with
83 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,7 @@ brews: | |
name: homebrew-tap | ||
folder: Formula | ||
homepage: "https://github.com/purpleclay/nsv" | ||
description: "Next Semantic Version" | ||
description: "Manage your semantic versioning without any config" | ||
license: MIT | ||
install: | | ||
bin.install "nsv" | ||
|
@@ -131,7 +131,7 @@ nfpms: | |
- file_name_template: "{{ .ConventionalFileName }}" | ||
id: packages | ||
homepage: "https://github.com/purpleclay/nsv" | ||
description: "Next Semantic Version" | ||
description: "Manage your semantic versioning without any config" | ||
maintainer: Purple Clay <[email protected]> | ||
license: MIT | ||
vendor: Purple Clay | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# nsv | ||
|
||
Calculate the next semantic version without any config. Just type: | ||
Manage your semantic versioning without any config. Just type: | ||
|
||
```go | ||
nsv | ||
nsv next | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright (c) 2023 Purple Clay | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/caarlos0/env/v7" | ||
git "github.com/purpleclay/gitz" | ||
"github.com/purpleclay/nsv/internal/nsv" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var nextLongDesc = `Generate the next semantic version based on the | ||
conventional commit history of your repository. | ||
Environment Variables: | ||
| Name | Description | | ||
|------------|---------------------------------------------------| | ||
| NSV_FORMAT | set a go template for formatting the provided tag |` | ||
|
||
func nextCmd(out io.Writer) *cobra.Command { | ||
opts := nsv.Options{ | ||
StdOut: out, | ||
StdErr: os.Stderr, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "next", | ||
Short: "Generate the next semantic version", | ||
Long: nextLongDesc, | ||
Args: cobra.NoArgs, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return env.Parse(&opts) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
gitc, err := git.NewClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nsv.NextVersion(gitc, opts) | ||
}, | ||
} | ||
|
||
flags := cmd.Flags() | ||
flags.BoolVar(&opts.Show, "show", false, "show how the next semantic version was generated") | ||
flags.StringVar(&opts.VersionFormat, "format", "", "provide a go template for changing the default version format") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters