Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions command/cmdHelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,34 @@ func (cmd *HelpCommand) Apply(m *manager.Manager) error {
<none>

init
-r|--reset (bool) [optional = false]
-r|-reset (bool) [optional = false]

dump
-k|--kind (string) [required]
-k|-kind (string) [required]
config, remote, system

update
-t|--timeout (duration) [optional = 5*time.Second]
-t|-timeout (duration) [optional = 5*time.Second]

ls
-r|--regex (bool) [optional = false]
-f|--format (string) [optional = json]
-r|-regex (bool) [optional = false]
-f|-format (string) [optional = json]
json, consul, env, telegraf
-p|--pick (string) [optional = ""]
-o|--omit (string) [optional = ""]
-p|-pick (string) [optional = ""]
-o|-omit (string) [optional = ""]
-e|-prefix (string) [optional = ""]
-u|-suffix (string) [optional = ""]

get
-k|--key (string) [required]
-d|--default (string) [optional = ""]
-k|-key (string) [required]
-d|-default (string) [optional = ""]

set
-k|--key (string) [required]
-v|--value (string) [required]
-k|-key (string) [required]
-v|-value (string) [required]

rm
-k|--key (string) [required]
-k|-key (string) [required]

version
<none>
Expand Down
10 changes: 10 additions & 0 deletions command/cmdLs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type LsCommand struct {
pick string
omit string
format string
prefix string
suffix string
}

func NewLsCommand() *LsCommand {
Expand All @@ -31,6 +33,10 @@ func NewLsCommand() *LsCommand {
cmd.flagSet.StringVar(&cmd.omit, "omit", "", "")
cmd.flagSet.StringVar(&cmd.format, "f", "json", "")
cmd.flagSet.StringVar(&cmd.format, "format", "json", "")
cmd.flagSet.StringVar(&cmd.prefix, "e", "", "")
cmd.flagSet.StringVar(&cmd.prefix, "prefix", "", "")
cmd.flagSet.StringVar(&cmd.suffix, "u", "", "")
cmd.flagSet.StringVar(&cmd.suffix, "suffix", "", "")

// Don't print unneeded usage
cmd.flagSet.Usage = func() {}
Expand Down Expand Up @@ -67,6 +73,10 @@ func (cmd *LsCommand) Apply(m *manager.Manager) error {

tags := m.GetTags(cmd.regex, cmd.pick, cmd.omit)

// Append prefixes or suffixes to keys
tags = m.PrefixTags(tags, cmd.prefix)
tags = m.SuffixTags(tags, cmd.suffix)

// Retrieve the specified format method
format, _ := manager.Formats[cmd.format]

Expand Down
34 changes: 34 additions & 0 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,37 @@ func (m *Manager) RemoveTag(key string) string {
delete(m.system, key)
return existing
}

// PrefixTags returns new tags based on the specified
// tags but with each key prepended with prefix string
func (m *Manager) PrefixTags(tags Tags, prefix string) Tags {

if prefix == "" {
return tags
}

result := make(Tags)
// Loop through specified tags
for key, value := range tags {
result[prefix+key] = value
}

return result
}

// SuffixTags returns new tags based on the specified
// tags but with each key appended with suffix string
func (m *Manager) SuffixTags(tags Tags, suffix string) Tags {

if suffix == "" {
return tags
}

result := make(Tags)
// Loop through specified tags
for key, value := range tags {
result[key+suffix] = value
}

return result
}