lsns: updated to util-linux 2.41

This commit is contained in:
Saurabh Kushwah 2025-04-28 22:45:13 +05:30
parent a8245a8b7a
commit a784350647
No known key found for this signature in database
GPG Key ID: 8E11E1DCD6CCE8D5
2 changed files with 27 additions and 16 deletions

View File

@ -1,21 +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(
"NS", "namespace identifier (inode number)",
"TYPE", "kind of namespace",
"PATH", "path to the namespace",
"NPROCS", "number of processes in the namespace",
"PID", "lowest PID in the namespace",
"PPID", "PPID of the PID",
"COMMAND", "command line of the PID",
"UID", "UID of the PID",
"USER", "username of the PID",
"NETNSID", "namespace ID as used by network subsystem",
"NSFS", "nsfs mountpoint (usually used network subsystem)",
"PNS", "parent namespace identifier (inode number)",
"ONS", "owner namespace identifier (inode number)",
)
return carapace.ActionExecCommand("lsns", "--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,25 +17,33 @@ var rootCmd = &cobra.Command{
func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()
rootCmd.Flags().StringP("filter", "Q", "", "apply display filter")
rootCmd.Flags().BoolP("help", "h", false, "display this help")
rootCmd.Flags().BoolP("json", "J", false, "use JSON output format")
rootCmd.Flags().BoolP("list", "l", false, "use list format output")
rootCmd.Flags().BoolP("list-columns", "H", false, "list the available columns")
rootCmd.Flags().BoolP("noheadings", "n", false, "don't print headings")
rootCmd.Flags().BoolP("notruncate", "u", false, "don't truncate text in columns")
rootCmd.Flags().BoolP("nowrap", "W", false, "don't use multi-line representation")
rootCmd.Flags().StringP("output", "o", "", "define which output columns to use")
rootCmd.Flags().Bool("output-all", false, "output all columns")
rootCmd.Flags().BoolP("persistent", "P", false, "namespaces without processes")
rootCmd.Flags().BoolP("raw", "r", false, "use the raw output format")
rootCmd.Flags().StringP("task", "p", "", "print process namespaces")
rootCmd.Flags().StringP("tree", "T", "", "use tree format (parent, owner, or process)")
rootCmd.Flags().StringP("type", "t", "", "namespace type (mnt, net, ipc, user, pid, uts, cgroup, time)")
rootCmd.Flags().BoolP("version", "V", false, "display version")
rootCmd.Flag("tree").NoOptDefVal = " "
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"output": action.ActionColumns().UniqueList(","),
"task": ps.ActionProcessIds(),
"tree": carapace.ActionValues("parent", "owner", "process"),
"type": carapace.ActionValues("mnt", "net", "ipc", "user", "pid", "uts", "cgroup", "time"),
})
}