Skip to content

Commit 53791bc

Browse files
committed
[OCONF-184] Updates on code structure
1 parent bfc7a65 commit 53791bc

1 file changed

Lines changed: 13 additions & 30 deletions

File tree

coconut/configuration/configuration.go

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func History(cfg *configuration.ConsulSource, cmd *cobra.Command, args []string,
301301
return errors.New(fmt.Sprintf("Component and Entry name cannot contain `/ or `@`")), invalidArgs
302302
}
303303
}
304+
304305
key = componentsPath + component + "/" + entry
305306
var keys sort.StringSlice
306307
keys , err = cfg.GetKeysByPrefix(key, "")
@@ -314,18 +315,18 @@ func History(cfg *configuration.ConsulSource, cmd *cobra.Command, args []string,
314315
} else {
315316
maxLen := GetMaxLenOfKey(keys)
316317
var currentKeys sort.StringSlice
318+
_, entry, _ := GetComponentEntryTimestamp(keys[0])
319+
317320
for _, value := range keys {
318321
_, currentEntry, _ := GetComponentEntryTimestamp(value)
319-
if currentEntry != entry {
320-
if entry != "" {
321-
fmt.Fprintln(o, "- " + entry)
322-
sort.Sort(sort.Reverse(currentKeys))
323-
drawTableHistoryConfigs([]string{}, currentKeys,maxLen, o)
324-
}
325-
currentKeys = []string{value}
326-
entry = currentEntry
327-
} else {
322+
if currentEntry == entry {
328323
currentKeys = append(currentKeys, value)
324+
} else {
325+
fmt.Fprintln(o, "- " + entry)
326+
sort.Sort(sort.Reverse(currentKeys)) //sort in reverse of timestamps
327+
drawTableHistoryConfigs([]string{}, currentKeys,maxLen, o)
328+
currentKeys = []string{value}
329+
entry = currentEntry
329330
}
330331
}
331332
fmt.Fprintln(o, "- " + entry)
@@ -358,22 +359,6 @@ func IsInputNameValid(input string) bool {
358359
return InputRegex.MatchString(input)
359360
}
360361

361-
func GetMapOfKeysAndTimestamps(keys []string)(map[string]string, error, int) {
362-
configMap := make(map[string]string)
363-
for index := range keys {
364-
var value = keys[index]
365-
value = strings.TrimPrefix(value , componentsPath)
366-
indexOfTimestamp := strings.LastIndex(value, "/")
367-
timestamp, err := GetTimestampInFormat(value[indexOfTimestamp+1:], time.RFC822)
368-
if err != nil {
369-
return nil, err, logicError
370-
}
371-
value = value[:indexOfTimestamp] + string("@") + value[indexOfTimestamp+1:]
372-
configMap[value] = timestamp
373-
}
374-
return configMap, nil, 0
375-
}
376-
377362
func IsInputSingleValidWord(input string) bool {
378363
return !strings.Contains(input, "/") && !strings.Contains(input, "@")
379364
}
@@ -464,15 +449,12 @@ func drawTableHistoryConfigs(headers []string, history []string, max int, o io.W
464449
table.Render()
465450
}
466451

467-
func GetComponentEntryTimestamp(key string)(component string, entry string, timestamp string) {
452+
func GetComponentEntryTimestamp(key string)(string, string, string) {
468453
key = strings.TrimPrefix(key, componentsPath)
469454
key = strings.TrimPrefix(key, "/'")
470455
key = strings.TrimSuffix(key, "/")
471456
elements := strings.Split(key, "/")
472-
component = elements[0]
473-
entry = elements[1]
474-
timestamp = elements[2]
475-
return
457+
return elements[0], elements[1], elements[2]
476458
}
477459

478460
func GetMaxLenOfKey(keys []string) (maxLen int){
@@ -482,4 +464,5 @@ func GetMaxLenOfKey(keys []string) (maxLen int){
482464
maxLen = len(value) - len(componentsPath)
483465
}
484466
}
467+
return
485468
}

0 commit comments

Comments
 (0)