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

Added completer for bluetoothctl #2313

Merged
merged 3 commits into from
Mar 29, 2024
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
62 changes: 62 additions & 0 deletions completers/bluetoothctl_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package action

import (
"strings"

"github.com/carapace-sh/carapace"
)

func ActionAgents() carapace.Action {
return carapace.ActionValues(
"off",
"on",
"auto",
"NoInputNoOutput",
"KeyboardOnly",
"KeyboardDisplay",
"DisplayYesNo",
"DisplayOnly",
)
}

func ActionControllers() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionExecCommand("bluetoothctl", "list")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)

for _, line := range lines {
if line == "" {
break
}

fields := strings.Fields(line)
vals = append(vals, fields[1], strings.Join(fields[2:], " "))
}
return carapace.ActionValuesDescribed(vals...)
})
})
}

func ActionDevices(filter string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
args := []string{"devices"}
if filter != "" {
args = append(args, filter)
}
return carapace.ActionExecCommand("bluetoothctl", args...)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)

for _, line := range lines {
if line == "" {
break
}

fields := strings.Fields(line)
vals = append(vals, fields[1], strings.Join(fields[2:], " "))
}
return carapace.ActionValuesDescribed(vals...)
})
})
}
20 changes: 20 additions & 0 deletions completers/bluetoothctl_completer/cmd/advertise.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var advertiseCmd = &cobra.Command{
Use: "advertise [on|off|broadcast|peripheral]",
Short: "Enable/disable advertising",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(advertiseCmd).Standalone()
rootCmd.AddCommand(advertiseCmd)
carapace.Gen(advertiseCmd).PositionalCompletion(
carapace.ActionValues("on", "off", "broadcast", "peripheral"),
)
}
21 changes: 21 additions & 0 deletions completers/bluetoothctl_completer/cmd/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/bluetoothctl_completer/cmd/action"
"github.com/spf13/cobra"
)

var agentCmd = &cobra.Command{
Use: "agent <on|off|auto|capability>",
Short: "Enable/disable agent with given capability",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(agentCmd).Standalone()
rootCmd.AddCommand(agentCmd)
carapace.Gen(agentCmd).PositionalCompletion(
action.ActionAgents(),
)
}
21 changes: 21 additions & 0 deletions completers/bluetoothctl_completer/cmd/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/bluetoothctl_completer/cmd/action"
"github.com/spf13/cobra"
)

var blockCmd = &cobra.Command{
Use: "block <device>",
Short: "Block device",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(blockCmd).Standalone()
rootCmd.AddCommand(blockCmd)
carapace.Gen(blockCmd).PositionalCompletion(
action.ActionDevices(""),
)
}
21 changes: 21 additions & 0 deletions completers/bluetoothctl_completer/cmd/cancelPairing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/bluetoothctl_completer/cmd/action"
"github.com/spf13/cobra"
)

var cancelPairingCmd = &cobra.Command{
Use: "cancel-pairing <device>",
Short: "Cancel pairing with device",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(cancelPairingCmd).Standalone()
rootCmd.AddCommand(cancelPairingCmd)
carapace.Gen(cancelPairingCmd).PositionalCompletion(
action.ActionDevices("Paired"),
)
}
21 changes: 21 additions & 0 deletions completers/bluetoothctl_completer/cmd/connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/bluetoothctl_completer/cmd/action"
"github.com/spf13/cobra"
)

var connectCmd = &cobra.Command{
Use: "connect <device>",
Short: "Connect device",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(connectCmd).Standalone()
rootCmd.AddCommand(connectCmd)
carapace.Gen(connectCmd).PositionalCompletion(
action.ActionDevices(""),
)
}
17 changes: 17 additions & 0 deletions completers/bluetoothctl_completer/cmd/defaultAgent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var defaultAgentCmd = &cobra.Command{
Use: "default-agent",
Short: "Set agent as the default one",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(defaultAgentCmd).Standalone()
rootCmd.AddCommand(defaultAgentCmd)
}
20 changes: 20 additions & 0 deletions completers/bluetoothctl_completer/cmd/devices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var devicesCmd = &cobra.Command{
Use: "devices",
Short: "List available devices, with an optional property as the filter",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(devicesCmd).Standalone()
rootCmd.AddCommand(devicesCmd)
carapace.Gen(devicesCmd).PositionalCompletion(
carapace.ActionValues("Paired", "Bonded", "Trusted", "Connected"),
)
}
21 changes: 21 additions & 0 deletions completers/bluetoothctl_completer/cmd/disconnect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/bluetoothctl_completer/cmd/action"
"github.com/spf13/cobra"
)

var disconnectCmd = &cobra.Command{
Use: "disconnect <device>",
Short: "Disconnect device",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(disconnectCmd).Standalone()
rootCmd.AddCommand(disconnectCmd)
carapace.Gen(disconnectCmd).PositionalCompletion(
action.ActionDevices("Connected"),
)
}
18 changes: 18 additions & 0 deletions completers/bluetoothctl_completer/cmd/discoverable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var discoverableCmd = &cobra.Command{
Use: "discoverable [on|off]",
Short: "Set controller discoverable mode",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(discoverableCmd).Standalone()
rootCmd.AddCommand(discoverableCmd)
carapace.Gen(discoverableCmd).PositionalCompletion(carapace.ActionValues("on", "off"))
}
17 changes: 17 additions & 0 deletions completers/bluetoothctl_completer/cmd/discoverableTimeout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var discoverableTimeoutCmd = &cobra.Command{
Use: "discoverable-timeout [value]",
Short: "Set controller discoverable timeout",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(discoverableTimeoutCmd).Standalone()
rootCmd.AddCommand(discoverableTimeoutCmd)
}
17 changes: 17 additions & 0 deletions completers/bluetoothctl_completer/cmd/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var exportCmd = &cobra.Command{
Use: "export",
Short: "Print environment variables",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(exportCmd).Standalone()
rootCmd.AddCommand(exportCmd)
}
17 changes: 17 additions & 0 deletions completers/bluetoothctl_completer/cmd/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var helpCmd = &cobra.Command{
Use: "help",
Short: "Display help about this program",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(helpCmd).Standalone()
rootCmd.AddCommand(helpCmd)
}
21 changes: 21 additions & 0 deletions completers/bluetoothctl_completer/cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/bluetoothctl_completer/cmd/action"
"github.com/spf13/cobra"
)

var infoCmd = &cobra.Command{
Use: "info [device]",
Short: "Device/Set information",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(infoCmd).Standalone()
rootCmd.AddCommand(infoCmd)
carapace.Gen(infoCmd).PositionalCompletion(
action.ActionDevices(""),
)
}
17 changes: 17 additions & 0 deletions completers/bluetoothctl_completer/cmd/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var listCmd = &cobra.Command{
Use: "list",
Short: "List available controllers",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(listCmd).Standalone()
rootCmd.AddCommand(listCmd)
}
21 changes: 21 additions & 0 deletions completers/bluetoothctl_completer/cmd/pair.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/bluetoothctl_completer/cmd/action"
"github.com/spf13/cobra"
)

var pairCmd = &cobra.Command{
Use: "pair <device>",
Short: "Pair with device",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(pairCmd).Standalone()
rootCmd.AddCommand(pairCmd)
carapace.Gen(pairCmd).PositionalCompletion(
action.ActionDevices(""),
)
}
18 changes: 18 additions & 0 deletions completers/bluetoothctl_completer/cmd/pairable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var pairableCmd = &cobra.Command{
Use: "pairable [on|off]",
Short: "Set controller pairable mode",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(pairableCmd).Standalone()
rootCmd.AddCommand(pairableCmd)
carapace.Gen(pairableCmd).PositionalCompletion(carapace.ActionValues("on", "off"))
}
Loading