Avoid passing params struct as pointer

This commit is contained in:
Mislav Marohnić 2021-09-24 17:36:18 +02:00
parent dc8f6ef183
commit c82d4c5472
2 changed files with 7 additions and 11 deletions

View file

@ -23,7 +23,7 @@ type createOptions struct {
}
func newCreateCmd(app *App) *cobra.Command {
opts := &createOptions{}
opts := createOptions{}
createCmd := &cobra.Command{
Use: "create",
@ -43,7 +43,7 @@ func newCreateCmd(app *App) *cobra.Command {
}
// Create creates a new Codespace
func (a *App) Create(ctx context.Context, opts *createOptions) error {
func (a *App) Create(ctx context.Context, opts createOptions) error {
locationCh := getLocation(ctx, a.apiClient)
userCh := getUser(ctx, a.apiClient)

View file

@ -10,28 +10,24 @@ import (
"github.com/spf13/cobra"
)
type listOptions struct {
asJSON bool
}
func newListCmd(app *App) *cobra.Command {
opts := &listOptions{}
var asJSON bool
listCmd := &cobra.Command{
Use: "list",
Short: "List your codespaces",
Args: noArgsConstraint,
RunE: func(cmd *cobra.Command, args []string) error {
return app.List(cmd.Context(), opts)
return app.List(cmd.Context(), asJSON)
},
}
listCmd.Flags().BoolVar(&opts.asJSON, "json", false, "Output as JSON")
listCmd.Flags().BoolVar(&asJSON, "json", false, "Output as JSON")
return listCmd
}
func (a *App) List(ctx context.Context, opts *listOptions) error {
func (a *App) List(ctx context.Context, asJSON bool) error {
user, err := a.apiClient.GetUser(ctx)
if err != nil {
return fmt.Errorf("error getting user: %w", err)
@ -42,7 +38,7 @@ func (a *App) List(ctx context.Context, opts *listOptions) error {
return fmt.Errorf("error getting codespaces: %w", err)
}
table := output.NewTable(os.Stdout, opts.asJSON)
table := output.NewTable(os.Stdout, asJSON)
table.SetHeader([]string{"Name", "Repository", "Branch", "State", "Created At"})
for _, codespace := range codespaces {
table.Append([]string{