lslocks: updated to util-linux 2.41

This commit is contained in:
Saurabh Kushwah 2025-04-28 18:41:33 +05:30
parent b6a7fb6603
commit 2e2672f678
No known key found for this signature in database
GPG Key ID: 8E11E1DCD6CCE8D5
2 changed files with 21 additions and 13 deletions

View File

@ -1,18 +1,24 @@
package action
import "github.com/carapace-sh/carapace"
import (
"regexp"
"strings"
"github.com/carapace-sh/carapace"
)
func ActionColumns() carapace.Action {
return carapace.ActionValuesDescribed(
"COMMAND", "command of the process holding the lock",
"PID", "PID of the process holding the lock",
"TYPE", "kind of lock",
"SIZE", "size of the lock",
"MODE", "lock access mode",
"M", "mandatory state of the lock: 0 (none), 1 (set)",
"START", "relative byte offset of the lock",
"END", "ending offset of the lock",
"PATH", "path of the locked file",
"BLOCKER", "PID of the process blocking the lock",
)
return carapace.ActionExecCommand("lslocks", "--list-columns")(func(output []byte) carapace.Action {
re := regexp.MustCompile(`^\s*(\S+)\s+<[^>]+>\s+(.*)$`)
var values []string
for _, line := range strings.Split(string(output), "\n") {
if matches := re.FindStringSubmatch(line); len(matches) == 3 {
name, description := matches[1], matches[2]
values = append(values, name, description)
}
}
return carapace.ActionValuesDescribed(values...)
})
}

View File

@ -17,12 +17,14 @@ var rootCmd = &cobra.Command{
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().BoolP("bytes", "b", false, "print SIZE in bytes rather than in human readable format")
rootCmd.Flags().BoolP("help", "h", false, "display this help")
rootCmd.Flags().BoolP("json", "J", false, "use JSON output format")
rootCmd.Flags().BoolP("list-columns", "H", false, "list the available columns")
rootCmd.Flags().BoolP("noheadings", "n", false, "don't print headings")
rootCmd.Flags().BoolP("noinaccessible", "i", false, "ignore locks without read permissions")
rootCmd.Flags().BoolP("notruncate", "u", false, "don't truncate text in columns")