From ad60dfbc3222c559ffada3138c6896d3e1ec9803 Mon Sep 17 00:00:00 2001 From: voduchau Date: Tue, 16 Aug 2022 13:38:53 +0700 Subject: [PATCH 1/7] doesn't support Status,Assignee,Categories fields --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6bd2859..7de9d3f 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ type Cell struct { Type string IsSubField bool Table string - Index int + Index int } // Row config @@ -82,6 +82,10 @@ type Row []*Cell func getFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) { fields, err := app.Fields() + ignoreFields := [3]string{"Status", "Assignee", "Categories"} + for i := 0; i < len(ignoreFields); i++ { + delete(fields, ignoreFields[i]) + } if err != nil { return nil, err } From 70605871355bef28af5508945dda19ad4aadaaa1 Mon Sep 17 00:00:00 2001 From: voduchau Date: Tue, 16 Aug 2022 14:31:09 +0700 Subject: [PATCH 2/7] change to check type when delete field --- main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 7de9d3f..5e45f0b 100644 --- a/main.go +++ b/main.go @@ -82,9 +82,14 @@ type Row []*Cell func getFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) { fields, err := app.Fields() - ignoreFields := [3]string{"Status", "Assignee", "Categories"} - for i := 0; i < len(ignoreFields); i++ { - delete(fields, ignoreFields[i]) + ignoreFields := []string{"STATUS_ASSIGNEE", "CATEGORY", "STATUS"} + for key, field := range fields { + for _, ignoreField := range ignoreFields { + if field.Type == ignoreField { + delete(fields, key) + break + } + } } if err != nil { return nil, err From 34da615f174cb2c8899d618a448e4b7c662a8c70 Mon Sep 17 00:00:00 2001 From: voduchau Date: Tue, 16 Aug 2022 15:34:57 +0700 Subject: [PATCH 3/7] separate func and change name from getFields to getSupportedFields --- export.go | 2 +- import-with-bulkRequest.go | 6 +++--- main.go | 28 +++++++++++++++++----------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/export.go b/export.go index 5167d55..7c276f3 100644 --- a/export.go +++ b/export.go @@ -44,7 +44,7 @@ func getRecordsForSeekMethod(app *kintone.App, id uint64, fields []string, isRec func getRow(app *kintone.App) (Row, error) { var row Row // retrieve field list - fields, err := getFields(app) + fields, err := getSupportedFields(app) if err != nil { return row, err } diff --git a/import-with-bulkRequest.go b/import-with-bulkRequest.go index f371aaf..8c9c3c3 100644 --- a/import-with-bulkRequest.go +++ b/import-with-bulkRequest.go @@ -119,7 +119,7 @@ func importFromCSV(app *kintone.App, _reader io.Reader) error { nextRowImport = config.Line bulkRequests := &BulkRequests{} // retrieve field list - fields, err := getFields(app) + fields, err := getSupportedFields(app) if err != nil { return err } @@ -216,7 +216,7 @@ func importFromCSV(app *kintone.App, _reader io.Reader) error { field, err := uploadFiles(app, col) if err != nil { - return fmt.Errorf("\ncolumn[" + strconv.Itoa(i) +"]"+ " - row[" + strconv.FormatUint(rowNumber, 10)+"]: "+ err.Error()) + return fmt.Errorf("\ncolumn[" + strconv.Itoa(i) + "]" + " - row[" + strconv.FormatUint(rowNumber, 10) + "]: " + err.Error()) } if field != nil { record[column.Code] = field @@ -261,7 +261,7 @@ func importFromCSV(app *kintone.App, _reader io.Reader) error { } if hasId && keyField != "" { - log.Fatalln("The \"$id\" field and update key fields cannot be specified together in CSV import file."); + log.Fatalln("The \"$id\" field and update key fields cannot be specified together in CSV import file.") } _, hasKeyField := record[keyField] diff --git a/main.go b/main.go index 5e45f0b..3ec4d9a 100644 --- a/main.go +++ b/main.go @@ -80,21 +80,27 @@ type Cell struct { // Row config type Row []*Cell -func getFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) { +func getSupportedFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) { fields, err := app.Fields() - ignoreFields := []string{"STATUS_ASSIGNEE", "CATEGORY", "STATUS"} - for key, field := range fields { - for _, ignoreField := range ignoreFields { - if field.Type == ignoreField { - delete(fields, key) - break - } - } - } if err != nil { return nil, err } - return fields, nil + supportedFields := deleteUnsupportedFields(fields) + return supportedFields, nil +} + +func deleteUnsupportedFields(fields map[string]*kintone.FieldInfo) map[string]*kintone.FieldInfo { + supportedFields := make(map[string]*kintone.FieldInfo) + for key, field := range fields { + _type := field.Type + isIgnoreFields := _type == "STATUS_ASSIGNEE" || _type == "CATEGORY" || _type == "STATUS" + if isIgnoreFields { + continue + } + supportedFields[key] = field + + } + return supportedFields } // set column information from fieldinfo From 1eb696c1c0b1604bd88055534ee9fa55a11c5da0 Mon Sep 17 00:00:00 2001 From: voduchau Date: Tue, 16 Aug 2022 15:40:04 +0700 Subject: [PATCH 4/7] rollback auto format --- import-with-bulkRequest.go | 4 ++-- main.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/import-with-bulkRequest.go b/import-with-bulkRequest.go index 8c9c3c3..65e959d 100644 --- a/import-with-bulkRequest.go +++ b/import-with-bulkRequest.go @@ -216,7 +216,7 @@ func importFromCSV(app *kintone.App, _reader io.Reader) error { field, err := uploadFiles(app, col) if err != nil { - return fmt.Errorf("\ncolumn[" + strconv.Itoa(i) + "]" + " - row[" + strconv.FormatUint(rowNumber, 10) + "]: " + err.Error()) + return fmt.Errorf("\ncolumn[" + strconv.Itoa(i) +"]"+ " - row[" + strconv.FormatUint(rowNumber, 10)+"]: "+ err.Error()) } if field != nil { record[column.Code] = field @@ -261,7 +261,7 @@ func importFromCSV(app *kintone.App, _reader io.Reader) error { } if hasId && keyField != "" { - log.Fatalln("The \"$id\" field and update key fields cannot be specified together in CSV import file.") + log.Fatalln("The \"$id\" field and update key fields cannot be specified together in CSV import file."); } _, hasKeyField := record[keyField] diff --git a/main.go b/main.go index 3ec4d9a..eb876d1 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ type Cell struct { Type string IsSubField bool Table string - Index int + Index int } // Row config From c98df77f127ffe5e697eb00c1aeb9ef9a6d40930 Mon Sep 17 00:00:00 2001 From: voduchau Date: Tue, 16 Aug 2022 16:01:45 +0700 Subject: [PATCH 5/7] add unsupported fields to readme and refactor getSupportedFields function --- README.md | 2 +- import-with-bulkRequest.go | 2 +- main.go | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9a9fcae..e6fbf8a 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ printf "name,age\nJohn,37\nJane,29" | cli-kintone --import -a -d ## Restrictions * The limit of each file size for uploading to attachments field is 10MB. * Client certificates cannot be used with cli-kintone. -* The following record data cannot be retrieved: Field group, Blank space, Label, Border +* The following record data cannot be retrieved: Field group, Blank space, Label, Border, Status, Assignee, Category ## Restriction of Encode/Decode * Windows command prompt may not display characters correctly like "譁�蟄怜喧縺�". diff --git a/import-with-bulkRequest.go b/import-with-bulkRequest.go index 65e959d..f371aaf 100644 --- a/import-with-bulkRequest.go +++ b/import-with-bulkRequest.go @@ -119,7 +119,7 @@ func importFromCSV(app *kintone.App, _reader io.Reader) error { nextRowImport = config.Line bulkRequests := &BulkRequests{} // retrieve field list - fields, err := getSupportedFields(app) + fields, err := getFields(app) if err != nil { return err } diff --git a/main.go b/main.go index eb876d1..2b2df7c 100644 --- a/main.go +++ b/main.go @@ -80,27 +80,28 @@ type Cell struct { // Row config type Row []*Cell -func getSupportedFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) { +func getFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) { fields, err := app.Fields() if err != nil { return nil, err } - supportedFields := deleteUnsupportedFields(fields) - return supportedFields, nil + return fields, nil } -func deleteUnsupportedFields(fields map[string]*kintone.FieldInfo) map[string]*kintone.FieldInfo { - supportedFields := make(map[string]*kintone.FieldInfo) +func getSupportedFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) { + fields, err := getFields(app) + if err != nil { + return nil, err + } for key, field := range fields { - _type := field.Type - isIgnoreFields := _type == "STATUS_ASSIGNEE" || _type == "CATEGORY" || _type == "STATUS" - if isIgnoreFields { - continue + switch field.Type { + case "STATUS_ASSIGNEE","CATEGORY","STATUS": + delete(fields, key) + default: continue } - supportedFields[key] = field } - return supportedFields + return fields, nil } // set column information from fieldinfo From 1e374b794a61f33ded71c8a466590b1b8f43de38 Mon Sep 17 00:00:00 2001 From: voduchau Date: Wed, 17 Aug 2022 16:17:13 +0700 Subject: [PATCH 6/7] change format --- main.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 2b2df7c..d65bb61 100644 --- a/main.go +++ b/main.go @@ -94,13 +94,13 @@ func getSupportedFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) return nil, err } for key, field := range fields { - switch field.Type { - case "STATUS_ASSIGNEE","CATEGORY","STATUS": - delete(fields, key) - default: continue - } - - } + switch field.Type { + case "STATUS_ASSIGNEE", "CATEGORY", "STATUS": + delete(fields, key) + default: + continue + } + } return fields, nil } From af5102314db2366c30a4665350a99c70273f5f45 Mon Sep 17 00:00:00 2001 From: voduchau Date: Thu, 18 Aug 2022 11:21:19 +0700 Subject: [PATCH 7/7] format --- main.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index d65bb61..76ed2bc 100644 --- a/main.go +++ b/main.go @@ -74,7 +74,7 @@ type Cell struct { Type string IsSubField bool Table string - Index int + Index int } // Row config @@ -94,13 +94,13 @@ func getSupportedFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) return nil, err } for key, field := range fields { - switch field.Type { - case "STATUS_ASSIGNEE", "CATEGORY", "STATUS": - delete(fields, key) - default: - continue - } - } + switch field.Type { + case "STATUS_ASSIGNEE", "CATEGORY", "STATUS": + delete(fields, key) + default: + continue + } + } return fields, nil }