Skip to content

Commit c60fa6f

Browse files
fix: dotenv reading
1 parent b883443 commit c60fa6f

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

cmd/root/root.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ func NewApp() *cli.App {
5353
EnvVars: []string{"CREATEOS_DEBUG"},
5454
},
5555
&cli.StringFlag{
56-
Name: "api-url",
57-
Usage: "Override the API base URL",
58-
EnvVars: []string{"CREATEOS_API_URL"},
59-
Value: api.DefaultBaseURL,
56+
Name: "api-url",
57+
Usage: "Override the API base URL",
58+
EnvVars: []string{"CREATEOS_API_URL",
59+
"CREATEOS_PLAN_API_URL",
60+
"CREATEOS_PROJECT_API_URL"},
61+
Value: api.DefaultBaseURL,
6062
},
6163
&cli.StringFlag{
6264
Name: "sandbox-api-url",
@@ -71,9 +73,11 @@ func NewApp() *cli.App {
7173
Value: "gateway.sb.createos.sh:2222",
7274
},
7375
&cli.StringFlag{
74-
Name: "api-key",
75-
Usage: "API key for authentication (overrides stored token)",
76-
EnvVars: []string{"CREATEOS_API_KEY"},
76+
Name: "api-key",
77+
Usage: "API key for authentication (overrides stored token)",
78+
EnvVars: []string{"CREATEOS_API_KEY",
79+
"CREATEOS_PLAN_API_KEY",
80+
"CREATEOS_PROJECT_API_KEY"},
7781
},
7882
&cli.StringFlag{
7983
Name: "output",

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
2828
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
2929
github.com/gookit/color v1.6.0 // indirect
30+
github.com/joho/godotenv v1.5.1 // indirect
3031
github.com/lithammer/fuzzysearch v1.1.8 // indirect
3132
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
3233
github.com/mattn/go-isatty v0.0.20 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ github.com/gookit/assert v0.1.1 h1:lh3GcawXe/p+cU7ESTZ5Ui3Sm/x8JWpIis4/1aF0mY0=
3838
github.com/gookit/assert v0.1.1/go.mod h1:jS5bmIVQZTIwk42uXl4lyj4iaaxx32tqH16CFj0VX2E=
3939
github.com/gookit/color v1.6.0 h1:JjJXBTk1ETNyqyilJhkTXJYYigHG24TM9Xa2M1xAhRA=
4040
github.com/gookit/color v1.6.0/go.mod h1:9ACFc7/1IpHGBW8RwuDm/0YEnhg3dwwXpoMsmtyHfjs=
41+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
42+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
4143
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
4244
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
4345
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import (
55
"errors"
66
"os"
77

8+
"github.com/joho/godotenv"
89
"github.com/pterm/pterm"
910

1011
"github.com/NodeOps-app/createos-cli/cmd/root"
1112
"github.com/NodeOps-app/createos-cli/internal/api"
1213
)
1314

1415
func main() {
16+
// Load .env file from the current directory if it exists.
17+
// Existing environment variables are NOT overwritten.
18+
_ = godotenv.Load()
19+
1520
app := root.NewApp()
1621

1722
if err := app.Run(os.Args); err != nil {

0 commit comments

Comments
 (0)