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:
25
main.go
25
main.go
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user