mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 09:51:59 +03:00
37 lines
676 B
Go
37 lines
676 B
Go
|
package util
|
||
|
|
||
|
import (
|
||
|
"github.com/Masterminds/semver"
|
||
|
)
|
||
|
|
||
|
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 {
|
||
|
v, err := semver.NewVersion(s)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
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()
|
||
|
}
|