Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create hotspot #533

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
}

func ipMethodCompletions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"static", "auto", "disabled"}, cobra.ShellCompDirectiveNoFileComp
return []string{"static", "auto", "disabled", "shared"}, cobra.ShellCompDirectiveNoFileComp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Inconsistency found in IPv4 method documentation

The "shared" method is inconsistently documented across commands:

  • network update correctly lists it as static|auto|disabled|shared
  • network vlan only shows static|auto|disabled

Both commands use the same completion function that now includes "shared", making the vlan command's help text outdated.

🔗 Analysis chain

LGTM! Addition of "shared" IP method supports hotspot functionality.

The addition of "shared" to IP method completions is correct and necessary for enabling hotspot functionality.

Let's verify that the "shared" method is properly handled in the network update logic:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any validation or handling of the "shared" IP method
rg -l "shared.*method" --type go

Length of output: 34


Script:

#!/bin/bash
# Search for shared IP-related code and method validation
echo "=== Searching for 'shared' in Go files ==="
rg "shared" --type go -B 2 -A 2

echo -e "\n=== Searching for IP method validation ==="
rg "method.*=|method.*:=|validateMethod|checkMethod" --type go -B 2 -A 2

Length of output: 1182


Script:

#!/bin/bash
# Search for method handling in network update logic
echo "=== Searching for network update implementation ==="
ast-grep --pattern 'func.*networkUpdate.*{
  $$$
}'

echo -e "\n=== Searching for IPv4 method handling ==="
rg "ipv4.*method" --type go -B 3 -A 3

Length of output: 3739

}

func networkInterfaceCompletions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down
12 changes: 10 additions & 2 deletions cmd/network_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func init() {

networkUpdateCmd.Flags().StringArray("ipv4-address", []string{}, "IPv4 address for the interface in the 192.168.1.5/24")
networkUpdateCmd.Flags().String("ipv4-gateway", "", "The IPv4 gateway the interface should use")
networkUpdateCmd.Flags().String("ipv4-method", "", "Method on IPv4: static|auto|disabled")
networkUpdateCmd.Flags().String("ipv4-method", "", "Method on IPv4: static|auto|disabled|shared")
networkUpdateCmd.Flags().StringArray("ipv4-nameserver", []string{}, "IPv4 address of upstream DNS servers. Use multiple times for multiple servers.")

networkUpdateCmd.Flags().StringArray("ipv6-address", []string{}, "IPv6 address for the interface in the 2001:0db8:85a3:0000:0000:8a2e:0370:7334/64")
Expand All @@ -87,6 +87,8 @@ func init() {
networkUpdateCmd.Flags().String("wifi-ssid", "", "SSID for wifi connection")
networkUpdateCmd.Flags().String("wifi-auth", "", "Used authentication: open, wep, wpa-psk")
networkUpdateCmd.Flags().String("wifi-psk", "", "Shared authentication key for wep or wpa")
networkUpdateCmd.Flags().String("wifi-band", "", "Wifi band required for mode 'ap': a for 5GHz, bg for 2.4GHz")
networkUpdateCmd.Flags().Int("wifi-channel", 0, "Wifi channel required for mode 'ap'")

networkUpdateCmd.Flags().BoolP("disabled", "e", false, "Disable interface")

Expand All @@ -108,6 +110,10 @@ func init() {
return []string{"open", "wep", "wpa-psk"}, cobra.ShellCompDirectiveNoFileComp
})
networkUpdateCmd.RegisterFlagCompletionFunc("wifi-psk", cobra.NoFileCompletions)
networkUpdateCmd.RegisterFlagCompletionFunc("wifi-band", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"a", "bg"}, cobra.ShellCompDirectiveNoFileComp
})
networkUpdateCmd.RegisterFlagCompletionFunc("wifi-channel", cobra.NoFileCompletions)

networkUpdateCmd.RegisterFlagCompletionFunc("disabled", boolCompletions)

Expand All @@ -131,7 +137,7 @@ func parseNetworkArgs(cmd *cobra.Command, args []NetworkArg) map[string]interfac
val, err = cmd.Flags().GetStringArray(arg.Arg)
changed = len(val.([]string)) > 0
} else {
val, err = cmd.Flags().GetString(arg.Arg)
val = cmd.Flags().Lookup(arg.Arg).Value.String()
changed = val.(string) != ""
}

Expand Down Expand Up @@ -162,6 +168,8 @@ func helperWifiConfig(cmd *cobra.Command, options map[string]interface{}) {
{Arg: "wifi-ssid", ApiKey: "ssid"},
{Arg: "wifi-auth", ApiKey: "auth"},
{Arg: "wifi-psk", ApiKey: "psk"},
{Arg: "wifi-band", ApiKey: "band"},
{Arg: "wifi-channel", ApiKey: "channel"},
}

wifiConfig := parseNetworkArgs(cmd, args)
Expand Down