1
0
mirror of https://github.com/pcvolkmer/docker-pps.git synced 2025-12-17 01:43:21 +00:00

Replace flag with github.com/spf13/pflag

This commit is contained in:
2022-02-19 15:46:01 +01:00
parent 9373657fb7
commit 5495ecc95a
3 changed files with 480 additions and 29 deletions

25
main.go
View File

@@ -2,11 +2,13 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"strings"
flag "github.com/spf13/pflag"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
@@ -24,17 +26,32 @@ var (
q *bool
h *string
uids *string
help *bool
)
func init() {
q = flag.Bool("q", false, "Only display process IDs")
h = flag.String("host", "", "Container host")
uids = flag.String("uid", "", "Only display processes for Username/UID(s)")
q = flag.BoolP("quiet", "q", false, "Only display process IDs")
h = flag.StringP("host", "h", "", "Container `host`")
uids = flag.String("uid", "", "Only display processes for `user`name/UID(s)")
help = flag.Bool("help", false, "Show this help text")
}
func main() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "\nUsage: docker-pps [OPTIONS]\n\nShow list of Processes running in docker containers\n\nOptions:")
flag.PrintDefaults()
}
flag.CommandLine.MarkHidden("help")
flag.CommandLine.SortFlags = false
flag.Parse()
if *help {
flag.Usage()
return
}
var opts []client.Opt
if *h != "" {
opts = append(opts, client.WithHost(*h))