-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unify the flag
--output
of the kusion version
command with other …
…commands (#394)
- Loading branch information
Showing
15 changed files
with
1,270 additions
and
1,327 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 |
---|---|---|
@@ -1,44 +1,34 @@ | ||
package version | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"kusionstack.io/kusion/pkg/version" | ||
) | ||
|
||
const jsonOutput = "json" | ||
|
||
type VersionOptions struct { | ||
ExportJSON bool | ||
ExportYAML bool | ||
Short bool | ||
Output string | ||
} | ||
|
||
func NewVersionOptions() *VersionOptions { | ||
return &VersionOptions{} | ||
} | ||
|
||
func (o *VersionOptions) Complete() { | ||
if !(o.ExportYAML || o.ExportJSON || o.Short) { | ||
o.ExportYAML = true | ||
} | ||
} | ||
|
||
func (o *VersionOptions) Validate() error { | ||
if (o.ExportJSON && o.ExportYAML) || (o.ExportJSON && o.Short) || (o.ExportYAML && o.Short) { | ||
return fmt.Errorf("invalid options") | ||
if o.Output != "" && o.Output != jsonOutput { | ||
return errors.New("invalid output type, output must be 'json'") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (o *VersionOptions) Run() { | ||
switch { | ||
case o.ExportJSON: | ||
if strings.ToLower(o.Output) == jsonOutput { | ||
fmt.Println(version.JSON()) | ||
case o.ExportYAML: | ||
fmt.Println(version.YAML()) | ||
case o.Short: | ||
fmt.Println(version.ShortString()) | ||
default: | ||
} else { | ||
fmt.Println(version.String()) | ||
} | ||
} |
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
Binary file modified
BIN
-616 Bytes
(97%)
pkg/util/i18n/translations/kusion/en_US/LC_MESSAGES/kusion.mo
Binary file not shown.
Oops, something went wrong.