2020-04-07 17:12:14 +03:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Masterminds/semver"
|
2022-10-28 12:31:03 +03:00
|
|
|
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/errors"
|
2020-04-07 17:12:14 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type VersionFlag struct {
|
|
|
|
Version *semver.Version
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewVersionFlagValue returns ConfigVersion set with default value
|
|
|
|
func NewVersionFlagValue(p *VersionFlag) *VersionFlag {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set sets the value of the named command-line flag.
|
|
|
|
func (c *VersionFlag) Set(s string) error {
|
2022-10-28 12:31:03 +03:00
|
|
|
var op errors.Op = "util.VersionFlag.Set"
|
2020-04-07 17:12:14 +03:00
|
|
|
v, err := semver.NewVersion(s)
|
|
|
|
if err != nil {
|
2022-10-28 12:31:03 +03:00
|
|
|
return errors.E(op, err)
|
2020-04-07 17:12:14 +03:00
|
|
|
}
|
|
|
|
c.Version = v
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type returns a string that uniquely represents this flag's type.
|
|
|
|
func (c *VersionFlag) Type() string {
|
|
|
|
return "string"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *VersionFlag) String() string {
|
|
|
|
if c.Version == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return c.Version.String()
|
|
|
|
}
|