Skip to content

Commit 78884e7

Browse files
authored
Support RENDER_REGION env var for object storage commands (#253)
Allows users to set the region via `RENDER_REGION` instead of passing `--region` on every command. The flag takes precedence when both are provided, matching the SDK's behavior for consistency.
1 parent 84f9417 commit 78884e7

6 files changed

Lines changed: 30 additions & 8 deletions

File tree

cmd/object.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ var objectCmd = &cobra.Command{
1212
Object storage allows you to store and retrieve arbitrary data. Use these commands
1313
to list, upload, download, and delete objects.
1414
15+
The --region flag specifies which region to use. Alternatively, set the
16+
RENDER_REGION environment variable. The --region flag takes precedence
17+
if both are provided.
18+
1519
In local development mode (when running with 'render ea tasks dev' or with the
1620
--local flag), objects are stored in the .render/objects/ directory.
1721
@@ -23,6 +27,7 @@ Available commands:
2327
2428
Examples:
2529
render ea objects list --region=oregon
30+
RENDER_REGION=oregon render ea objects list
2631
render ea objects put my/object/key --file=./data.txt --region=oregon
2732
render ea objects get my/object/key --file=./output.txt --region=oregon
2833
render ea objects delete my/object/key --region=oregon --yes
@@ -31,11 +36,8 @@ Examples:
3136

3237
func init() {
3338
// Add persistent flags shared by all object commands
34-
objectCmd.PersistentFlags().String("region", "", "Target region (required)")
39+
objectCmd.PersistentFlags().String("region", "", "Target region (or set RENDER_REGION env var)")
3540
objectCmd.PersistentFlags().Bool("local", false, "Use local storage (.render/objects/) instead of cloud storage")
3641

37-
// Mark region as required for all object commands
38-
objectCmd.MarkPersistentFlagRequired("region")
39-
4042
EarlyAccessCmd.AddCommand(objectCmd)
4143
}

cmd/objectdelete.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/spf13/cobra"
1010

11+
"github.com/render-oss/cli/pkg/cfg"
1112
"github.com/render-oss/cli/pkg/command"
1213
"github.com/render-oss/cli/pkg/storage"
1314
"github.com/render-oss/cli/pkg/text"
@@ -25,7 +26,10 @@ func (i *ObjectDeleteInput) Validate(interactive bool) error {
2526
return fmt.Errorf("key is required")
2627
}
2728
if i.Region == "" {
28-
return fmt.Errorf("--region is required")
29+
i.Region = cfg.GetRegion()
30+
}
31+
if i.Region == "" {
32+
return fmt.Errorf("--region is required (or set RENDER_REGION environment variable)")
2933
}
3034
return nil
3135
}

cmd/objectget.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/spf13/cobra"
88

9+
"github.com/render-oss/cli/pkg/cfg"
910
"github.com/render-oss/cli/pkg/command"
1011
"github.com/render-oss/cli/pkg/storage"
1112
"github.com/render-oss/cli/pkg/text"
@@ -23,7 +24,10 @@ func (i *ObjectGetInput) Validate(interactive bool) error {
2324
return fmt.Errorf("key is required")
2425
}
2526
if i.Region == "" {
26-
return fmt.Errorf("--region is required")
27+
i.Region = cfg.GetRegion()
28+
}
29+
if i.Region == "" {
30+
return fmt.Errorf("--region is required (or set RENDER_REGION environment variable)")
2731
}
2832
return nil
2933
}

cmd/objectlist.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/spf13/cobra"
77

8+
"github.com/render-oss/cli/pkg/cfg"
89
"github.com/render-oss/cli/pkg/command"
910
"github.com/render-oss/cli/pkg/storage"
1011
"github.com/render-oss/cli/pkg/text"
@@ -18,7 +19,10 @@ type ObjectListInput struct {
1819

1920
func (i *ObjectListInput) Validate(interactive bool) error {
2021
if i.Region == "" {
21-
return fmt.Errorf("--region is required")
22+
i.Region = cfg.GetRegion()
23+
}
24+
if i.Region == "" {
25+
return fmt.Errorf("--region is required (or set RENDER_REGION environment variable)")
2226
}
2327
if i.Limit <= 0 {
2428
return fmt.Errorf("--limit must be greater than 0")

cmd/objectput.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/spf13/cobra"
77

8+
"github.com/render-oss/cli/pkg/cfg"
89
"github.com/render-oss/cli/pkg/command"
910
"github.com/render-oss/cli/pkg/storage"
1011
"github.com/render-oss/cli/pkg/text"
@@ -25,7 +26,10 @@ func (i *ObjectPutInput) Validate(interactive bool) error {
2526
return fmt.Errorf("--file is required")
2627
}
2728
if i.Region == "" {
28-
return fmt.Errorf("--region is required")
29+
i.Region = cfg.GetRegion()
30+
}
31+
if i.Region == "" {
32+
return fmt.Errorf("--region is required (or set RENDER_REGION environment variable)")
2933
}
3034
return nil
3135
}

pkg/cfg/cfg.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ func GetAPIKey() string {
2424
return os.Getenv("RENDER_API_KEY")
2525
}
2626

27+
func GetRegion() string {
28+
return os.Getenv("RENDER_REGION")
29+
}
30+
2731
func AddUserAgent(header http.Header) http.Header {
2832
header.Add("user-agent", fmt.Sprintf("render-cli/%s (%s)", Version, getOSInfoOnce()))
2933
return header

0 commit comments

Comments
 (0)