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 #71 from kintone/dev
Browse files Browse the repository at this point in the history
Release v0.11.0
  • Loading branch information
josh-vo authored Mar 12, 2020
2 parents 0fe08da + c033c33 commit be5e420
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.13.3
- 1.13.7
env: "PATH=/home/travis/gopath/bin:$PATH"
before_install:
- go get github.com/mattn/gom
Expand Down
97 changes: 19 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,7 @@ cli-kintone is a command line utility for exporting and importing kintone App da

## Version

0.10.2

## How to Build

### Requirement

- Go 1.13.3
- Git and Mercurial to be able to clone the packages

### Mac OS X/Linux
#### Step 1: Creating folder to develop
```
mkdir -p /tmp/dev-cli-kintone/src
```
Note: "/tmp/dev-cli-kintone" is the path to project at local, can be changed to match with the project at local of you.

#### Step 2: Creating variable environment GOPATH

```
export GOPATH=/tmp/dev-cli-kintone
```

#### Step 3: Getting cli-kintone repository
```
cd ${GOPATH}/src
git clone https://github.com/kintone/cli-kintone.git
```

#### Step 4: Install dependencies
```
cd ${GOPATH}/src/cli-kintone
go get github.com/mattn/gom
sudo ln -s $GOPATH/bin/gom /usr/local/bin/gom # Link package gom to directory "/usr/local/" to use globally
gom -production install
```

#### Step 5: Build
```
mv vendor/ src
gom build
```

### Windows
#### Step 1: Creating folder to develop
```
mkdir -p c:\tmp\dev-cli-kintone\src
```
Note: "c:\tmp\dev-cli-kintone" is the path to project at local, can be changed to match with the project at local of you.

#### Step 2: Creating variable environment GOPATH

```
set GOPATH=c:\tmp\dev-cli-kintone
```

#### Step 3: Getting cli-kintone repository
```
cd %GOPATH%\src
git clone https://github.com/kintone/cli-kintone.git
```

#### Step 4: Install dependencies
```
cd %GOPATH%\src\cli-kintone
go get github.com/mattn/gom
..\..\bin\gom.exe -production install
```

#### Step 5: Build
```
..\..\bin\gom.exe build
```
0.11.0

## Downloads

Expand All @@ -94,6 +23,8 @@ https://github.com/kintone/cli-kintone/releases
cli-kintone [OPTIONS]
Application Options:
--import Import data from stdin. If "-f" is also specified, data is imported from the file instead
--export Export kintone data to stdout
-d= Domain name (specify the FQDN)
-a= App ID (default: 0)
-u= User's log in name
Expand All @@ -103,7 +34,7 @@ https://github.com/kintone/cli-kintone/releases
-o= Output format. Specify either 'json' or 'csv' (default: csv)
-e= Character encoding (default: utf-8).
Only support the encoding below both field code and data itself:
'utf-8', 'utf-16', 'utf-16be-with-signature', 'utf-16le-with-signature', 'sjis' or'euc-jp'
'utf-8', 'utf-16', 'utf-16be-with-signature', 'utf-16le-with-signature', 'sjis' or'euc-jp', 'gbk' or 'big5'
-U= Basic authentication user name
-P= Basic authentication password
-q= Query string
Expand All @@ -112,8 +43,6 @@ https://github.com/kintone/cli-kintone/releases
-b= Attachment file directory
-D Delete records before insert. You can specify the deleting record condition by option "-q"
-l= Position index of data in the input file (default: 1)
--import Import data from stdin. If "-f" is also specified, data is imported from the file instead
--export Export kintone data to stdout
-v, --version Version of cli-kintone
Help Options:
Expand Down Expand Up @@ -166,16 +95,28 @@ cli-kintone --import -a <APP_ID> -d <FQDN> -t <API_TOKEN> -f <INPUT_FILE> -l 25
```
printf "name,age\nJohn,37\nJane,29" | cli-kintone --import -a <APP_ID> -d <FQDN> -t <API_TOKEN>
```
## Documents for Basic Usage
English: https://developer.kintone.io/hc/en-us/articles/115002614853
Japanese: https://developer.cybozu.io/hc/ja/articles/202957070

## Restriction
* The limit of the file upload size is 10 MB.
* Client certificates cannot be used with cli-kintone.
* The following record data cannot be retrieved: Category, Status, Field group.
* The following fields cannot be retrieved if they are set inside a Field group: Record number, Created by, Created datetime, Updated by, Updated datetime, Blank space, Label, Border.

## Documents for Basic Usage
English: https://developer.kintone.io/hc/en-us/articles/115002614853
Japanese: https://developer.cybozu.io/hc/ja/articles/202957070

## How to Build

Requirement

- Go 1.13.7
- Git and Mercurial to be able to clone the packages

[Mac OS X/Linux](./docs/BuildForMacLinux.md)

[Windows](./docs/BuildForWindows.md)

## License

GPL v2
Expand Down
36 changes: 36 additions & 0 deletions docs/BuildForMacLinux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## How to Build Mac OS X/Linux
#### Step 1: Creating folder to develop
```
mkdir -p /tmp/dev-cli-kintone/src
```
Note: "/tmp/dev-cli-kintone" is the path to project at local, can be changed to match with the project at local of you.

#### Step 2: Creating variable environment GOPATH

```
export GOPATH=/tmp/dev-cli-kintone
```

#### Step 3: Getting cli-kintone repository
```
cd ${GOPATH}/src
git clone https://github.com/kintone/cli-kintone.git
```

#### Step 4: Install dependencies
```
cd ${GOPATH}/src/cli-kintone
go get github.com/mattn/gom
sudo ln -s $GOPATH/bin/gom /usr/local/bin/gom # Link package gom to directory "/usr/local/" to use globally
gom -production install
```

#### Step 5: Build
```
mv vendor/ src
gom build
```

## Copyright

Copyright(c) Cybozu, Inc.
34 changes: 34 additions & 0 deletions docs/BuildForWindows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## How to Build Windows
#### Step 1: Creating folder to develop
```
mkdir -p c:\tmp\dev-cli-kintone\src
```
Note: "c:\tmp\dev-cli-kintone" is the path to project at local, can be changed to match with the project at local of you.

#### Step 2: Creating variable environment GOPATH

```
set GOPATH=c:\tmp\dev-cli-kintone
```

#### Step 3: Getting cli-kintone repository
```
cd %GOPATH%\src
git clone https://github.com/kintone/cli-kintone.git
```

#### Step 4: Install dependencies
```
cd %GOPATH%\src\cli-kintone
go get github.com/mattn/gom
..\..\bin\gom.exe -production install
```

#### Step 5: Build
```
..\..\bin\gom.exe build
```

## Copyright

Copyright(c) Cybozu, Inc.
6 changes: 4 additions & 2 deletions import-with-bulkRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ type SubRecord struct {
}

func getReader(reader io.Reader) io.Reader {
readerWithoutBOM := removeBOMCharacter(reader)

encoding := getEncoding()
if encoding == nil {
return reader
return readerWithoutBOM
}
return transform.NewReader(reader, encoding.NewDecoder())
return transform.NewReader(readerWithoutBOM, encoding.NewDecoder())
}

// delete specific records
Expand Down
41 changes: 11 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/howeyc/gopass"
"github.com/kintone/go-kintone"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/encoding/traditionalchinese"

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

// VERSION of this package
const VERSION = "0.10.2"
const VERSION = "0.11.0"

// IMPORT_ROW_LIMIT The maximum row will be import
const IMPORT_ROW_LIMIT = 100
Expand All @@ -30,14 +32,16 @@ const EXPORT_ROW_LIMIT = 500

// Configure of this package
type Configure struct {
IsImport bool `long:"import" description:"Import data from stdin. If \"-f\" is also specified, data is imported from the file instead"`
IsExport bool `long:"export" description:"Export kintone data to stdout"`
Domain string `short:"d" default:"" description:"Domain name (specify the FQDN)"`
AppID uint64 `short:"a" default:"0" description:"App ID"`
Login string `short:"u" default:"" description:"User's log in name"`
Password string `short:"p" default:"" description:"User's password"`
APIToken string `short:"t" default:"" description:"API token"`
GuestSpaceID uint64 `short:"g" default:"0" description:"Guest Space ID"`
Format string `short:"o" default:"csv" description:"Output format. Specify either 'json' or 'csv'"`
Encoding string `short:"e" default:"utf-8" description:"Character encoding (default: utf-8).\n Only support the encoding below both field code and data itself: \n 'utf-8', 'utf-16', 'utf-16be-with-signature', 'utf-16le-with-signature', 'sjis' or 'euc-jp'"`
Encoding string `short:"e" default:"utf-8" description:"Character encoding (default: utf-8).\n Only support the encoding below both field code and data itself: \n 'utf-8', 'utf-16', 'utf-16be-with-signature', 'utf-16le-with-signature', 'sjis' or 'euc-jp', 'gbk' or 'big5'"`
BasicAuthUser string `short:"U" default:"" description:"Basic authentication user name"`
BasicAuthPassword string `short:"P" default:"" description:"Basic authentication password"`
Query string `short:"q" default:"" description:"Query string"`
Expand All @@ -46,8 +50,6 @@ type Configure struct {
FileDir string `short:"b" default:"" description:"Attachment file directory"`
DeleteAll bool `short:"D" description:"Delete records before insert. You can specify the deleting record condition by option \"-q\""`
Line uint64 `short:"l" default:"1" description:"Position index of data in the input file"`
IsImport bool `long:"import" description:"Import data from stdin. If \"-f\" is also specified, data is imported from the file instead"`
IsExport bool `long:"export" description:"Export kintone data to stdout"`
Version bool `short:"v" long:"version" description:"Version of cli-kintone"`
}

Expand Down Expand Up @@ -77,31 +79,6 @@ type Cell struct {
// Row config
type Row []*Cell

func (p Columns) Len() int {
return len(p)
}

func (p Columns) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}

func (p Columns) Less(i, j int) bool {
p1 := p[i]
code1 := p1.Code
if p1.IsSubField {
code1 = p1.Table
}
p2 := p[j]
code2 := p2.Code
if p2.IsSubField {
code2 = p2.Table
}
if code1 == code2 {
return p[i].Code < p[j].Code
}
return code1 < code2
}

func getFields(app *kintone.App) (map[string]*kintone.FieldInfo, error) {
fields, err := app.Fields()
if err != nil {
Expand Down Expand Up @@ -196,6 +173,10 @@ func getEncoding() encoding.Encoding {
return japanese.EUCJP
case "sjis":
return japanese.ShiftJIS
case "gbk":
return simplifiedchinese.GBK
case "big5":
return traditionalchinese.Big5
default:
return nil
}
Expand Down
20 changes: 20 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"bufio"
"log"
"io"
)

func removeBOMCharacter(reader io.Reader) io.Reader {
bufferReader := bufio.NewReader(reader)
r, _, err := bufferReader.ReadRune()
if err != nil {
log.Fatal(err)
}

if r != '\uFEFF' {
bufferReader.UnreadRune() // Not a BOM -- put the rune back
}
return bufferReader
}

0 comments on commit be5e420

Please sign in to comment.