VOL-2168 - add the ability to specify default formats and ordering
Change-Id: Ie867bbd8d055e34f26eb43466a92f1d1954e35d4
diff --git a/internal/pkg/commands/devices.go b/internal/pkg/commands/devices.go
index 78d1aca..ac6d508 100644
--- a/internal/pkg/commands/devices.go
+++ b/internal/pkg/commands/devices.go
@@ -23,7 +23,6 @@
"github.com/jhump/protoreflect/dynamic"
"github.com/opencord/voltctl/pkg/format"
"github.com/opencord/voltctl/pkg/model"
- "log"
"strings"
)
@@ -115,7 +114,7 @@
func RegisterDeviceCommands(parser *flags.Parser) {
if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil {
- log.Fatalf("Unexpected error while attempting to register device commands : %s", err)
+ Error.Fatalf("Unexpected error while attempting to register device commands : %s", err)
}
}
@@ -204,12 +203,17 @@
outputFormat := CharReplacer.Replace(options.Format)
if outputFormat == "" {
- outputFormat = DEFAULT_DEVICE_FORMAT
+ outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT)
}
if options.Quiet {
outputFormat = "{{.Id}}"
}
+ orderBy := options.OrderBy
+ if orderBy == "" {
+ orderBy = GetCommandOptionWithDefault("device-list", "order", "")
+ }
+
data := make([]model.Device, len(items.([]interface{})))
for i, item := range items.([]interface{}) {
val := item.(*dynamic.Message)
@@ -219,7 +223,7 @@
result := CommandResult{
Format: format.Format(outputFormat),
Filter: options.Filter,
- OrderBy: options.OrderBy,
+ OrderBy: orderBy,
OutputAs: toOutputType(options.OutputAs),
NameLimit: options.NameLimit,
Data: data,
@@ -450,12 +454,17 @@
outputFormat := CharReplacer.Replace(options.Format)
if outputFormat == "" {
- outputFormat = DEFAULT_DEVICE_PORTS_FORMAT
+ outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT)
}
if options.Quiet {
outputFormat = "{{.Id}}"
}
+ orderBy := options.OrderBy
+ if orderBy == "" {
+ orderBy = GetCommandOptionWithDefault("device-ports", "order", "")
+ }
+
data := make([]model.DevicePort, len(items.([]interface{})))
for i, item := range items.([]interface{}) {
data[i].PopulateFrom(item.(*dynamic.Message))
@@ -464,7 +473,7 @@
result := CommandResult{
Format: format.Format(outputFormat),
Filter: options.Filter,
- OrderBy: options.OrderBy,
+ OrderBy: orderBy,
OutputAs: toOutputType(options.OutputAs),
NameLimit: options.NameLimit,
Data: data,
@@ -478,7 +487,7 @@
fl := &FlowList{}
fl.ListOutputOptions = options.ListOutputOptions
fl.Args.Id = string(options.Args.Id)
- fl.Method = "device-flow-list"
+ fl.Method = "device-flows"
return fl.Execute(args)
}
@@ -521,7 +530,7 @@
outputFormat := CharReplacer.Replace(options.Format)
if outputFormat == "" {
- outputFormat = DEFAULT_DEVICE_INSPECT_FORMAT
+ outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT)
}
if options.Quiet {
outputFormat = "{{.Id}}"