2013-07-15 02:16:30 +00:00
|
|
|
package cli
|
|
|
|
|
2013-12-07 15:10:04 +00:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2014-07-11 17:29:56 +00:00
|
|
|
"os"
|
2013-12-07 15:10:04 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2014-08-02 21:32:32 +00:00
|
|
|
"time"
|
2013-12-07 15:10:04 +00:00
|
|
|
)
|
2013-07-15 02:16:30 +00:00
|
|
|
|
2014-04-12 13:32:53 +00:00
|
|
|
// This flag enables bash-completion for all commands and subcommands
|
2014-07-11 22:13:10 +00:00
|
|
|
var BashCompletionFlag = BoolFlag{
|
|
|
|
Name: "generate-bash-completion",
|
|
|
|
}
|
2014-04-12 13:32:53 +00:00
|
|
|
|
2014-04-29 14:21:19 +00:00
|
|
|
// This flag prints the version for the application
|
2014-07-11 22:13:10 +00:00
|
|
|
var VersionFlag = BoolFlag{
|
|
|
|
Name: "version, v",
|
|
|
|
Usage: "print the version",
|
|
|
|
}
|
2014-04-29 14:21:19 +00:00
|
|
|
|
|
|
|
// This flag prints the help for all commands and subcommands
|
2014-07-11 22:13:10 +00:00
|
|
|
var HelpFlag = BoolFlag{
|
|
|
|
Name: "help, h",
|
|
|
|
Usage: "show help",
|
|
|
|
}
|
2014-04-29 14:21:19 +00:00
|
|
|
|
2013-11-01 14:31:37 +00:00
|
|
|
// Flag is a common interface related to parsing flags in cli.
|
|
|
|
// For more advanced flag parsing techniques, it is recomended that
|
|
|
|
// this interface be implemented.
|
2013-07-15 02:16:30 +00:00
|
|
|
type Flag interface {
|
2013-07-19 00:39:42 +00:00
|
|
|
fmt.Stringer
|
2013-11-01 14:31:37 +00:00
|
|
|
// Apply Flag settings to the given flag set
|
2013-07-19 00:39:42 +00:00
|
|
|
Apply(*flag.FlagSet)
|
2013-11-21 01:24:37 +00:00
|
|
|
getName() string
|
2013-07-19 00:39:42 +00:00
|
|
|
}
|
|
|
|
|
2013-07-20 15:21:20 +00:00
|
|
|
func flagSet(name string, flags []Flag) *flag.FlagSet {
|
2013-07-24 14:35:45 +00:00
|
|
|
set := flag.NewFlagSet(name, flag.ContinueOnError)
|
2013-09-24 01:41:31 +00:00
|
|
|
|
2013-07-19 00:39:42 +00:00
|
|
|
for _, f := range flags {
|
|
|
|
f.Apply(set)
|
|
|
|
}
|
|
|
|
return set
|
2013-07-15 02:16:30 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 08:05:18 +00:00
|
|
|
func eachName(longName string, fn func(string)) {
|
|
|
|
parts := strings.Split(longName, ",")
|
|
|
|
for _, name := range parts {
|
|
|
|
name = strings.Trim(name, " ")
|
|
|
|
fn(name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 14:16:47 +00:00
|
|
|
// Generic is a generic parseable type identified by a specific flag
|
|
|
|
type Generic interface {
|
|
|
|
Set(value string) error
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// GenericFlag is the flag type for types implementing Generic
|
|
|
|
type GenericFlag struct {
|
2014-07-11 17:29:56 +00:00
|
|
|
Name string
|
|
|
|
Value Generic
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
2014-04-15 14:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f GenericFlag) String() string {
|
2014-07-11 17:29:56 +00:00
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf("%s%s %v\t`%v` %s", prefixFor(f.Name), f.Name, f.Value, "-"+f.Name+" option -"+f.Name+" option", f.Usage))
|
2014-04-15 14:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f GenericFlag) Apply(set *flag.FlagSet) {
|
2014-07-11 17:29:56 +00:00
|
|
|
val := f.Value
|
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
val.Set(envVal)
|
|
|
|
break
|
|
|
|
}
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 14:16:47 +00:00
|
|
|
eachName(f.Name, func(name string) {
|
|
|
|
set.Var(f.Value, name, f.Usage)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f GenericFlag) getName() string {
|
|
|
|
return f.Name
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:41:31 +00:00
|
|
|
type StringSlice []string
|
|
|
|
|
2013-09-24 19:36:01 +00:00
|
|
|
func (f *StringSlice) Set(value string) error {
|
|
|
|
*f = append(*f, value)
|
2013-09-24 01:41:31 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-09-24 19:36:01 +00:00
|
|
|
func (f *StringSlice) String() string {
|
|
|
|
return fmt.Sprintf("%s", *f)
|
2013-09-24 01:41:31 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 19:36:01 +00:00
|
|
|
func (f *StringSlice) Value() []string {
|
|
|
|
return *f
|
2013-09-24 01:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type StringSliceFlag struct {
|
2014-07-11 17:29:56 +00:00
|
|
|
Name string
|
|
|
|
Value *StringSlice
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
2013-09-24 01:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f StringSliceFlag) String() string {
|
2014-04-17 08:42:55 +00:00
|
|
|
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
|
|
|
|
pref := prefixFor(firstName)
|
2014-07-11 17:29:56 +00:00
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
|
2013-09-24 01:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
|
2014-07-11 17:29:56 +00:00
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
newVal := &StringSlice{}
|
|
|
|
for _, s := range strings.Split(envVal, ",") {
|
|
|
|
s = strings.TrimSpace(s)
|
|
|
|
newVal.Set(s)
|
|
|
|
}
|
|
|
|
f.Value = newVal
|
|
|
|
break
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 08:05:18 +00:00
|
|
|
eachName(f.Name, func(name string) {
|
2013-11-18 23:35:23 +00:00
|
|
|
set.Var(f.Value, name, f.Usage)
|
2013-11-20 08:05:18 +00:00
|
|
|
})
|
2013-11-18 23:35:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 01:24:37 +00:00
|
|
|
func (f StringSliceFlag) getName() string {
|
2013-11-18 23:35:23 +00:00
|
|
|
return f.Name
|
2013-09-24 01:41:31 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 19:36:01 +00:00
|
|
|
type IntSlice []int
|
|
|
|
|
|
|
|
func (f *IntSlice) Set(value string) error {
|
|
|
|
|
|
|
|
tmp, err := strconv.Atoi(value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
*f = append(*f, tmp)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *IntSlice) String() string {
|
|
|
|
return fmt.Sprintf("%d", *f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *IntSlice) Value() []int {
|
|
|
|
return *f
|
|
|
|
}
|
|
|
|
|
|
|
|
type IntSliceFlag struct {
|
2014-07-11 17:29:56 +00:00
|
|
|
Name string
|
|
|
|
Value *IntSlice
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
2013-09-24 19:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f IntSliceFlag) String() string {
|
2013-11-20 08:05:18 +00:00
|
|
|
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
|
|
|
|
pref := prefixFor(firstName)
|
2014-07-11 17:29:56 +00:00
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
|
2013-09-24 19:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
2014-07-11 17:29:56 +00:00
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
newVal := &IntSlice{}
|
|
|
|
for _, s := range strings.Split(envVal, ",") {
|
|
|
|
s = strings.TrimSpace(s)
|
|
|
|
err := newVal.Set(s)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, err.Error())
|
|
|
|
}
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
2014-09-23 03:24:08 +00:00
|
|
|
f.Value = newVal
|
|
|
|
break
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 08:05:18 +00:00
|
|
|
eachName(f.Name, func(name string) {
|
2013-11-18 23:35:23 +00:00
|
|
|
set.Var(f.Value, name, f.Usage)
|
2013-11-20 08:05:18 +00:00
|
|
|
})
|
2013-11-18 23:35:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 01:24:37 +00:00
|
|
|
func (f IntSliceFlag) getName() string {
|
2013-11-18 23:35:23 +00:00
|
|
|
return f.Name
|
2013-09-24 19:36:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 02:16:30 +00:00
|
|
|
type BoolFlag struct {
|
2014-07-11 17:29:56 +00:00
|
|
|
Name string
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
2013-07-19 00:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f BoolFlag) String() string {
|
2014-07-11 17:29:56 +00:00
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage))
|
2013-07-19 00:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f BoolFlag) Apply(set *flag.FlagSet) {
|
2014-07-11 17:29:56 +00:00
|
|
|
val := false
|
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
envValBool, err := strconv.ParseBool(envVal)
|
|
|
|
if err == nil {
|
|
|
|
val = envValBool
|
|
|
|
}
|
|
|
|
break
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 08:05:18 +00:00
|
|
|
eachName(f.Name, func(name string) {
|
2014-07-11 17:29:56 +00:00
|
|
|
set.Bool(name, val, f.Usage)
|
2013-11-20 08:05:18 +00:00
|
|
|
})
|
2013-11-18 23:35:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 01:24:37 +00:00
|
|
|
func (f BoolFlag) getName() string {
|
2013-11-18 23:35:23 +00:00
|
|
|
return f.Name
|
2013-07-15 02:16:30 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 01:24:22 +00:00
|
|
|
type BoolTFlag struct {
|
2014-07-11 17:29:56 +00:00
|
|
|
Name string
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
2014-03-06 01:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f BoolTFlag) String() string {
|
2014-07-11 17:29:56 +00:00
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage))
|
2014-03-06 01:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f BoolTFlag) Apply(set *flag.FlagSet) {
|
2014-07-11 17:29:56 +00:00
|
|
|
val := true
|
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
envValBool, err := strconv.ParseBool(envVal)
|
|
|
|
if err == nil {
|
|
|
|
val = envValBool
|
|
|
|
break
|
|
|
|
}
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:24:22 +00:00
|
|
|
eachName(f.Name, func(name string) {
|
2014-07-11 17:29:56 +00:00
|
|
|
set.Bool(name, val, f.Usage)
|
2014-03-06 01:24:22 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f BoolTFlag) getName() string {
|
|
|
|
return f.Name
|
|
|
|
}
|
|
|
|
|
2013-07-15 02:16:30 +00:00
|
|
|
type StringFlag struct {
|
2014-07-11 17:29:56 +00:00
|
|
|
Name string
|
|
|
|
Value string
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
2013-07-15 02:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f StringFlag) String() string {
|
2014-04-11 19:09:59 +00:00
|
|
|
var fmtString string
|
|
|
|
fmtString = "%s %v\t%v"
|
|
|
|
|
|
|
|
if len(f.Value) > 0 {
|
|
|
|
fmtString = "%s '%v'\t%v"
|
|
|
|
} else {
|
|
|
|
fmtString = "%s %v\t%v"
|
|
|
|
}
|
|
|
|
|
2014-07-11 17:29:56 +00:00
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf(fmtString, prefixedNames(f.Name), f.Value, f.Usage))
|
2013-07-15 02:16:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 02:59:04 +00:00
|
|
|
func (f StringFlag) Apply(set *flag.FlagSet) {
|
2014-07-11 17:29:56 +00:00
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
f.Value = envVal
|
|
|
|
break
|
|
|
|
}
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 08:05:18 +00:00
|
|
|
eachName(f.Name, func(name string) {
|
2013-11-18 23:35:23 +00:00
|
|
|
set.String(name, f.Value, f.Usage)
|
2013-11-20 08:05:18 +00:00
|
|
|
})
|
2013-11-18 23:35:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 01:24:37 +00:00
|
|
|
func (f StringFlag) getName() string {
|
2013-11-18 23:35:23 +00:00
|
|
|
return f.Name
|
2013-07-17 02:59:04 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 00:39:42 +00:00
|
|
|
type IntFlag struct {
|
2014-07-11 17:29:56 +00:00
|
|
|
Name string
|
|
|
|
Value int
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
2013-07-15 02:16:30 +00:00
|
|
|
}
|
2013-07-17 02:59:04 +00:00
|
|
|
|
2013-07-19 00:39:42 +00:00
|
|
|
func (f IntFlag) String() string {
|
2014-07-11 17:29:56 +00:00
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
2013-07-17 02:59:04 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 00:39:42 +00:00
|
|
|
func (f IntFlag) Apply(set *flag.FlagSet) {
|
2014-07-11 17:29:56 +00:00
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
envValInt, err := strconv.ParseUint(envVal, 10, 64)
|
|
|
|
if err == nil {
|
|
|
|
f.Value = int(envValInt)
|
|
|
|
break
|
|
|
|
}
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 08:05:18 +00:00
|
|
|
eachName(f.Name, func(name string) {
|
2013-11-18 23:35:23 +00:00
|
|
|
set.Int(name, f.Value, f.Usage)
|
2013-11-20 08:05:18 +00:00
|
|
|
})
|
2013-11-18 23:35:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 01:24:37 +00:00
|
|
|
func (f IntFlag) getName() string {
|
2013-11-18 23:35:23 +00:00
|
|
|
return f.Name
|
2013-07-17 02:59:04 +00:00
|
|
|
}
|
2013-07-24 14:35:45 +00:00
|
|
|
|
2014-08-02 21:32:32 +00:00
|
|
|
type DurationFlag struct {
|
|
|
|
Name string
|
|
|
|
Value time.Duration
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f DurationFlag) String() string {
|
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f DurationFlag) Apply(set *flag.FlagSet) {
|
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
envValDuration, err := time.ParseDuration(envVal)
|
|
|
|
if err == nil {
|
|
|
|
f.Value = envValDuration
|
|
|
|
break
|
|
|
|
}
|
2014-08-02 21:32:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eachName(f.Name, func(name string) {
|
|
|
|
set.Duration(name, f.Value, f.Usage)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f DurationFlag) getName() string {
|
|
|
|
return f.Name
|
|
|
|
}
|
|
|
|
|
2013-12-03 13:42:09 +00:00
|
|
|
type Float64Flag struct {
|
2014-07-11 17:29:56 +00:00
|
|
|
Name string
|
|
|
|
Value float64
|
|
|
|
Usage string
|
|
|
|
EnvVar string
|
2013-12-03 13:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f Float64Flag) String() string {
|
2014-07-11 17:29:56 +00:00
|
|
|
return withEnvHint(f.EnvVar, fmt.Sprintf("%s '%v'\t%v", prefixedNames(f.Name), f.Value, f.Usage))
|
2013-12-03 13:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
2014-07-11 17:29:56 +00:00
|
|
|
if f.EnvVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
|
|
|
envVar = strings.TrimSpace(envVar)
|
|
|
|
if envVal := os.Getenv(envVar); envVal != "" {
|
|
|
|
envValFloat, err := strconv.ParseFloat(envVal, 10)
|
|
|
|
if err == nil {
|
|
|
|
f.Value = float64(envValFloat)
|
|
|
|
}
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 13:42:09 +00:00
|
|
|
eachName(f.Name, func(name string) {
|
|
|
|
set.Float64(name, f.Value, f.Usage)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f Float64Flag) getName() string {
|
|
|
|
return f.Name
|
|
|
|
}
|
|
|
|
|
2013-09-09 18:51:46 +00:00
|
|
|
func prefixFor(name string) (prefix string) {
|
|
|
|
if len(name) == 1 {
|
|
|
|
prefix = "-"
|
|
|
|
} else {
|
|
|
|
prefix = "--"
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2013-11-20 08:05:18 +00:00
|
|
|
|
|
|
|
func prefixedNames(fullName string) (prefixed string) {
|
|
|
|
parts := strings.Split(fullName, ",")
|
|
|
|
for i, name := range parts {
|
|
|
|
name = strings.Trim(name, " ")
|
|
|
|
prefixed += prefixFor(name) + name
|
2013-11-21 01:25:13 +00:00
|
|
|
if i < len(parts)-1 {
|
2013-11-20 08:05:18 +00:00
|
|
|
prefixed += ", "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2014-07-11 17:29:56 +00:00
|
|
|
|
|
|
|
func withEnvHint(envVar, str string) string {
|
|
|
|
envText := ""
|
|
|
|
if envVar != "" {
|
2014-09-23 03:24:08 +00:00
|
|
|
envText = fmt.Sprintf(" [$%s]", strings.Join(strings.Split(envVar, ","), ", $"))
|
2014-07-11 17:29:56 +00:00
|
|
|
}
|
|
|
|
return str + envText
|
|
|
|
}
|