mirror of
https://github.com/rsteube/carapace-bin.git
synced 2025-05-05 23:42:54 +00:00
lsns: updated to util-linux 2.41
This commit is contained in:
parent
a8245a8b7a
commit
a784350647
@ -1,21 +1,24 @@
|
|||||||
package action
|
package action
|
||||||
|
|
||||||
import "github.com/carapace-sh/carapace"
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/carapace-sh/carapace"
|
||||||
|
)
|
||||||
|
|
||||||
func ActionColumns() carapace.Action {
|
func ActionColumns() carapace.Action {
|
||||||
return carapace.ActionValuesDescribed(
|
return carapace.ActionExecCommand("lsns", "--list-columns")(func(output []byte) carapace.Action {
|
||||||
"NS", "namespace identifier (inode number)",
|
re := regexp.MustCompile(`^\s*(\S+)\s+<[^>]+>\s+(.*)$`)
|
||||||
"TYPE", "kind of namespace",
|
var values []string
|
||||||
"PATH", "path to the namespace",
|
|
||||||
"NPROCS", "number of processes in the namespace",
|
for _, line := range strings.Split(string(output), "\n") {
|
||||||
"PID", "lowest PID in the namespace",
|
if matches := re.FindStringSubmatch(line); len(matches) == 3 {
|
||||||
"PPID", "PPID of the PID",
|
name, description := matches[1], matches[2]
|
||||||
"COMMAND", "command line of the PID",
|
values = append(values, name, description)
|
||||||
"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)",
|
return carapace.ActionValuesDescribed(values...)
|
||||||
"PNS", "parent namespace identifier (inode number)",
|
})
|
||||||
"ONS", "owner namespace identifier (inode number)",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
@ -17,25 +17,33 @@ var rootCmd = &cobra.Command{
|
|||||||
func Execute() error {
|
func Execute() error {
|
||||||
return rootCmd.Execute()
|
return rootCmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
carapace.Gen(rootCmd).Standalone()
|
carapace.Gen(rootCmd).Standalone()
|
||||||
|
|
||||||
|
rootCmd.Flags().StringP("filter", "Q", "", "apply display filter")
|
||||||
rootCmd.Flags().BoolP("help", "h", false, "display this help")
|
rootCmd.Flags().BoolP("help", "h", false, "display this help")
|
||||||
rootCmd.Flags().BoolP("json", "J", false, "use JSON output format")
|
rootCmd.Flags().BoolP("json", "J", false, "use JSON output format")
|
||||||
rootCmd.Flags().BoolP("list", "l", false, "use list format output")
|
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("noheadings", "n", false, "don't print headings")
|
||||||
rootCmd.Flags().BoolP("notruncate", "u", false, "don't truncate text in columns")
|
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().BoolP("nowrap", "W", false, "don't use multi-line representation")
|
||||||
rootCmd.Flags().StringP("output", "o", "", "define which output columns to use")
|
rootCmd.Flags().StringP("output", "o", "", "define which output columns to use")
|
||||||
rootCmd.Flags().Bool("output-all", false, "output all columns")
|
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().BoolP("raw", "r", false, "use the raw output format")
|
||||||
rootCmd.Flags().StringP("task", "p", "", "print process namespaces")
|
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().StringP("type", "t", "", "namespace type (mnt, net, ipc, user, pid, uts, cgroup, time)")
|
||||||
rootCmd.Flags().BoolP("version", "V", false, "display version")
|
rootCmd.Flags().BoolP("version", "V", false, "display version")
|
||||||
|
|
||||||
|
rootCmd.Flag("tree").NoOptDefVal = " "
|
||||||
|
|
||||||
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
|
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
|
||||||
"output": action.ActionColumns().UniqueList(","),
|
"output": action.ActionColumns().UniqueList(","),
|
||||||
"task": ps.ActionProcessIds(),
|
"task": ps.ActionProcessIds(),
|
||||||
|
"tree": carapace.ActionValues("parent", "owner", "process"),
|
||||||
"type": carapace.ActionValues("mnt", "net", "ipc", "user", "pid", "uts", "cgroup", "time"),
|
"type": carapace.ActionValues("mnt", "net", "ipc", "user", "pid", "uts", "cgroup", "time"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user