Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions cmd/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"errors"
"fmt"

"github.com/massdriver-cloud/mass/docs/helpdocs"
Expand Down Expand Up @@ -159,28 +160,21 @@ func runComponentUpdate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("error initializing massdriver client: %w", err)
}

current, err := mdClient.Components.Get(ctx, componentID)
if err != nil {
return fmt.Errorf("error getting component: %w", err)
if !cmd.Flags().Changed("name") && !cmd.Flags().Changed("description") && !cmd.Flags().Changed("attributes") {
return errors.New("nothing to update: set at least one of --name, --description, or --attributes")
}

if !cmd.Flags().Changed("name") {
name = current.Name
// Only send fields whose flags were explicitly set. Nil pointers (and a
// nil Attributes map) leave the corresponding values unchanged at the server.
input := components.UpdateInput{}
if cmd.Flags().Changed("name") {
input.Name = &name
}
if !cmd.Flags().Changed("description") {
description = current.Description
if cmd.Flags().Changed("description") {
input.Description = &description
}
var attributes map[string]any
if cmd.Flags().Changed("attributes") {
attributes = cli.AttributesToAnyMap(attrs)
} else {
attributes = current.Attributes
}

input := components.UpdateInput{
Name: name,
Description: description,
Attributes: attributes,
input.Attributes = cli.AttributesToAnyMap(attrs)
}

updated, err := mdClient.Components.Update(ctx, componentID, input)
Expand Down
28 changes: 11 additions & 17 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"embed"
"encoding/json"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -423,28 +424,21 @@ func runEnvironmentUpdate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("error initializing massdriver client: %w", err)
}

current, err := mdClient.Environments.Get(ctx, environmentID)
if err != nil {
return fmt.Errorf("error getting environment: %w", err)
if !cmd.Flags().Changed("name") && !cmd.Flags().Changed("description") && !cmd.Flags().Changed("attributes") {
return errors.New("nothing to update: set at least one of --name, --description, or --attributes")
}

if !cmd.Flags().Changed("name") {
name = current.Name
// Only send fields whose flags were explicitly set. Nil pointers (and a
// nil Attributes map) leave the corresponding values unchanged at the server.
input := environments.UpdateInput{}
if cmd.Flags().Changed("name") {
input.Name = &name
}
if !cmd.Flags().Changed("description") {
description = current.Description
if cmd.Flags().Changed("description") {
input.Description = &description
}
var attributes map[string]any
if cmd.Flags().Changed("attributes") {
attributes = cli.AttributesToAnyMap(attrs)
} else {
attributes = current.Attributes
}

input := environments.UpdateInput{
Name: name,
Description: description,
Attributes: attributes,
input.Attributes = cli.AttributesToAnyMap(attrs)
}

updated, err := mdClient.Environments.Update(ctx, environmentID, input)
Expand Down
30 changes: 11 additions & 19 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"embed"
"encoding/json"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -362,30 +363,21 @@ func runProjectUpdate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("error initializing massdriver client: %w", err)
}

// Fetch current state so unset flags retain their existing values rather
// than blanking the field at the server.
current, err := mdClient.Projects.Get(ctx, projectID)
if err != nil {
return fmt.Errorf("error getting project: %w", err)
if !cmd.Flags().Changed("name") && !cmd.Flags().Changed("description") && !cmd.Flags().Changed("attributes") {
return errors.New("nothing to update: set at least one of --name, --description, or --attributes")
}

if !cmd.Flags().Changed("name") {
name = current.Name
// Only send fields whose flags were explicitly set. Nil pointers (and a
// nil Attributes map) leave the corresponding values unchanged at the server.
input := projects.UpdateInput{}
if cmd.Flags().Changed("name") {
input.Name = &name
}
if !cmd.Flags().Changed("description") {
description = current.Description
if cmd.Flags().Changed("description") {
input.Description = &description
}
var attributes map[string]any
if cmd.Flags().Changed("attributes") {
attributes = cli.AttributesToAnyMap(attrs)
} else {
attributes = current.Attributes
}

input := projects.UpdateInput{
Name: name,
Description: description,
Attributes: attributes,
input.Attributes = cli.AttributesToAnyMap(attrs)
}

updated, err := mdClient.Projects.Update(ctx, projectID, input)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/itchyny/gojq v0.12.16
github.com/manifoldco/promptui v0.9.0
github.com/massdriver-cloud/airlock v0.0.10
github.com/massdriver-cloud/massdriver-sdk-go v0.2.11
github.com/massdriver-cloud/massdriver-sdk-go v0.2.15
github.com/mattn/go-runewidth v0.0.24
github.com/opencontainers/image-spec v1.1.1
github.com/osteele/liquid v1.7.0
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,8 @@ github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYt
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/massdriver-cloud/airlock v0.0.10 h1:05wz7kovH09X1VMfHcjLWylYanoLFcxuD0oZi13WG9U=
github.com/massdriver-cloud/airlock v0.0.10/go.mod h1:igJm33JvINiUtbyEspUeKUWyWewG+jYyxO1UDHqLp9Q=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.6 h1:si8MxuvRBTK3cz6IsAaXvtjE8jsxUnL0Q7O4vixAkxw=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.6/go.mod h1:6NrSP+wfGQvUOAggsz10/Wkln8CKmk3VBnD+OJzZgFY=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.10-0.20260721201746-c925c95365f7 h1:6shd1AfMSiLwfRf5w4NJIQZLzRG+Zsd8Pex/VpnC94Q=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.10-0.20260721201746-c925c95365f7/go.mod h1:6NrSP+wfGQvUOAggsz10/Wkln8CKmk3VBnD+OJzZgFY=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.10 h1:KtRWFibrabU5shvIiIQMpYieg72gUq93omM39LuEPTw=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.10/go.mod h1:6NrSP+wfGQvUOAggsz10/Wkln8CKmk3VBnD+OJzZgFY=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.11 h1:8MXqxArkX3TO+UJpzRF7iexHVO08TocPDqGGk6twBeM=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.11/go.mod h1:6NrSP+wfGQvUOAggsz10/Wkln8CKmk3VBnD+OJzZgFY=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.15 h1:ZJjirglHljaZqrHu8/3HeNK7RkMBHL0ZJTfPtgYlQlg=
github.com/massdriver-cloud/massdriver-sdk-go v0.2.15/go.mod h1:6NrSP+wfGQvUOAggsz10/Wkln8CKmk3VBnD+OJzZgFY=
github.com/massdriver-cloud/terraform-config-inspect v0.0.2 h1:Jc7BrhFHLbK7Epig6ShiEVMzQPPHVIOx0/BatvtEwtY=
github.com/massdriver-cloud/terraform-config-inspect v0.0.2/go.mod h1:3AbDpWxIRMdMAg7FDmTJuVBhCGNwdm49cBIOmUHjqRg=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down
Loading