Skip to content

Commit 0edc609

Browse files
authored
Add disks usage API (#599)
1 parent 7e05533 commit 0edc609

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

cmd/host_disks.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var hostDisksCmd = &cobra.Command{
8+
Use: "disks",
9+
Aliases: []string{"disk"},
10+
Short: "Manage host disk operations",
11+
Long: `
12+
The disks command provides access to disk-related operations on the host system
13+
that Home Assistant is running on.`,
14+
Example: `
15+
ha host disks usage`,
16+
}
17+
18+
func init() {
19+
hostCmd.AddCommand(hostDisksCmd)
20+
}

cmd/host_disks_usage.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmd
2+
3+
import (
4+
helper "github.com/home-assistant/cli/client"
5+
log "github.com/sirupsen/logrus"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var hostDisksUsageCmd = &cobra.Command{
10+
Use: "usage",
11+
Aliases: []string{"us", "use"},
12+
Short: "Get default disk usage information",
13+
Long: `
14+
This command provides information about the default disk usage on the host system
15+
that Home Assistant is running on.`,
16+
Example: `
17+
ha host disks usage`,
18+
ValidArgsFunction: cobra.NoFileCompletions,
19+
Args: cobra.NoArgs,
20+
Run: func(cmd *cobra.Command, args []string) {
21+
log.WithField("args", args).Debug("host disks usage")
22+
23+
section := "host"
24+
command := "disks/default/usage"
25+
26+
resp, err := helper.GenericJSONGet(section, command)
27+
if err != nil {
28+
helper.PrintError(err)
29+
ExitWithError = true
30+
} else {
31+
ExitWithError = !helper.ShowJSONResponse(resp)
32+
}
33+
},
34+
}
35+
36+
func init() {
37+
hostDisksCmd.AddCommand(hostDisksUsageCmd)
38+
}

0 commit comments

Comments
 (0)