Skip to content

Commit

Permalink
added light
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 4, 2022
1 parent a4bd251 commit b4953bb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
60 changes: 60 additions & 0 deletions completers/light_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cmd

import (
"strings"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "light",
Short: "a program to control backlight controllers",
Long: "https://github.com/haikarainen/light",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().StringS("A", "A", "", "Increase brightness by value")
rootCmd.Flags().BoolS("G", "G", false, "Get brightness")
rootCmd.Flags().BoolS("I", "I", false, "Restore the previously saved brightness")
rootCmd.Flags().BoolS("L", "L", false, "List available devices")
rootCmd.Flags().BoolS("N", "N", false, "Set minimum brightness to value")
rootCmd.Flags().BoolS("O", "O", false, "Save the current brightness")
rootCmd.Flags().BoolS("P", "P", false, "Get minimum brightness")
rootCmd.Flags().StringS("S", "S", "", "Set brightness to value")
rootCmd.Flags().StringS("T", "T", "", "Multiply brightness by value")
rootCmd.Flags().StringS("U", "U", "", "Decrease brightness by value")
rootCmd.Flags().BoolS("V", "V", false, "Show program version and exit")
rootCmd.Flags().BoolS("r", "r", false, "Interpret input and output values in raw mode")
rootCmd.Flags().StringS("s", "s", "", "Specify device target path to use")
rootCmd.Flags().StringS("v", "v", "", "Specify the verbosity level")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"s": ActionDevices(),
"v": carapace.ActionValuesDescribed(
"0", "Values only",
"1", "Values, Errors",
"2", "Values, Errors, Warnings",
"3", "Values, Errors, Warnings, Notices",
),
})
}

func ActionDevices() carapace.Action {
return carapace.ActionExecCommand("light", "-L")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")

vals := make([]string, 0)
for _, line := range lines[1 : len(lines)-1] {
vals = append(vals, strings.TrimSpace(line))
}

return carapace.ActionValues(vals...)
})
}
7 changes: 7 additions & 0 deletions completers/light_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/rsteube/carapace-bin/completers/light_completer/cmd"

func main() {
cmd.Execute()
}

0 comments on commit b4953bb

Please sign in to comment.