Skip to content

Commit

Permalink
[fhome] fix crash when installing with Homebrew
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Dec 4, 2024
1 parent 24e586c commit 99a815b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 9 additions & 0 deletions cmd/fhome/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var configCommand = cli.Command{
return fmt.Errorf("cannot use both --system and --user")
}

config := loadConfig()

client, err := highlevel.Connect(ctx, config, nil)
if err != nil {
return fmt.Errorf("failed to create api client: %v", err)
Expand Down Expand Up @@ -138,6 +140,8 @@ var eventCommand = cli.Command{
Name: "watch",
Usage: "Print all incoming messages",
Action: func(ctx context.Context, c *cli.Command) error {
config := loadConfig()

client, err := highlevel.Connect(ctx, config, nil)
if err != nil {
return fmt.Errorf("failed to create api client: %v", err)
Expand Down Expand Up @@ -180,6 +184,8 @@ var objectCommand = cli.Command{
return fmt.Errorf("object not specified")
}

config := loadConfig()

client, err := highlevel.Connect(ctx, config, nil)
if err != nil {
return fmt.Errorf("failed to create api client: %v", err)
Expand Down Expand Up @@ -232,6 +238,7 @@ var objectCommand = cli.Command{
}
},
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
config := loadConfig()
client, err := highlevel.Connect(ctx, config, nil)
if err != nil {
panic(err)
Expand Down Expand Up @@ -264,6 +271,8 @@ var objectCommand = cli.Command{
return fmt.Errorf("invalid value: %v", err)
}

config := loadConfig()

client, err := highlevel.Connect(ctx, config, nil)
if err != nil {
return fmt.Errorf("failed to create api client: %v", err)
Expand Down
6 changes: 2 additions & 4 deletions cmd/fhome/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"github.com/urfave/cli/v3"
)

var config *highlevel.Config

// This is set by GoReleaser, see https://goreleaser.com/cookbooks/using-main.version
var version = "dev"

Expand Down Expand Up @@ -82,7 +80,7 @@ func main() {
}
}

func loadConfig() {
func loadConfig() *highlevel.Config {
k := koanf.New(".")

p := "/etc/fhome/config.toml"
Expand All @@ -100,7 +98,7 @@ func loadConfig() {
slog.Debug("loaded config file", slog.String("path", p))
}

config = &highlevel.Config{
return &highlevel.Config{
Email: k.MustString("FHOME_EMAIL"),
Password: k.MustString("FHOME_CLOUD_PASSWORD"),
ResourcePassword: k.MustString("FHOME_RESOURCE_PASSWORD"),
Expand Down

0 comments on commit 99a815b

Please sign in to comment.