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
4 changes: 2 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The CLI is communicating with the Supervisor using the Supervisor's HTTP REST AP
- **CLI Framework**: Cobra (github.com/spf13/cobra)
- **HTTP Client**: Resty (github.com/go-resty/resty/v2)
- **Configuration**: Viper (github.com/spf13/viper)
- **Logging**: Logrus (github.com/sirupsen/logrus)
- **Logging**: Go stdlib log/slog

## Available Commands
The CLI provides the following main command categories:
Expand Down Expand Up @@ -62,7 +62,7 @@ The CLI provides the following main command categories:
- Uses Cobra for command structure and flag parsing
- Resty for HTTP API calls to Home Assistant Supervisor
- Viper for configuration management
- Logrus for structured logging
- Go stdlib log/slog for structured logging
- Custom spinner implementation for progress indication

## Testing
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package client

import (
"fmt"
"log/slog"
"net/http"
"time"

resty "github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
)

// RawJSON controls if the client does json handling or outputs it raw
Expand Down Expand Up @@ -61,7 +61,7 @@ func genericJSONMethod(get bool, section, command string, body map[string]any, t
resp, err = request.Get(url)
} else {
if len(body) > 0 {
log.WithField("body", body).Debug("Request body")
slog.Debug("Request body", "body", body)
request.SetBody(body)
}
resp, err = request.Post(url)
Expand Down
24 changes: 4 additions & 20 deletions client/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"net/url"
"os"
"os/signal"
Expand All @@ -18,7 +19,6 @@ import (

yaml "github.com/ghodss/yaml"
resty "github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"

"strings"
Expand All @@ -43,11 +43,7 @@ type Response struct {
// URLHelper returns a URL built from the arguments
func URLHelper(section, command string) (string, error) {
base := viper.GetString("endpoint")
log.WithFields(log.Fields{
"base": base,
"section": section,
"command": command,
}).Debug("[GenerateURI]")
slog.Debug("[GenerateURI]", "base", base, "section", section, "command", command)

scheme := ""
if !strings.Contains(base, "://") {
Expand All @@ -69,11 +65,7 @@ func URLHelper(section, command string) (string, error) {
myurl.Path = path.Clean(myurl.Path)

res, _ := url.PathUnescape(myurl.String())
log.WithFields(log.Fields{
"uri": uri,
"url": myurl,
"url(string)": res,
}).Debug("[GenerateURI] Result")
slog.Debug("[GenerateURI] Result", "uri", uri, "url", myurl, "url(string)", res)
return res, nil
}

Expand Down Expand Up @@ -108,15 +100,7 @@ func GetRequestTimeout(timeout time.Duration) *resty.Request {
// Registering Response Middleware
client.OnAfterResponse(func(c *resty.Client, resp *resty.Response) error {
// explore response object
log.WithFields(log.Fields{
"statuscode": resp.StatusCode(),
"status": resp.Status(),
"time": resp.Time(),
"received-at": resp.ReceivedAt(),
"headers": resp.Header(),
"request": resp.Request.RawRequest,
"body": resp,
}).Debug("Response")
slog.Debug("Response", "statuscode", resp.StatusCode(), "status", resp.Status(), "time", resp.Time(), "received-at", resp.ReceivedAt(), "headers", resp.Header(), "request", resp.Request.RawRequest, "body", resp)

return nil // if its success otherwise return error
})
Expand Down
6 changes: 3 additions & 3 deletions cmd/apps.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd

import (
"log/slog"
"os"
"strings"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -30,7 +30,7 @@ information commands for apps.`,
rootCmd.PersistentPreRun(cmd, args)
},
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps")
slog.Debug("apps", "args", args)

section := "addons"
command := ""
Expand All @@ -46,7 +46,7 @@ information commands for apps.`,
}

func init() {
log.Debug("Init apps")
slog.Debug("Init apps")

rootCmd.AddCommand(appsCmd)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/apps_changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package cmd
import (
"errors"
"fmt"
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -22,7 +22,7 @@ ha apps changelog core_mosquitto`,
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps changelog")
slog.Debug("apps changelog", "args", args)

section := "addons"
command := "{slug}/changelog"
Expand All @@ -48,7 +48,7 @@ ha apps changelog core_mosquitto`,
// returns 200 OK or 400, everything else is wrong
if err == nil && resp.StatusCode() != 200 && resp.StatusCode() != 400 {
err = errors.New("unexpected server response")
log.Error(err)
slog.Error("unexpected server response", "status", resp.StatusCode())
}

if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_info.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -21,7 +22,7 @@ is provided, information about a specific app.
ValidArgsFunction: appsCompletions,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps info")
slog.Debug("apps info", "args", args)

section := "addons"
command := "{slug}/info"
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_install.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -19,7 +20,7 @@ This command allows you to install a Home Assistant app from the commandline.
ValidArgsFunction: storeAppCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps install")
slog.Debug("apps install", "args", args)

section := "addons"
command := "{slug}/install"
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_logs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -19,7 +20,7 @@ Allowing you to look at the log output generated by a Home Assistant app.
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps logs")
slog.Debug("apps logs", "args", args)

section := "addons/{slug}"

Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_rebuild.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -24,7 +25,7 @@ of apps. This command allows you to trigger a rebuild of a locally built app.
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps rebuild")
slog.Debug("apps rebuild", "args", args)

section := "addons"
command := "{slug}/rebuild"
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_restart.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -19,7 +20,7 @@ Restart a Home Assistant app
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps restart")
slog.Debug("apps restart", "args", args)

section := "addons"
command := "{slug}/restart"
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_start.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -19,7 +20,7 @@ This command allows you to manually start a stopped Home Assistant app
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps start")
slog.Debug("apps start", "args", args)

section := "addons"
command := "{slug}/start"
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_stats.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +21,7 @@ how much CPU, memory, disk & network resources it uses.
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps stats")
slog.Debug("apps stats", "args", args)

section := "addons"
command := "{slug}/stats"
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_stop.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -19,7 +20,7 @@ This command allows you to manually stop a Home Assistant app
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps stop")
slog.Debug("apps stop", "args", args)

section := "addons"
command := "{slug}/stop"
Expand Down
5 changes: 3 additions & 2 deletions cmd/apps_uninstall.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -19,7 +20,7 @@ This command allows you to uninstall a Home Assistant app.
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps uninstall")
slog.Debug("apps uninstall", "args", args)

section := "addons"
command := "{slug}/uninstall"
Expand Down
7 changes: 4 additions & 3 deletions cmd/apps_update.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
"log/slog"

helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +21,7 @@ It is currently not possible to upgrade/downgrade to a specific version.
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("apps update")
slog.Debug("apps update", "args", args)

section := "addons"
command := "{slug}/update"
Expand Down Expand Up @@ -51,7 +52,7 @@ It is currently not possible to upgrade/downgrade to a specific version.
}

if len(options) > 0 {
log.WithField("options", options).Debug("Request body")
slog.Debug("Request body", "options", options)
request.SetBody(options)
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/audio.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cmd

import (
log "github.com/sirupsen/logrus"
"log/slog"

"github.com/spf13/cobra"
)

Expand All @@ -18,7 +19,7 @@ Control audio devices.
}

func init() {
log.Debug("Init audio")
slog.Debug("Init audio")

rootCmd.AddCommand(audioCmd)
}
Loading