Skip to content

Commit

Permalink
Release v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mithrandie committed Jun 23, 2017
2 parents 604a3b0 + ee3cd46 commit 92acc0e
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 293 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ deploy:
api_key: $GITHUB_API_TOKEN
skip_cleanup: true
file_glob: true
prerelease: true
file: 'dist/*.{tar.gz, zip}'
on:
tags: true
18 changes: 9 additions & 9 deletions docs/_posts/2006-01-02-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ csvq [global options] [subcommand [subcommand options]] ["query"|"statements"]
* utf8
* sjis
--line-break value, -l value
: Line break. default is "lf". One of following values
* crlf
* cr
* lf
--repository value, -r value
: Directory path where files are located. Default is the current directory.
--source FILE, -s FILE
: Load query or statements from FILE
--no-header
--no-header, -n
: Import first line as a record
--without-null
--without-null, -a
: Parse empty field as empty string
--help, -h
Expand Down Expand Up @@ -69,12 +75,6 @@ csvq [global options] write [subcommand options] ["query"|"statements"]
--write-encoding value, -E value
: File encoding. Default is "utf8".
--line-break value, -l value
: Line break. default is "lf". One of following values
* crlf
* cr
* lf
--out FILE, -o FILE
: Write output to FILE. Default is empty string. Empty string is interpreted as standard output.
Expand All @@ -88,7 +88,7 @@ csvq [global options] write [subcommand options] ["query"|"statements"]
--write-delimiter value, -D value
: Field delimiter for csv format. Default is ",".
--without-header
--without-header, -N
: When format is specified as csv or tsv, write without header line
--help, -h
Expand Down
3 changes: 0 additions & 3 deletions docs/_posts/2006-01-02-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ category: reference
* [Automatic Type Casting](#automatic_type_casting)


> In this document, "decimal" means integer or float.

## Primitive Types
{: #primitive_types}

Expand Down
3 changes: 3 additions & 0 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

var appHHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
https://mithrandie.github.io/csvq
USAGE:
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}["query"]{{end}}
{{if len .Authors}}
Expand Down
4 changes: 2 additions & 2 deletions lib/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ type Flags struct {
// Global Options
Delimiter rune
Encoding Encoding
LineBreak LineBreak
Repository string
Source string
NoHeader bool
WithoutNull bool

// Write Subcommand Options
WriteEncoding Encoding
LineBreak LineBreak
OutFile string
Format Format
WriteDelimiter rune
Expand All @@ -80,12 +80,12 @@ func GetFlags() *Flags {
flags = &Flags{
Delimiter: UNDEF,
Encoding: UTF8,
LineBreak: LF,
Repository: ".",
Source: "",
NoHeader: false,
WithoutNull: false,
WriteEncoding: UTF8,
LineBreak: LF,
OutFile: "",
Format: TEXT,
WriteDelimiter: ',',
Expand Down
12 changes: 12 additions & 0 deletions lib/csv/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"

"github.com/mithrandie/csvq/lib/cmd"
"github.com/mithrandie/csvq/lib/parser"
)

Expand All @@ -21,6 +22,8 @@ type Reader struct {
column int

FieldsPerRecords int

LineBreak cmd.LineBreak
}

func NewReader(r io.Reader) *Reader {
Expand Down Expand Up @@ -221,11 +224,20 @@ func (r *Reader) isNewLine(r1 rune) bool {
case '\r':
r2, _, _ := r.reader.ReadRune()
if r2 == '\n' {
if r.LineBreak == "" {
r.LineBreak = cmd.CRLF
}
return true
}
r.reader.UnreadRune()
if r.LineBreak == "" {
r.LineBreak = cmd.CR
}
return true
case '\n':
if r.LineBreak == "" {
r.LineBreak = cmd.LF
}
return true
}
return false
Expand Down
14 changes: 14 additions & 0 deletions lib/csv/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"testing"

"github.com/mithrandie/csvq/lib/cmd"
"github.com/mithrandie/csvq/lib/parser"
)

Expand All @@ -13,6 +14,7 @@ var readAllTests = []struct {
Delimiter rune
Input string
Output [][]parser.Primary
LineBreak cmd.LineBreak
Error string
}{
{
Expand All @@ -22,6 +24,7 @@ var readAllTests = []struct {
{parser.NewString("a"), parser.NewString("b"), parser.NewString("c")},
{parser.NewString("d"), parser.NewString("e"), parser.NewString("f")},
},
LineBreak: cmd.LF,
},
{
Name: "NewLineCR",
Expand All @@ -30,6 +33,7 @@ var readAllTests = []struct {
{parser.NewString("a"), parser.NewString("b"), parser.NewString("c")},
{parser.NewString("d"), parser.NewString("e"), parser.NewString("f")},
},
LineBreak: cmd.CR,
},
{
Name: "NewLineCRLF",
Expand All @@ -38,6 +42,7 @@ var readAllTests = []struct {
{parser.NewString("a"), parser.NewString("b"), parser.NewString("c")},
{parser.NewString("d"), parser.NewString("e"), parser.NewString("f")},
},
LineBreak: cmd.CRLF,
},
{
Name: "TabDelimiter",
Expand All @@ -47,6 +52,7 @@ var readAllTests = []struct {
{parser.NewString("a"), parser.NewString("b"), parser.NewString("c")},
{parser.NewString("d"), parser.NewString("e"), parser.NewString("f")},
},
LineBreak: cmd.LF,
},
{
Name: "QuotedString",
Expand All @@ -55,6 +61,7 @@ var readAllTests = []struct {
{parser.NewString("a"), parser.NewString("b"), parser.NewString("ccc\ncc")},
{parser.NewString("d"), parser.NewString("e"), parser.NewNull()},
},
LineBreak: cmd.LF,
},
{
Name: "EscapeDoubleQuote",
Expand All @@ -63,6 +70,7 @@ var readAllTests = []struct {
{parser.NewString("a"), parser.NewString("b"), parser.NewString("ccc\"cc")},
{parser.NewString("d"), parser.NewString("e"), parser.NewString("")},
},
LineBreak: cmd.LF,
},
{
Name: "DoubleQuoteInNoQuoteField",
Expand All @@ -71,13 +79,15 @@ var readAllTests = []struct {
{parser.NewString("a"), parser.NewString("b"), parser.NewString("ccc\"cc")},
{parser.NewString("d"), parser.NewString("e"), parser.NewNull()},
},
LineBreak: cmd.LF,
},
{
Name: "SingleValue",
Input: "a",
Output: [][]parser.Primary{
{parser.NewString("a")},
},
LineBreak: "",
},
{
Name: "ExtraneousQuote",
Expand Down Expand Up @@ -123,6 +133,10 @@ func TestReader_ReadAll(t *testing.T) {
if !reflect.DeepEqual(records, v.Output) {
t.Errorf("%s: records = %q, want %q", v.Name, records, v.Output)
}

if r.LineBreak != v.LineBreak {
t.Errorf("%s: line break = %q, want %q", v.Name, r.LineBreak, v.LineBreak)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/query/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ var cursorMapOpenTests = []struct {
FileInfo: &FileInfo{
Path: GetTestFilePath("table1.csv"),
Delimiter: ',',
NoHeader: false,
Encoding: cmd.UTF8,
LineBreak: cmd.LF,
},
},
index: 0,
Expand Down
Loading

0 comments on commit 92acc0e

Please sign in to comment.