- Notifications
You must be signed in to change notification settings - Fork928
chore:version
sub command remove--version
and-v
flag#2090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
35 changes: 22 additions & 13 deletionscli/root.go
This file contains hidden or 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 |
---|---|---|
@@ -53,7 +53,6 @@ func init() { | ||
func Root() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "coder", | ||
SilenceErrors: true, | ||
SilenceUsage: true, | ||
Long: `Coder — A tool for provisioning self-hosted development environments. | ||
@@ -90,10 +89,10 @@ func Root() *cobra.Command { | ||
users(), | ||
portForward(), | ||
workspaceAgent(), | ||
versionCmd(), | ||
) | ||
cmd.SetUsageTemplate(usageTemplate()) | ||
cmd.PersistentFlags().String(varURL, "", "Specify the URL to your deployment.") | ||
cmd.PersistentFlags().String(varToken, "", "Specify an authentication token.") | ||
@@ -110,6 +109,27 @@ func Root() *cobra.Command { | ||
return cmd | ||
} | ||
// versionCmd prints the coder version | ||
func versionCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Show coder version", | ||
Example: "coder version", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var str strings.Builder | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
_, _ = str.WriteString(fmt.Sprintf("Coder %s", buildinfo.Version())) | ||
buildTime, valid := buildinfo.Time() | ||
if valid { | ||
_, _ = str.WriteString(" " + buildTime.Format(time.UnixDate)) | ||
} | ||
_, _ = str.WriteString("\r\n" + buildinfo.ExternalURL() + "\r\n") | ||
_, _ = fmt.Fprint(cmd.OutOrStdout(), str.String()) | ||
return nil | ||
}, | ||
} | ||
} | ||
// createClient returns a new client from the command context. | ||
// It reads from global configuration files if flags are not set. | ||
func createClient(cmd *cobra.Command) (*codersdk.Client, error) { | ||
@@ -286,17 +306,6 @@ Use "{{.CommandPath}} [command] --help" for more information about a command. | ||
{{end}}` | ||
} | ||
// FormatCobraError colorizes and adds "--help" docs to cobra commands. | ||
func FormatCobraError(err error, cmd *cobra.Command) string { | ||
helpErrMsg := fmt.Sprintf("Run '%s --help' for usage.", cmd.CommandPath()) | ||
17 changes: 17 additions & 0 deletionscli/root_test.go
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.