Added lsclocks completer

This commit is contained in:
Saurabh Kushwah 2025-04-28 21:20:20 +05:30
parent 2e2672f678
commit 529beb6193
No known key found for this signature in database
GPG Key ID: 8E11E1DCD6CCE8D5
3 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package action
import (
"strings"
"github.com/carapace-sh/carapace"
)
func ActionColumns() carapace.Action {
return carapace.ActionValuesDescribed(
"TYPE", "type",
"ID", "numeric id",
"CLOCK", "symbolic name",
"NAME", "readable name",
"TIME", "numeric time",
"ISO_TIME", "human readable ISO time",
"RESOL", "human readable resolution",
"RESOL_RAW", "resolution",
"REL_TIME", "human readable relative time",
"NS_OFFSET", "namespace offset",
)
}
func ActionClocks() carapace.Action {
return carapace.ActionExecCommand("lsclocks", "--output", "CLOCK")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
return carapace.ActionValues(lines[1:]...)
})
}

View File

@ -0,0 +1,42 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/lsclocks_completer/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/actions/ps"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "lsclocks",
Short: "display system clocks",
Long: "https://man7.org/linux/man-pages/man1/lsclocks.1.html",
Run: func(cmd *cobra.Command, args []string) {},
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().StringP("cpu-clock", "c", "", "also display CPU clock of specified process")
rootCmd.Flags().StringP("dynamic-clock", "d", "", "also display specified dynamic clock")
rootCmd.Flags().BoolP("help", "h", false, "display this help")
rootCmd.Flags().BoolP("json", "J", false, "use JSON output format")
rootCmd.Flags().Bool("no-discover-dynamic", false, "do not try to discover dynamic clocks")
rootCmd.Flags().BoolP("noheadings", "n", false, "don't print headings")
rootCmd.Flags().StringP("output", "o", "", "output columns")
rootCmd.Flags().Bool("output-all", false, "output all columns")
rootCmd.Flags().BoolP("raw", "r", false, "use raw output format")
rootCmd.Flags().StringP("time", "t", "", "show current time of single clock")
rootCmd.Flags().BoolP("version", "V", false, "display version")
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"cpu-clock": ps.ActionProcessIds(),
"dynamic-clock": carapace.ActionFiles(),
"output": action.ActionColumns().UniqueList(","),
"time": action.ActionClocks(),
})
}

View File

@ -0,0 +1,7 @@
package main
import "github.com/carapace-sh/carapace-bin/completers/lsclocks_completer/cmd"
func main() {
cmd.Execute()
}