Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #45 from kintone/v0.9.4_issues_sjis
Browse files Browse the repository at this point in the history
V0.9.4 issues sjis
  • Loading branch information
quocphien90 authored Apr 2, 2019
2 parents 4938d85 + 9e0accc commit 39980cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 108 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cli-kintone is a command line utility for exporting and importing kintone App da

## Version

0.9.3
0.9.4

## How to Build

Expand Down
98 changes: 12 additions & 86 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ func writeJSON(app *kintone.App, _writer io.Writer) error {

}
}
subTableValue.Fields[fieldCodeInSubTable] = transformEncodingJSONValue(fieldValueInSubTable)
}
}
}
record.Fields[fieldCode] = transformEncodingJSONValue(fieldInfo)

}
jsonArray, _ := record.MarshalJSON()
json := string(jsonArray)
fmt.Fprint(writer, json)
_, err := fmt.Fprint(writer, json)
if err != nil {
return err
}
i++
}
if eof {
Expand All @@ -100,78 +100,6 @@ func writeJSON(app *kintone.App, _writer io.Writer) error {

return nil
}
func transformEncodingJSONValue(fields interface{}) interface{} {
var fieldEncodingValues interface{}
switch fields.(type) {
case kintone.SingleLineTextField:
fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n"))
fieldEncodingValues = kintone.SingleLineTextField(fieldStringValues)
case kintone.MultiLineTextField:
fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n"))
fieldEncodingValues = kintone.MultiLineTextField(fieldStringValues)
case kintone.RichTextField:
fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n"))
fieldEncodingValues = kintone.RichTextField(fieldStringValues)
case kintone.SingleSelectField:
fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n"))
if fieldStringValues == "" {
fieldEncodingValues = kintone.SingleSelectField{Valid: false}
} else {
fieldEncodingValues = kintone.SingleSelectField{String: fieldStringValues, Valid: true}
}
case kintone.CheckBoxField:
fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n"))
fieldStringValuesArray := strings.Split(fieldStringValues, "\n")
fieldEncodingValues = kintone.CheckBoxField(fieldStringValuesArray)
case kintone.RadioButtonField:
fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n"))
fieldEncodingValues = kintone.RadioButtonField(fieldStringValues)
case kintone.MultiSelectField:
fieldStringValues, _ := transformStringFromEncoding(toString(fields, "\n"))
fieldStringValuesArray := strings.Split(fieldStringValues, "\n")
fieldEncodingValues = kintone.MultiSelectField(fieldStringValuesArray)
case kintone.UserField:
var userList []kintone.User
userField := fields.(kintone.UserField)
for _, user := range userField {
user.Code, _ = transformStringFromEncoding(user.Code)
user.Name, _ = transformStringFromEncoding(user.Name)
userList = append(userList, user)
}
fieldEncodingValues = kintone.UserField(userList)
case kintone.OrganizationField:
var organizations []kintone.Organization
organizationField := fields.(kintone.OrganizationField)
for _, organization := range organizationField {
organization.Code, _ = transformStringFromEncoding(organization.Code)
organization.Name, _ = transformStringFromEncoding(organization.Name)
organizations = append(organizations, organization)
}
fieldEncodingValues = kintone.OrganizationField(organizations)
case kintone.GroupField:
var groups []kintone.Group
groupField := fields.(kintone.GroupField)
for _, group := range groupField {
group.Code, _ = transformStringFromEncoding(group.Code)
group.Name, _ = transformStringFromEncoding(group.Name)
groups = append(groups, group)
}
fieldEncodingValues = kintone.GroupField(groupField)
case kintone.CreatorField:
creatorField := fields.(kintone.CreatorField)
creatorField.Code, _ = transformStringFromEncoding(creatorField.Code)
creatorField.Name, _ = transformStringFromEncoding(creatorField.Name)
fieldEncodingValues = kintone.CreatorField(creatorField)
case kintone.ModifierField:
modifierField := fields.(kintone.ModifierField)
modifierField.Code, _ = transformStringFromEncoding(modifierField.Code)
modifierField.Name, _ = transformStringFromEncoding(modifierField.Name)
fieldEncodingValues = kintone.ModifierField(modifierField)
default:
fieldEncodingValues = fields
}
return fieldEncodingValues
}

func makeColumns(fields map[string]*kintone.FieldInfo) Columns {
columns := make([]*Column, 0)
Expand Down Expand Up @@ -343,9 +271,11 @@ func writeCsv(app *kintone.App, _writer io.Writer) error {
return err
}
}
subFieldEncoding, _ := transformStringFromEncoding(toString(subField, "\n"))
fmt.Fprint(writer, "\"")
fmt.Fprint(writer, escapeCol(subFieldEncoding))
_, err := fmt.Fprint(writer, escapeCol(toString(subField, "\n")))
if err != nil {
return err
}
fmt.Fprint(writer, "\"")
}
} else {
Expand All @@ -358,9 +288,11 @@ func writeCsv(app *kintone.App, _writer io.Writer) error {
return err
}
}
fieldEncoding, _ := transformStringFromEncoding(toString(field, "\n"))
fmt.Fprint(writer, "\"")
fmt.Fprint(writer, escapeCol(fieldEncoding))
_, err := fmt.Fprint(writer, escapeCol(toString(field, "\n")))
if err != nil {
return err
}
fmt.Fprint(writer, "\"")
}
}
Expand Down Expand Up @@ -593,26 +525,20 @@ func toString(f interface{}, delimiter string) string {
userField := f.(kintone.UserField)
users := make([]string, 0, len(userField))
for _, user := range userField {
user.Code, _ = transformStringFromEncoding(user.Code)
user.Name, _ = transformStringFromEncoding(user.Name)
users = append(users, user.Code)
}
return strings.Join(users, delimiter)
case kintone.OrganizationField:
organizationField := f.(kintone.OrganizationField)
organizations := make([]string, 0, len(organizationField))
for _, organization := range organizationField {
organization.Code, _ = transformStringFromEncoding(organization.Code)
organization.Name, _ = transformStringFromEncoding(organization.Name)
organizations = append(organizations, organization.Code)
}
return strings.Join(organizations, delimiter)
case kintone.GroupField:
groupField := f.(kintone.GroupField)
groups := make([]string, 0, len(groupField))
for _, group := range groupField {
group.Code, _ = transformStringFromEncoding(group.Code)
group.Name, _ = transformStringFromEncoding(group.Name)
groups = append(groups, group.Code)
}
return strings.Join(groups, delimiter)
Expand Down
22 changes: 1 addition & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package main

import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
Expand All @@ -13,7 +11,6 @@ import (
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"

flags "github.com/jessevdk/go-flags"
)
Expand All @@ -22,7 +19,7 @@ import (
const NAME = "cli-kintone"

// VERSION of this package
const VERSION = "0.9.1"
const VERSION = "0.9.4"

// IMPORT_ROW_LIMIT The maximum row will be import
const IMPORT_ROW_LIMIT = 100
Expand Down Expand Up @@ -272,20 +269,3 @@ func importDataFromFile(app *kintone.App) error {
}
return err
}

func transformStringFromEncoding(str string) (string, error) {
transformString := str
encoding := getEncoding()
if encoding != nil {
return transformEncoding(strings.NewReader(str), encoding.NewEncoder())
}
return transformString, nil
}

func transformEncoding(rawReader io.Reader, trans transform.Transformer) (string, error) {
ret, err := ioutil.ReadAll(transform.NewReader(rawReader, trans))
if err == nil {
return string(ret), nil
}
return string(ret), err
}

0 comments on commit 39980cd

Please sign in to comment.