mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-05 21:15:38 -05:00
core: add dynamic completion for more commands (#889)
This commit is contained in:
@@ -28,6 +28,13 @@ var brightnessSetCmd = &cobra.Command{
|
|||||||
Short: "Set brightness for a device",
|
Short: "Set brightness for a device",
|
||||||
Long: "Set brightness percentage (0-100) for a specific device",
|
Long: "Set brightness percentage (0-100) for a specific device",
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
includeDDC, _ := cmd.Flags().GetBool("ddc")
|
||||||
|
return getBrightnessDevices(includeDDC), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
Run: runBrightnessSet,
|
Run: runBrightnessSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +43,13 @@ var brightnessGetCmd = &cobra.Command{
|
|||||||
Short: "Get brightness for a device",
|
Short: "Get brightness for a device",
|
||||||
Long: "Get current brightness percentage for a specific device",
|
Long: "Get current brightness percentage for a specific device",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
includeDDC, _ := cmd.Flags().GetBool("ddc")
|
||||||
|
return getBrightnessDevices(includeDDC), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
Run: runBrightnessGet,
|
Run: runBrightnessGet,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,9 +119,7 @@ Global Flags:
|
|||||||
brightnessCmd.AddCommand(brightnessListCmd, brightnessSetCmd, brightnessGetCmd)
|
brightnessCmd.AddCommand(brightnessListCmd, brightnessSetCmd, brightnessGetCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runBrightnessList(cmd *cobra.Command, args []string) {
|
func getAllBrightnessDevices(includeDDC bool) []brightness.Device {
|
||||||
includeDDC, _ := cmd.Flags().GetBool("ddc")
|
|
||||||
|
|
||||||
allDevices := []brightness.Device{}
|
allDevices := []brightness.Device{}
|
||||||
|
|
||||||
sysfs, err := brightness.NewSysfsBackend()
|
sysfs, err := brightness.NewSysfsBackend()
|
||||||
@@ -138,6 +150,13 @@ func runBrightnessList(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return allDevices
|
||||||
|
}
|
||||||
|
|
||||||
|
func runBrightnessList(cmd *cobra.Command, args []string) {
|
||||||
|
includeDDC, _ := cmd.Flags().GetBool("ddc")
|
||||||
|
allDevices := getAllBrightnessDevices(includeDDC)
|
||||||
|
|
||||||
if len(allDevices) == 0 {
|
if len(allDevices) == 0 {
|
||||||
fmt.Println("No brightness devices found")
|
fmt.Println("No brightness devices found")
|
||||||
return
|
return
|
||||||
@@ -261,31 +280,20 @@ func runBrightnessSet(cmd *cobra.Command, args []string) {
|
|||||||
log.Fatalf("Failed to set brightness for device: %s", deviceID)
|
log.Fatalf("Failed to set brightness for device: %s", deviceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBrightnessDevices(includeDDC bool) []string {
|
||||||
|
allDevices := getAllBrightnessDevices(includeDDC)
|
||||||
|
|
||||||
|
var deviceIDs []string
|
||||||
|
for _, device := range allDevices {
|
||||||
|
deviceIDs = append(deviceIDs, device.ID)
|
||||||
|
}
|
||||||
|
return deviceIDs
|
||||||
|
}
|
||||||
|
|
||||||
func runBrightnessGet(cmd *cobra.Command, args []string) {
|
func runBrightnessGet(cmd *cobra.Command, args []string) {
|
||||||
deviceID := args[0]
|
deviceID := args[0]
|
||||||
includeDDC, _ := cmd.Flags().GetBool("ddc")
|
includeDDC, _ := cmd.Flags().GetBool("ddc")
|
||||||
|
allDevices := getAllBrightnessDevices(includeDDC)
|
||||||
allDevices := []brightness.Device{}
|
|
||||||
|
|
||||||
sysfs, err := brightness.NewSysfsBackend()
|
|
||||||
if err == nil {
|
|
||||||
devices, err := sysfs.GetDevices()
|
|
||||||
if err == nil {
|
|
||||||
allDevices = append(allDevices, devices...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if includeDDC {
|
|
||||||
ddc, err := brightness.NewDDCBackend()
|
|
||||||
if err == nil {
|
|
||||||
defer ddc.Close()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
devices, err := ddc.GetDevices()
|
|
||||||
if err == nil {
|
|
||||||
allDevices = append(allDevices, devices...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, device := range allDevices {
|
for _, device := range allDevices {
|
||||||
if device.ID == deviceID {
|
if device.ID == deviceID {
|
||||||
|
|||||||
@@ -119,6 +119,12 @@ var pluginsInstallCmd = &cobra.Command{
|
|||||||
Short: "Install a plugin by ID",
|
Short: "Install a plugin by ID",
|
||||||
Long: "Install a DMS plugin from the registry using its ID (e.g., 'myPlugin'). Plugin names with spaces are also supported for backward compatibility.",
|
Long: "Install a DMS plugin from the registry using its ID (e.g., 'myPlugin'). Plugin names with spaces are also supported for backward compatibility.",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
return getAvailablePluginIDs(), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if err := installPluginCLI(args[0]); err != nil {
|
if err := installPluginCLI(args[0]); err != nil {
|
||||||
log.Fatalf("Error installing plugin: %v", err)
|
log.Fatalf("Error installing plugin: %v", err)
|
||||||
@@ -131,6 +137,12 @@ var pluginsUninstallCmd = &cobra.Command{
|
|||||||
Short: "Uninstall a plugin by ID",
|
Short: "Uninstall a plugin by ID",
|
||||||
Long: "Uninstall a DMS plugin using its ID (e.g., 'myPlugin'). Plugin names with spaces are also supported for backward compatibility.",
|
Long: "Uninstall a DMS plugin using its ID (e.g., 'myPlugin'). Plugin names with spaces are also supported for backward compatibility.",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
return getInstalledPluginIDs(), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if err := uninstallPluginCLI(args[0]); err != nil {
|
if err := uninstallPluginCLI(args[0]); err != nil {
|
||||||
log.Fatalf("Error uninstalling plugin: %v", err)
|
log.Fatalf("Error uninstalling plugin: %v", err)
|
||||||
@@ -303,6 +315,38 @@ func installPluginCLI(idOrName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAvailablePluginIDs() []string {
|
||||||
|
registry, err := plugins.NewRegistry()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginList, err := registry.List()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var ids []string
|
||||||
|
for _, p := range pluginList {
|
||||||
|
ids = append(ids, p.ID)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
func getInstalledPluginIDs() []string {
|
||||||
|
manager, err := plugins.NewManager()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
installed, err := manager.ListInstalled()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return installed
|
||||||
|
}
|
||||||
|
|
||||||
func uninstallPluginCLI(idOrName string) error {
|
func uninstallPluginCLI(idOrName string) error {
|
||||||
manager, err := plugins.NewManager()
|
manager, err := plugins.NewManager()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ func init() {
|
|||||||
dank16Cmd.Flags().Bool("wezterm", false, "Output in Wezterm terminal format")
|
dank16Cmd.Flags().Bool("wezterm", false, "Output in Wezterm terminal format")
|
||||||
dank16Cmd.Flags().String("background", "", "Custom background color")
|
dank16Cmd.Flags().String("background", "", "Custom background color")
|
||||||
dank16Cmd.Flags().String("contrast", "dps", "Contrast algorithm: dps (Delta Phi Star, default) or wcag")
|
dank16Cmd.Flags().String("contrast", "dps", "Contrast algorithm: dps (Delta Phi Star, default) or wcag")
|
||||||
|
_ = dank16Cmd.RegisterFlagCompletionFunc("contrast", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return []string{"dps", "wcag"}, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDank16(cmd *cobra.Command, args []string) {
|
func runDank16(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -16,6 +16,12 @@ var dpmsOnCmd = &cobra.Command{
|
|||||||
Use: "on [output]",
|
Use: "on [output]",
|
||||||
Short: "Turn display(s) on",
|
Short: "Turn display(s) on",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
return getDPMSOutputs(), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
Run: runDPMSOn,
|
Run: runDPMSOn,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +29,12 @@ var dpmsOffCmd = &cobra.Command{
|
|||||||
Use: "off [output]",
|
Use: "off [output]",
|
||||||
Short: "Turn display(s) off",
|
Short: "Turn display(s) off",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
return getDPMSOutputs(), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
Run: runDPMSOff,
|
Run: runDPMSOff,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +83,15 @@ func runDPMSOff(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDPMSOutputs() []string {
|
||||||
|
client, err := newDPMSClient()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
return client.ListOutputs()
|
||||||
|
}
|
||||||
|
|
||||||
func runDPMSList(cmd *cobra.Command, args []string) {
|
func runDPMSList(cmd *cobra.Command, args []string) {
|
||||||
client, err := newDPMSClient()
|
client, err := newDPMSClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ var keybindsShowCmd = &cobra.Command{
|
|||||||
Short: "Show keybinds for a provider",
|
Short: "Show keybinds for a provider",
|
||||||
Long: "Display keybinds/cheatsheet for the specified provider",
|
Long: "Display keybinds/cheatsheet for the specified provider",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 0 {
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
registry := keybinds.GetDefaultRegistry()
|
||||||
|
return registry.List(), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
Run: runKeybindsShow,
|
Run: runKeybindsShow,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ func init() {
|
|||||||
openCmd.Flags().StringVar(&openMimeType, "mime", "", "MIME type for filtering applications")
|
openCmd.Flags().StringVar(&openMimeType, "mime", "", "MIME type for filtering applications")
|
||||||
openCmd.Flags().StringSliceVar(&openCategories, "category", []string{}, "Application categories to filter (e.g., WebBrowser, Office, Graphics)")
|
openCmd.Flags().StringSliceVar(&openCategories, "category", []string{}, "Application categories to filter (e.g., WebBrowser, Office, Graphics)")
|
||||||
openCmd.Flags().StringVar(&openRequestType, "type", "url", "Request type (url, file, or custom)")
|
openCmd.Flags().StringVar(&openRequestType, "type", "url", "Request type (url, file, or custom)")
|
||||||
|
_ = openCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return []string{"url", "file", "custom"}, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// mimeTypeToCategories maps MIME types to desktop file categories
|
// mimeTypeToCategories maps MIME types to desktop file categories
|
||||||
|
|||||||
Reference in New Issue
Block a user