-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(version): adds command to check current gum version
closes #352 Signed-off-by: Carlos Alexandro Becker <[email protected]>
- Loading branch information
Showing
6 changed files
with
46 additions
and
0 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
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
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,25 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
"github.com/alecthomas/kong" | ||
) | ||
|
||
// Run check that a given version matches a semantic version constraint. | ||
func (o Options) Run(ctx *kong.Context) error { | ||
c, err := semver.NewConstraint(o.Constraint) | ||
if err != nil { | ||
return fmt.Errorf("could not parse range %s: %w", o.Constraint, err) | ||
} | ||
current := ctx.Model.Vars()["versionNumber"] | ||
v, err := semver.NewVersion(current) | ||
if err != nil { | ||
return fmt.Errorf("could parse version %s: %w", current, err) | ||
} | ||
if !c.Check(v) { | ||
return fmt.Errorf("gum version %q is not within given range %q", current, o.Constraint) | ||
} | ||
return nil | ||
} |
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,6 @@ | ||
package version | ||
|
||
// Options is the set of options that can be used with version. | ||
type Options struct { | ||
Constraint string `arg:"" help:"Semantic version constraint"` | ||
} |