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 53b5d89
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
20 changes: 20 additions & 0 deletions completers/light_completer/cmd/action/device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package action

import (
"strings"

"github.com/rsteube/carapace"
)

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...)
})
}
46 changes: 46 additions & 0 deletions completers/light_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/light_completer/cmd/action"
"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": action.ActionDevices(),
"v": carapace.ActionValuesDescribed(
"0", "Values only",
"1", "Values, Errors",
"2", "Values, Errors, Warnings",
"3", "Values, Errors, Warnings, Notices",
),
})
}
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 53b5d89

Please sign in to comment.