This commit is contained in:
@@ -68,31 +68,39 @@ func init() {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"worksheet-name",
|
||||
"out-filename"
|
||||
],
|
||||
"properties": {
|
||||
"files": {
|
||||
"description": "File to create before running commands.",
|
||||
"type": "array",
|
||||
"default": null,
|
||||
"items": {
|
||||
"$ref": "#/definitions/direktivFile"
|
||||
}
|
||||
},
|
||||
"infile": {
|
||||
"description": "Name of the json input file to utilise",
|
||||
"type": "string"
|
||||
},
|
||||
"out-filename": {
|
||||
"description": "the filename of the output spreadsheet",
|
||||
"type": "string",
|
||||
"default": "output.xlsx"
|
||||
},
|
||||
"worksheet-name": {
|
||||
"description": "Label for the worksheet created in the spreadsheet",
|
||||
"type": "string",
|
||||
"default": "Sheet1"
|
||||
"sheets": {
|
||||
"description": "Array of worksheets to create in spreadsheet",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"infile": {
|
||||
"description": "Name of the json input file to utilise",
|
||||
"type": "string"
|
||||
},
|
||||
"input-file": {
|
||||
"description": "File to create before running commands",
|
||||
"type": "array",
|
||||
"default": null,
|
||||
"items": {
|
||||
"$ref": "#/definitions/direktivFile"
|
||||
}
|
||||
},
|
||||
"worksheet-name": {
|
||||
"description": "Label for the worksheet created in the spreadsheet",
|
||||
"type": "string",
|
||||
"default": "Sheet1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,8 +140,9 @@ func init() {
|
||||
"x-direktiv": {
|
||||
"cmds": [
|
||||
{
|
||||
"action": "exec",
|
||||
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Infile) \"\" }} \"input.json\" {{- else }} {{ .Infile }} {{- end }} -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||
"action": "foreach",
|
||||
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Item.Infile) \"\" }} \"input.json\" {{- else }} {{ .Item.Infile }} {{- end }} -worksheetName \"{{ .Item.WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||
"loop": ".Sheets",
|
||||
"print": true,
|
||||
"silent": false
|
||||
},
|
||||
@@ -151,11 +160,11 @@ func init() {
|
||||
},
|
||||
"x-direktiv-examples": [
|
||||
{
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx",
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n out-filename: example.xlsx\n sheets:\n - sheet:\n worksheet-name: \"TestSpreadsheet\"\n input-file:\n - name: input.json\n data: |\n jq(.input)",
|
||||
"title": "Basic"
|
||||
},
|
||||
{
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.array | {input: . } | tostring ) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx ",
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n out-filename: example.xlsx \n sheets:\n - sheet:\n worksheet-name: \"TestSpreadsheet\"\n input-file:\n - name: input.json\n data: |\n jq(.array | {input: . } | tostring ) ",
|
||||
"title": "Use jq to add a parent key 'input' containing array of objects"
|
||||
}
|
||||
],
|
||||
@@ -295,8 +304,9 @@ func init() {
|
||||
"x-direktiv": {
|
||||
"cmds": [
|
||||
{
|
||||
"action": "exec",
|
||||
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Infile) \"\" }} \"input.json\" {{- else }} {{ .Infile }} {{- end }} -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||
"action": "foreach",
|
||||
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Item.Infile) \"\" }} \"input.json\" {{- else }} {{ .Item.Infile }} {{- end }} -worksheetName \"{{ .Item.WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||
"loop": ".Sheets",
|
||||
"print": true,
|
||||
"silent": false
|
||||
},
|
||||
@@ -314,11 +324,11 @@ func init() {
|
||||
},
|
||||
"x-direktiv-examples": [
|
||||
{
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.input) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx",
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n out-filename: example.xlsx\n sheets:\n - sheet:\n worksheet-name: \"TestSpreadsheet\"\n input-file:\n - name: input.json\n data: |\n jq(.input)",
|
||||
"title": "Basic"
|
||||
},
|
||||
{
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n files:\n - name: input.json\n data: |\n jq(.array | {input: . } | tostring ) \n worksheet-name: \"TestSpreadsheet\"\n out-filename: example.xlsx ",
|
||||
"content": "- id: export-xlsx\n type: action\n action:\n function: export-xlsx\n input: \n out-filename: example.xlsx \n sheets:\n - sheet:\n worksheet-name: \"TestSpreadsheet\"\n input-file:\n - name: input.json\n data: |\n jq(.array | {input: . } | tostring ) ",
|
||||
"title": "Use jq to add a parent key 'input' containing array of objects"
|
||||
}
|
||||
],
|
||||
@@ -388,27 +398,39 @@ func init() {
|
||||
"postParamsBody": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"worksheet-name",
|
||||
"out-filename"
|
||||
],
|
||||
"properties": {
|
||||
"files": {
|
||||
"description": "File to create before running commands.",
|
||||
"out-filename": {
|
||||
"description": "the filename of the output spreadsheet",
|
||||
"type": "string",
|
||||
"default": "output.xlsx"
|
||||
},
|
||||
"sheets": {
|
||||
"description": "Array of worksheets to create in spreadsheet",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/postParamsBodySheetsItems"
|
||||
}
|
||||
}
|
||||
},
|
||||
"x-go-gen-location": "operations"
|
||||
},
|
||||
"postParamsBodySheetsItems": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"infile": {
|
||||
"description": "Name of the json input file to utilise",
|
||||
"type": "string"
|
||||
},
|
||||
"input-file": {
|
||||
"description": "File to create before running commands",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"items": {
|
||||
"$ref": "#/definitions/direktivFile"
|
||||
}
|
||||
},
|
||||
"infile": {
|
||||
"description": "Name of the json input file to utilise",
|
||||
"type": "string"
|
||||
},
|
||||
"out-filename": {
|
||||
"description": "the filename of the output spreadsheet",
|
||||
"type": "string",
|
||||
"default": "output.xlsx"
|
||||
},
|
||||
"worksheet-name": {
|
||||
"description": "Label for the worksheet created in the spreadsheet",
|
||||
"type": "string",
|
||||
|
@@ -86,9 +86,7 @@ func PostDirektivHandle(params PostParams) middleware.Responder {
|
||||
|
||||
// if foreach returns an error there is no continue
|
||||
//
|
||||
// default we do not continue
|
||||
cont = convertTemplateToBool("<no value>", accParams, false)
|
||||
// cont = convertTemplateToBool("<no value>", accParams, true)
|
||||
// cont = false
|
||||
//
|
||||
|
||||
if err != nil && !cont {
|
||||
@@ -163,34 +161,65 @@ func PostDirektivHandle(params PostParams) middleware.Responder {
|
||||
return NewPostOK().WithPayload(resp)
|
||||
}
|
||||
|
||||
// exec
|
||||
// foreach command
|
||||
type LoopStruct0 struct {
|
||||
accParams
|
||||
Item interface{}
|
||||
DirektivDir string
|
||||
}
|
||||
|
||||
func runCommand0(ctx context.Context,
|
||||
params accParams, ri *apps.RequestInfo) (map[string]interface{}, error) {
|
||||
params accParams, ri *apps.RequestInfo) ([]map[string]interface{}, error) {
|
||||
|
||||
ir := make(map[string]interface{})
|
||||
ir[successKey] = false
|
||||
var cmds []map[string]interface{}
|
||||
|
||||
at := accParamsTemplate{
|
||||
*params.Body,
|
||||
params.Commands,
|
||||
params.DirektivDir,
|
||||
if params.Body == nil {
|
||||
return cmds, nil
|
||||
}
|
||||
|
||||
cmd, err := templateString(`/bin/json2excel -inputJson {{- if eq (deref .Infile) "" }} "input.json" {{- else }} {{ .Infile }} {{- end }} -worksheetName "{{ .WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, at)
|
||||
if err != nil {
|
||||
ri.Logger().Infof("error executing command: %v", err)
|
||||
ir[resultKey] = err.Error()
|
||||
return ir, err
|
||||
for a := range params.Body.Sheets {
|
||||
|
||||
ls := &LoopStruct0{
|
||||
params,
|
||||
params.Body.Sheets[a],
|
||||
params.DirektivDir,
|
||||
}
|
||||
|
||||
cmd, err := templateString(`/bin/json2excel -inputJson {{- if eq (deref .Item.Infile) "" }} "input.json" {{- else }} {{ .Item.Infile }} {{- end }} -worksheetName "{{ .Item.WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, ls)
|
||||
if err != nil {
|
||||
ir := make(map[string]interface{})
|
||||
ir[successKey] = false
|
||||
ir[resultKey] = err.Error()
|
||||
cmds = append(cmds, ir)
|
||||
continue
|
||||
}
|
||||
|
||||
silent := convertTemplateToBool("false", ls, false)
|
||||
print := convertTemplateToBool("true", ls, true)
|
||||
cont := convertTemplateToBool("<no value>", ls, false)
|
||||
output := ""
|
||||
|
||||
envs := []string{}
|
||||
|
||||
r, err := runCmd(ctx, cmd, envs, output, silent, print, ri)
|
||||
if err != nil {
|
||||
ir := make(map[string]interface{})
|
||||
ir[successKey] = false
|
||||
ir[resultKey] = err.Error()
|
||||
cmds = append(cmds, ir)
|
||||
|
||||
if cont {
|
||||
continue
|
||||
}
|
||||
|
||||
return cmds, err
|
||||
|
||||
}
|
||||
cmds = append(cmds, r)
|
||||
|
||||
}
|
||||
cmd = strings.Replace(cmd, "\n", "", -1)
|
||||
|
||||
silent := convertTemplateToBool("false", at, false)
|
||||
print := convertTemplateToBool("true", at, true)
|
||||
output := ""
|
||||
|
||||
envs := []string{}
|
||||
|
||||
return runCmd(ctx, cmd, envs, output, silent, print, ri)
|
||||
return cmds, nil
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user