mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.1.0 -> release/2.2.0
* commit '5ddb796c9d51eb3dde002f808010e3f48703f2b7': 不序列化export_file和export_texts 修正:qutoa的images使用量不准确 支持将list的结果导出为excel文件
This commit is contained in:
@@ -19,7 +19,11 @@ func init() {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Servers.GetColumns(s))
|
||||
if len(opts.ExportFile) > 0 {
|
||||
exportList(result, opts.ExportFile, opts.ExportKeys, opts.ExportTexts, modules.Servers.GetColumns(s))
|
||||
} else {
|
||||
printList(result, modules.Servers.GetColumns(s))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/util/printutils"
|
||||
"yunion.io/x/onecloud/pkg/util/excelutils"
|
||||
)
|
||||
|
||||
func printList(list *modules.ListResult, columns []string) {
|
||||
@@ -18,3 +20,16 @@ func printObject(obj jsonutils.JSONObject) {
|
||||
func printBatchResults(results []modules.SubmitResult, columns []string) {
|
||||
printutils.PrintJSONBatchResults(results, columns)
|
||||
}
|
||||
|
||||
func exportList(list *modules.ListResult, file string, exportKeys string, exportTexts string, columns []string) {
|
||||
var keys []string
|
||||
var texts []string
|
||||
if len(exportKeys) > 0 {
|
||||
keys = strings.Split(exportKeys, ",")
|
||||
texts = strings.Split(exportTexts, ",")
|
||||
}else {
|
||||
keys = columns
|
||||
texts = columns
|
||||
}
|
||||
excelutils.ExportFile(list.Data, keys, texts, file)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user