-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |