...

Source file src/cmd/vendor/github.com/google/pprof/internal/driver/flags.go

     1	//  Copyright 2018 Google Inc. All Rights Reserved.
     2	//
     3	//  Licensed under the Apache License, Version 2.0 (the "License");
     4	//  you may not use this file except in compliance with the License.
     5	//  You may obtain a copy of the License at
     6	//
     7	//      http://www.apache.org/licenses/LICENSE-2.0
     8	//
     9	//  Unless required by applicable law or agreed to in writing, software
    10	//  distributed under the License is distributed on an "AS IS" BASIS,
    11	//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12	//  See the License for the specific language governing permissions and
    13	//  limitations under the License.
    14	
    15	package driver
    16	
    17	import (
    18		"flag"
    19		"strings"
    20	)
    21	
    22	// GoFlags implements the plugin.FlagSet interface.
    23	type GoFlags struct {
    24		UsageMsgs []string
    25	}
    26	
    27	// Bool implements the plugin.FlagSet interface.
    28	func (*GoFlags) Bool(o string, d bool, c string) *bool {
    29		return flag.Bool(o, d, c)
    30	}
    31	
    32	// Int implements the plugin.FlagSet interface.
    33	func (*GoFlags) Int(o string, d int, c string) *int {
    34		return flag.Int(o, d, c)
    35	}
    36	
    37	// Float64 implements the plugin.FlagSet interface.
    38	func (*GoFlags) Float64(o string, d float64, c string) *float64 {
    39		return flag.Float64(o, d, c)
    40	}
    41	
    42	// String implements the plugin.FlagSet interface.
    43	func (*GoFlags) String(o, d, c string) *string {
    44		return flag.String(o, d, c)
    45	}
    46	
    47	// BoolVar implements the plugin.FlagSet interface.
    48	func (*GoFlags) BoolVar(b *bool, o string, d bool, c string) {
    49		flag.BoolVar(b, o, d, c)
    50	}
    51	
    52	// IntVar implements the plugin.FlagSet interface.
    53	func (*GoFlags) IntVar(i *int, o string, d int, c string) {
    54		flag.IntVar(i, o, d, c)
    55	}
    56	
    57	// Float64Var implements the plugin.FlagSet interface.
    58	// the value of the flag.
    59	func (*GoFlags) Float64Var(f *float64, o string, d float64, c string) {
    60		flag.Float64Var(f, o, d, c)
    61	}
    62	
    63	// StringVar implements the plugin.FlagSet interface.
    64	func (*GoFlags) StringVar(s *string, o, d, c string) {
    65		flag.StringVar(s, o, d, c)
    66	}
    67	
    68	// StringList implements the plugin.FlagSet interface.
    69	func (*GoFlags) StringList(o, d, c string) *[]*string {
    70		return &[]*string{flag.String(o, d, c)}
    71	}
    72	
    73	// ExtraUsage implements the plugin.FlagSet interface.
    74	func (f *GoFlags) ExtraUsage() string {
    75		return strings.Join(f.UsageMsgs, "\n")
    76	}
    77	
    78	// AddExtraUsage implements the plugin.FlagSet interface.
    79	func (f *GoFlags) AddExtraUsage(eu string) {
    80		f.UsageMsgs = append(f.UsageMsgs, eu)
    81	}
    82	
    83	// Parse implements the plugin.FlagSet interface.
    84	func (*GoFlags) Parse(usage func()) []string {
    85		flag.Usage = usage
    86		flag.Parse()
    87		args := flag.Args()
    88		if len(args) == 0 {
    89			usage()
    90		}
    91		return args
    92	}
    93	

View as plain text