Skip to content

Commit 5db69b7

Browse files
committed
feat: Add docker opetions enable-ipv6
Signed-off-by: David Rapan <david@rapan.cz>
1 parent 4aa2652 commit 5db69b7

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

cmd/docker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The docker command provides command-line tools to control the host docker that
1313
Home Assistant is running on. It allows you to do things like use private OCI registries.`,
1414
Example: `
1515
ha docker info
16+
ha docker options
1617
ha docker registries`,
1718
}
1819

cmd/docker_options.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
helper "github.com/home-assistant/cli/client"
8+
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/pflag"
11+
)
12+
13+
var dockerOptionsCmd = &cobra.Command{
14+
Use: "options",
15+
Aliases: []string{"option", "opt", "opts", "op"},
16+
Short: "Allows you to set options on the host docker backend",
17+
Long: `
18+
This command allows you to set configuration options for on the host
19+
docker backend running on your Home Assistant system.`,
20+
Example: `
21+
ha docker options --enable-ipv6 true`,
22+
ValidArgsFunction: cobra.NoFileCompletions,
23+
Args: cobra.NoArgs,
24+
Run: func(cmd *cobra.Command, args []string) {
25+
log.WithField("args", args).Debug("docker options")
26+
27+
section := "docker"
28+
command := "options"
29+
30+
options := make(map[string]any)
31+
32+
for _, value := range []string{
33+
"enable_ipv6",
34+
} {
35+
data, err := cmd.Flags().GetBool(value)
36+
if err == nil && cmd.Flags().Changed(value) {
37+
options[strings.ReplaceAll(value, "-", "_")] = data
38+
}
39+
}
40+
41+
resp, err := helper.GenericJSONPost(section, command, options)
42+
if err != nil {
43+
fmt.Println(err)
44+
ExitWithError = true
45+
} else {
46+
ExitWithError = !helper.ShowJSONResponse(resp)
47+
}
48+
},
49+
}
50+
51+
func init() {
52+
dockerOptionsCmd.Flags().BoolP("enable-ipv6", "", false, "Enable IPv6")
53+
dockerOptionsCmd.Flags().SetNormalizeFunc(func(set *pflag.FlagSet, name string) pflag.NormalizedName {
54+
return pflag.NormalizedName(strings.ReplaceAll(name, "_", "-"))
55+
})
56+
57+
dockerCmd.AddCommand(dockerOptionsCmd)
58+
}

0 commit comments

Comments
 (0)