Skip to content

Commit

Permalink
Merge pull request #6725 from cli/cmbrose/rename-repo-shorthand
Browse files Browse the repository at this point in the history
Codespaces: Use -R for --repo shorthand and deprecate -r
  • Loading branch information
cmbrose committed Dec 13, 2022
2 parents dd8c5c9 + 56006ee commit 6f1d149
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
16 changes: 16 additions & 0 deletions pkg/cmd/codespace/common.go
Expand Up @@ -284,3 +284,19 @@ func (c codespace) hasUnsavedChanges() bool {
func (c codespace) running() bool {
return c.State == api.CodespaceStateAvailable
}

// addDeprecatedRepoShorthand adds a -r parameter (deprecated shorthand for --repo)
// which instructs the user to use -R instead.
func addDeprecatedRepoShorthand(cmd *cobra.Command, target *string) error {
cmd.Flags().StringVarP(target, "repo-deprecated", "r", "", "(Deprecated) Shorthand for --repo")

if err := cmd.Flags().MarkHidden("repo-deprecated"); err != nil {
return fmt.Errorf("error marking `-r` shorthand as hidden: %w", err)
}

if err := cmd.Flags().MarkShorthandDeprecated("repo-deprecated", "use `-R` instead"); err != nil {
return fmt.Errorf("error marking `-r` shorthand as deprecated: %w", err)
}

return nil
}
6 changes: 5 additions & 1 deletion pkg/cmd/codespace/create.go
Expand Up @@ -81,7 +81,11 @@ func newCreateCmd(app *App) *cobra.Command {
},
}

createCmd.Flags().StringVarP(&opts.repo, "repo", "r", "", "repository name with owner: user/repo")
createCmd.Flags().StringVarP(&opts.repo, "repo", "R", "", "repository name with owner: user/repo")
if err := addDeprecatedRepoShorthand(createCmd, &opts.repo); err != nil {
fmt.Fprintf(app.io.ErrOut, "%v\n", err)
}

createCmd.Flags().StringVarP(&opts.branch, "branch", "b", "", "repository branch")
createCmd.Flags().StringVarP(&opts.location, "location", "l", "", "location: {EastUs|SouthEastAsia|WestEurope|WestUs2} (determined automatically if not provided)")
createCmd.Flags().StringVarP(&opts.machine, "machine", "m", "", "hardware specifications for the VM")
Expand Down
6 changes: 5 additions & 1 deletion pkg/cmd/codespace/delete.go
Expand Up @@ -66,7 +66,11 @@ func newDeleteCmd(app *App) *cobra.Command {

deleteCmd.Flags().StringVarP(&opts.codespaceName, "codespace", "c", "", "Name of the codespace")
deleteCmd.Flags().BoolVar(&opts.deleteAll, "all", false, "Delete all codespaces")
deleteCmd.Flags().StringVarP(&opts.repoFilter, "repo", "r", "", "Delete codespaces for a `repository`")
deleteCmd.Flags().StringVarP(&opts.repoFilter, "repo", "R", "", "Delete codespaces for a `repository`")
if err := addDeprecatedRepoShorthand(deleteCmd, &opts.repoFilter); err != nil {
fmt.Fprintf(app.io.ErrOut, "%v\n", err)
}

deleteCmd.Flags().BoolVarP(&opts.skipConfirm, "force", "f", false, "Skip confirmation for codespaces that contain unsaved changes")
deleteCmd.Flags().Uint16Var(&opts.keepDays, "days", 0, "Delete codespaces older than `N` days")
deleteCmd.Flags().StringVarP(&opts.orgName, "org", "o", "", "The `login` handle of the organization (admin-only)")
Expand Down
6 changes: 5 additions & 1 deletion pkg/cmd/codespace/list.go
Expand Up @@ -44,7 +44,11 @@ func newListCmd(app *App) *cobra.Command {
}

listCmd.Flags().IntVarP(&opts.limit, "limit", "L", 30, "Maximum number of codespaces to list")
listCmd.Flags().StringVarP(&opts.repo, "repo", "r", "", "Repository name with owner: user/repo")
listCmd.Flags().StringVarP(&opts.repo, "repo", "R", "", "Repository name with owner: user/repo")
if err := addDeprecatedRepoShorthand(listCmd, &opts.repo); err != nil {
fmt.Fprintf(app.io.ErrOut, "%v\n", err)
}

listCmd.Flags().StringVarP(&opts.orgName, "org", "o", "", "The `login` handle of the organization to list codespaces for (admin-only)")
listCmd.Flags().StringVarP(&opts.userName, "user", "u", "", "The `username` to list codespaces for (used with --org)")
cmdutil.AddJSONFlags(listCmd, &exporter, api.CodespaceFields)
Expand Down

0 comments on commit 6f1d149

Please sign in to comment.