This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/direktiv/apps/go/pkg/apps"
|
|
||||||
"github.com/go-openapi/errors"
|
"github.com/go-openapi/errors"
|
||||||
"github.com/go-openapi/strfmt"
|
"github.com/go-openapi/strfmt"
|
||||||
"github.com/go-openapi/swag"
|
"github.com/go-openapi/swag"
|
||||||
@@ -21,34 +20,23 @@ import (
|
|||||||
// swagger:model postParamsBody
|
// swagger:model postParamsBody
|
||||||
type PostParamsBody struct {
|
type PostParamsBody struct {
|
||||||
|
|
||||||
// File to create before running commands.
|
|
||||||
Files []apps.DirektivFile `json:"files"`
|
|
||||||
|
|
||||||
// Name of the json input file to utilise
|
|
||||||
Infile string `json:"infile,omitempty"`
|
|
||||||
|
|
||||||
// the filename of the output spreadsheet
|
// the filename of the output spreadsheet
|
||||||
// Required: true
|
// Required: true
|
||||||
OutFilename *string `json:"out-filename"`
|
OutFilename *string `json:"out-filename"`
|
||||||
|
|
||||||
// Label for the worksheet created in the spreadsheet
|
// Array of worksheets to create in spreadsheet
|
||||||
// Required: true
|
Sheets []*PostParamsBodySheetsItems `json:"sheets"`
|
||||||
WorksheetName *string `json:"worksheet-name"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates this post params body
|
// Validate validates this post params body
|
||||||
func (m *PostParamsBody) Validate(formats strfmt.Registry) error {
|
func (m *PostParamsBody) Validate(formats strfmt.Registry) error {
|
||||||
var res []error
|
var res []error
|
||||||
|
|
||||||
if err := m.validateFiles(formats); err != nil {
|
|
||||||
res = append(res, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := m.validateOutFilename(formats); err != nil {
|
if err := m.validateOutFilename(formats); err != nil {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.validateWorksheetName(formats); err != nil {
|
if err := m.validateSheets(formats); err != nil {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,27 +46,6 @@ func (m *PostParamsBody) Validate(formats strfmt.Registry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PostParamsBody) validateFiles(formats strfmt.Registry) error {
|
|
||||||
if swag.IsZero(m.Files) { // not required
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < len(m.Files); i++ {
|
|
||||||
|
|
||||||
if err := m.Files[i].Validate(formats); err != nil {
|
|
||||||
if ve, ok := err.(*errors.Validation); ok {
|
|
||||||
return ve.ValidateName("files" + "." + strconv.Itoa(i))
|
|
||||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
|
||||||
return ce.ValidateName("files" + "." + strconv.Itoa(i))
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *PostParamsBody) validateOutFilename(formats strfmt.Registry) error {
|
func (m *PostParamsBody) validateOutFilename(formats strfmt.Registry) error {
|
||||||
|
|
||||||
if err := validate.Required("out-filename", "body", m.OutFilename); err != nil {
|
if err := validate.Required("out-filename", "body", m.OutFilename); err != nil {
|
||||||
@@ -88,11 +55,28 @@ func (m *PostParamsBody) validateOutFilename(formats strfmt.Registry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PostParamsBody) validateWorksheetName(formats strfmt.Registry) error {
|
func (m *PostParamsBody) validateSheets(formats strfmt.Registry) error {
|
||||||
|
if swag.IsZero(m.Sheets) { // not required
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := validate.Required("worksheet-name", "body", m.WorksheetName); err != nil {
|
for i := 0; i < len(m.Sheets); i++ {
|
||||||
|
if swag.IsZero(m.Sheets[i]) { // not required
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.Sheets[i] != nil {
|
||||||
|
if err := m.Sheets[i].Validate(formats); err != nil {
|
||||||
|
if ve, ok := err.(*errors.Validation); ok {
|
||||||
|
return ve.ValidateName("sheets" + "." + strconv.Itoa(i))
|
||||||
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||||
|
return ce.ValidateName("sheets" + "." + strconv.Itoa(i))
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -101,7 +85,7 @@ func (m *PostParamsBody) validateWorksheetName(formats strfmt.Registry) error {
|
|||||||
func (m *PostParamsBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
func (m *PostParamsBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||||
var res []error
|
var res []error
|
||||||
|
|
||||||
if err := m.contextValidateFiles(ctx, formats); err != nil {
|
if err := m.contextValidateSheets(ctx, formats); err != nil {
|
||||||
res = append(res, err)
|
res = append(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,18 +95,20 @@ func (m *PostParamsBody) ContextValidate(ctx context.Context, formats strfmt.Reg
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PostParamsBody) contextValidateFiles(ctx context.Context, formats strfmt.Registry) error {
|
func (m *PostParamsBody) contextValidateSheets(ctx context.Context, formats strfmt.Registry) error {
|
||||||
|
|
||||||
for i := 0; i < len(m.Files); i++ {
|
for i := 0; i < len(m.Sheets); i++ {
|
||||||
|
|
||||||
if err := m.Files[i].ContextValidate(ctx, formats); err != nil {
|
if m.Sheets[i] != nil {
|
||||||
|
if err := m.Sheets[i].ContextValidate(ctx, formats); err != nil {
|
||||||
if ve, ok := err.(*errors.Validation); ok {
|
if ve, ok := err.(*errors.Validation); ok {
|
||||||
return ve.ValidateName("files" + "." + strconv.Itoa(i))
|
return ve.ValidateName("sheets" + "." + strconv.Itoa(i))
|
||||||
} else if ce, ok := err.(*errors.CompositeError); ok {
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||||
return ce.ValidateName("files" + "." + strconv.Itoa(i))
|
return ce.ValidateName("sheets" + "." + strconv.Itoa(i))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
116
build/app/models/post_params_body_sheets_items.go
Normal file
116
build/app/models/post_params_body_sheets_items.go
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
// Code generated by go-swagger; DO NOT EDIT.
|
||||||
|
|
||||||
|
package models
|
||||||
|
|
||||||
|
// This file was generated by the swagger tool.
|
||||||
|
// Editing this file might prove futile when you re-run the swagger generate command
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/direktiv/apps/go/pkg/apps"
|
||||||
|
"github.com/go-openapi/errors"
|
||||||
|
"github.com/go-openapi/strfmt"
|
||||||
|
"github.com/go-openapi/swag"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PostParamsBodySheetsItems post params body sheets items
|
||||||
|
//
|
||||||
|
// swagger:model postParamsBodySheetsItems
|
||||||
|
type PostParamsBodySheetsItems struct {
|
||||||
|
|
||||||
|
// Name of the json input file to utilise
|
||||||
|
Infile string `json:"infile,omitempty"`
|
||||||
|
|
||||||
|
// File to create before running commands
|
||||||
|
InputFile []apps.DirektivFile `json:"input-file"`
|
||||||
|
|
||||||
|
// Label for the worksheet created in the spreadsheet
|
||||||
|
WorksheetName *string `json:"worksheet-name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate validates this post params body sheets items
|
||||||
|
func (m *PostParamsBodySheetsItems) Validate(formats strfmt.Registry) error {
|
||||||
|
var res []error
|
||||||
|
|
||||||
|
if err := m.validateInputFile(formats); err != nil {
|
||||||
|
res = append(res, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(res) > 0 {
|
||||||
|
return errors.CompositeValidationError(res...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PostParamsBodySheetsItems) validateInputFile(formats strfmt.Registry) error {
|
||||||
|
if swag.IsZero(m.InputFile) { // not required
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(m.InputFile); i++ {
|
||||||
|
|
||||||
|
if err := m.InputFile[i].Validate(formats); err != nil {
|
||||||
|
if ve, ok := err.(*errors.Validation); ok {
|
||||||
|
return ve.ValidateName("input-file" + "." + strconv.Itoa(i))
|
||||||
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||||
|
return ce.ValidateName("input-file" + "." + strconv.Itoa(i))
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContextValidate validate this post params body sheets items based on the context it is used
|
||||||
|
func (m *PostParamsBodySheetsItems) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
|
||||||
|
var res []error
|
||||||
|
|
||||||
|
if err := m.contextValidateInputFile(ctx, formats); err != nil {
|
||||||
|
res = append(res, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(res) > 0 {
|
||||||
|
return errors.CompositeValidationError(res...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *PostParamsBodySheetsItems) contextValidateInputFile(ctx context.Context, formats strfmt.Registry) error {
|
||||||
|
|
||||||
|
for i := 0; i < len(m.InputFile); i++ {
|
||||||
|
|
||||||
|
if err := m.InputFile[i].ContextValidate(ctx, formats); err != nil {
|
||||||
|
if ve, ok := err.(*errors.Validation); ok {
|
||||||
|
return ve.ValidateName("input-file" + "." + strconv.Itoa(i))
|
||||||
|
} else if ce, ok := err.(*errors.CompositeError); ok {
|
||||||
|
return ce.ValidateName("input-file" + "." + strconv.Itoa(i))
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalBinary interface implementation
|
||||||
|
func (m *PostParamsBodySheetsItems) MarshalBinary() ([]byte, error) {
|
||||||
|
if m == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return swag.WriteJSON(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalBinary interface implementation
|
||||||
|
func (m *PostParamsBodySheetsItems) UnmarshalBinary(b []byte) error {
|
||||||
|
var res PostParamsBodySheetsItems
|
||||||
|
if err := swag.ReadJSON(b, &res); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*m = res
|
||||||
|
return nil
|
||||||
|
}
|
@@ -68,27 +68,32 @@ func init() {
|
|||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"worksheet-name",
|
|
||||||
"out-filename"
|
"out-filename"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"files": {
|
"out-filename": {
|
||||||
"description": "File to create before running commands.",
|
"description": "the filename of the output spreadsheet",
|
||||||
|
"type": "string",
|
||||||
|
"default": "output.xlsx"
|
||||||
|
},
|
||||||
|
"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",
|
"type": "array",
|
||||||
"default": null,
|
"default": null,
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/direktivFile"
|
"$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": {
|
"worksheet-name": {
|
||||||
"description": "Label for the worksheet created in the spreadsheet",
|
"description": "Label for the worksheet created in the spreadsheet",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@@ -97,6 +102,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -132,8 +140,9 @@ func init() {
|
|||||||
"x-direktiv": {
|
"x-direktiv": {
|
||||||
"cmds": [
|
"cmds": [
|
||||||
{
|
{
|
||||||
"action": "exec",
|
"action": "foreach",
|
||||||
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Infile) \"\" }} \"input.json\" {{- else }} {{ .Infile }} {{- end }} -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Item.Infile) \"\" }} \"input.json\" {{- else }} {{ .Item.Infile }} {{- end }} -worksheetName \"{{ .Item.WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||||
|
"loop": ".Sheets",
|
||||||
"print": true,
|
"print": true,
|
||||||
"silent": false
|
"silent": false
|
||||||
},
|
},
|
||||||
@@ -151,11 +160,11 @@ func init() {
|
|||||||
},
|
},
|
||||||
"x-direktiv-examples": [
|
"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"
|
"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"
|
"title": "Use jq to add a parent key 'input' containing array of objects"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -295,8 +304,9 @@ func init() {
|
|||||||
"x-direktiv": {
|
"x-direktiv": {
|
||||||
"cmds": [
|
"cmds": [
|
||||||
{
|
{
|
||||||
"action": "exec",
|
"action": "foreach",
|
||||||
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Infile) \"\" }} \"input.json\" {{- else }} {{ .Infile }} {{- end }} -worksheetName \"{{ .WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
"exec": "/bin/json2excel -inputJson {{- if eq (deref .Item.Infile) \"\" }} \"input.json\" {{- else }} {{ .Item.Infile }} {{- end }} -worksheetName \"{{ .Item.WorksheetName }}\" -outputFilename '{{ .OutFilename }}'",
|
||||||
|
"loop": ".Sheets",
|
||||||
"print": true,
|
"print": true,
|
||||||
"silent": false
|
"silent": false
|
||||||
},
|
},
|
||||||
@@ -314,11 +324,11 @@ func init() {
|
|||||||
},
|
},
|
||||||
"x-direktiv-examples": [
|
"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"
|
"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"
|
"title": "Use jq to add a parent key 'input' containing array of objects"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -388,27 +398,39 @@ func init() {
|
|||||||
"postParamsBody": {
|
"postParamsBody": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"worksheet-name",
|
|
||||||
"out-filename"
|
"out-filename"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"files": {
|
"out-filename": {
|
||||||
"description": "File to create before running commands.",
|
"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",
|
"type": "array",
|
||||||
"default": [],
|
"default": [],
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/direktivFile"
|
"$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": {
|
"worksheet-name": {
|
||||||
"description": "Label for the worksheet created in the spreadsheet",
|
"description": "Label for the worksheet created in the spreadsheet",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@@ -86,9 +86,7 @@ func PostDirektivHandle(params PostParams) middleware.Responder {
|
|||||||
|
|
||||||
// if foreach returns an error there is no continue
|
// if foreach returns an error there is no continue
|
||||||
//
|
//
|
||||||
// default we do not continue
|
// cont = false
|
||||||
cont = convertTemplateToBool("<no value>", accParams, false)
|
|
||||||
// cont = convertTemplateToBool("<no value>", accParams, true)
|
|
||||||
//
|
//
|
||||||
|
|
||||||
if err != nil && !cont {
|
if err != nil && !cont {
|
||||||
@@ -163,34 +161,65 @@ func PostDirektivHandle(params PostParams) middleware.Responder {
|
|||||||
return NewPostOK().WithPayload(resp)
|
return NewPostOK().WithPayload(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// exec
|
// foreach command
|
||||||
|
type LoopStruct0 struct {
|
||||||
|
accParams
|
||||||
|
Item interface{}
|
||||||
|
DirektivDir string
|
||||||
|
}
|
||||||
|
|
||||||
func runCommand0(ctx context.Context,
|
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{})
|
var cmds []map[string]interface{}
|
||||||
ir[successKey] = false
|
|
||||||
|
|
||||||
at := accParamsTemplate{
|
if params.Body == nil {
|
||||||
*params.Body,
|
return cmds, nil
|
||||||
params.Commands,
|
}
|
||||||
|
|
||||||
|
for a := range params.Body.Sheets {
|
||||||
|
|
||||||
|
ls := &LoopStruct0{
|
||||||
|
params,
|
||||||
|
params.Body.Sheets[a],
|
||||||
params.DirektivDir,
|
params.DirektivDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, err := templateString(`/bin/json2excel -inputJson {{- if eq (deref .Infile) "" }} "input.json" {{- else }} {{ .Infile }} {{- end }} -worksheetName "{{ .WorksheetName }}" -outputFilename '{{ .OutFilename }}'`, at)
|
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 {
|
if err != nil {
|
||||||
ri.Logger().Infof("error executing command: %v", err)
|
ir := make(map[string]interface{})
|
||||||
|
ir[successKey] = false
|
||||||
ir[resultKey] = err.Error()
|
ir[resultKey] = err.Error()
|
||||||
return ir, err
|
cmds = append(cmds, ir)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
cmd = strings.Replace(cmd, "\n", "", -1)
|
|
||||||
|
|
||||||
silent := convertTemplateToBool("false", at, false)
|
silent := convertTemplateToBool("false", ls, false)
|
||||||
print := convertTemplateToBool("true", at, true)
|
print := convertTemplateToBool("true", ls, true)
|
||||||
|
cont := convertTemplateToBool("<no value>", ls, false)
|
||||||
output := ""
|
output := ""
|
||||||
|
|
||||||
envs := []string{}
|
envs := []string{}
|
||||||
|
|
||||||
return runCmd(ctx, cmd, envs, output, silent, print, ri)
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmds, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
readme.md
35
readme.md
@@ -31,12 +31,14 @@ functions:
|
|||||||
action:
|
action:
|
||||||
function: export-xlsx
|
function: export-xlsx
|
||||||
input:
|
input:
|
||||||
files:
|
out-filename: example.xlsx
|
||||||
|
sheets:
|
||||||
|
- sheet:
|
||||||
|
worksheet-name: "TestSpreadsheet"
|
||||||
|
input-file:
|
||||||
- name: input.json
|
- name: input.json
|
||||||
data: |
|
data: |
|
||||||
jq(.input)
|
jq(.input)
|
||||||
worksheet-name: "TestSpreadsheet"
|
|
||||||
out-filename: example.xlsx
|
|
||||||
```
|
```
|
||||||
#### Use jq to add a parent key 'input' containing array of objects
|
#### Use jq to add a parent key 'input' containing array of objects
|
||||||
```yaml
|
```yaml
|
||||||
@@ -45,12 +47,14 @@ functions:
|
|||||||
action:
|
action:
|
||||||
function: export-xlsx
|
function: export-xlsx
|
||||||
input:
|
input:
|
||||||
files:
|
out-filename: example.xlsx
|
||||||
|
sheets:
|
||||||
|
- sheet:
|
||||||
|
worksheet-name: "TestSpreadsheet"
|
||||||
|
input-file:
|
||||||
- name: input.json
|
- name: input.json
|
||||||
data: |
|
data: |
|
||||||
jq(.array | {input: . } | tostring )
|
jq(.array | {input: . } | tostring )
|
||||||
worksheet-name: "TestSpreadsheet"
|
|
||||||
out-filename: example.xlsx
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Secrets
|
### Secrets
|
||||||
@@ -115,9 +119,22 @@ functions:
|
|||||||
|
|
||||||
| Name | Type | Go type | Required | Default | Description | Example |
|
| Name | Type | Go type | Required | Default | Description | Example |
|
||||||
|------|------|---------|:--------:| ------- |-------------|---------|
|
|------|------|---------|:--------:| ------- |-------------|---------|
|
||||||
| files | [][DirektivFile](#direktiv-file)| `[]apps.DirektivFile` | | | File to create before running commands. | |
|
|
||||||
| infile | string| `string` | | | Name of the json input file to utilise | |
|
|
||||||
| out-filename | string| `string` | ✓ | `"output.xlsx"`| the filename of the output spreadsheet | |
|
| out-filename | string| `string` | ✓ | `"output.xlsx"`| the filename of the output spreadsheet | |
|
||||||
| worksheet-name | string| `string` | ✓ | `"Sheet1"`| Label for the worksheet created in the spreadsheet | |
|
| sheets | [][PostParamsBodySheetsItems](#post-params-body-sheets-items)| `[]*PostParamsBodySheetsItems` | | | Array of worksheets to create in spreadsheet | |
|
||||||
|
|
||||||
|
|
||||||
|
#### <span id="post-params-body-sheets-items"></span> postParamsBodySheetsItems
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Properties**
|
||||||
|
|
||||||
|
| Name | Type | Go type | Required | Default | Description | Example |
|
||||||
|
|------|------|---------|:--------:| ------- |-------------|---------|
|
||||||
|
| infile | string| `string` | | | Name of the json input file to utilise | |
|
||||||
|
| input-file | [][DirektivFile](#direktiv-file)| `[]apps.DirektivFile` | | | File to create before running commands | |
|
||||||
|
| worksheet-name | string| `string` | | `"Sheet1"`| Label for the worksheet created in the spreadsheet | |
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user