Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ijaz Ahmad
ksonnet
Commits
5cd773db
Commit
5cd773db
authored
Mar 02, 2018
by
bryanl
Browse files
upgrader deps
Signed-off-by:
bryanl
<
bryanliles@gmail.com
>
parent
b05cd344
Changes
38
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
2931 additions
and
5 deletions
+2931
-5
Gopkg.lock
Gopkg.lock
+20
-1
Gopkg.toml
Gopkg.toml
+0
-4
vendor/github.com/mattn/go-runewidth/.travis.yml
vendor/github.com/mattn/go-runewidth/.travis.yml
+8
-0
vendor/github.com/mattn/go-runewidth/LICENSE
vendor/github.com/mattn/go-runewidth/LICENSE
+21
-0
vendor/github.com/mattn/go-runewidth/README.mkd
vendor/github.com/mattn/go-runewidth/README.mkd
+27
-0
vendor/github.com/mattn/go-runewidth/runewidth.go
vendor/github.com/mattn/go-runewidth/runewidth.go
+1223
-0
vendor/github.com/mattn/go-runewidth/runewidth_js.go
vendor/github.com/mattn/go-runewidth/runewidth_js.go
+8
-0
vendor/github.com/mattn/go-runewidth/runewidth_posix.go
vendor/github.com/mattn/go-runewidth/runewidth_posix.go
+77
-0
vendor/github.com/mattn/go-runewidth/runewidth_windows.go
vendor/github.com/mattn/go-runewidth/runewidth_windows.go
+25
-0
vendor/github.com/olekukonko/tablewriter/.travis.yml
vendor/github.com/olekukonko/tablewriter/.travis.yml
+12
-0
vendor/github.com/olekukonko/tablewriter/LICENCE.md
vendor/github.com/olekukonko/tablewriter/LICENCE.md
+19
-0
vendor/github.com/olekukonko/tablewriter/README.md
vendor/github.com/olekukonko/tablewriter/README.md
+277
-0
vendor/github.com/olekukonko/tablewriter/csv.go
vendor/github.com/olekukonko/tablewriter/csv.go
+52
-0
vendor/github.com/olekukonko/tablewriter/table.go
vendor/github.com/olekukonko/tablewriter/table.go
+839
-0
vendor/github.com/olekukonko/tablewriter/table_with_color.go
vendor/github.com/olekukonko/tablewriter/table_with_color.go
+134
-0
vendor/github.com/olekukonko/tablewriter/test.csv
vendor/github.com/olekukonko/tablewriter/test.csv
+4
-0
vendor/github.com/olekukonko/tablewriter/test_info.csv
vendor/github.com/olekukonko/tablewriter/test_info.csv
+4
-0
vendor/github.com/olekukonko/tablewriter/util.go
vendor/github.com/olekukonko/tablewriter/util.go
+78
-0
vendor/github.com/olekukonko/tablewriter/wrap.go
vendor/github.com/olekukonko/tablewriter/wrap.go
+99
-0
vendor/github.com/stretchr/objx/.gitignore
vendor/github.com/stretchr/objx/.gitignore
+4
-0
No files found.
Gopkg.lock
View file @
5cd773db
...
...
@@ -255,6 +255,18 @@
packages = ["."]
revision = "fc9e8d8ef48496124e79ae0df75490096eccf6fe"
[[projects]]
name = "github.com/mattn/go-runewidth"
packages = ["."]
revision = "9e777a8366cce605130a531d2cd6363d07ad7317"
version = "v0.0.2"
[[projects]]
branch = "master"
name = "github.com/olekukonko/tablewriter"
packages = ["."]
revision = "b8a9be070da40449e501c3c4730a889e42d87a9e"
[[projects]]
name = "github.com/onsi/ginkgo"
packages = [
...
...
@@ -359,10 +371,17 @@
packages = ["."]
revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66"
[[projects]]
name = "github.com/stretchr/objx"
packages = ["."]
revision = "facf9a85c22f48d2f52f2380e4efce1768749a89"
version = "v0.1"
[[projects]]
name = "github.com/stretchr/testify"
packages = [
"assert",
"mock",
"require"
]
revision = "f6abca593680b2315d2075e0f5e2a9751e3f431a"
...
...
@@ -603,6 +622,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "
8b786abd404b80a5933fdf9b29cae67837bf6630041f144bffd7092fdb0e331c
"
inputs-digest = "
cb1ea2fcb93a4e383a77524868cca62997ccf5e8b862f2d8250c388870c4da49
"
solver-name = "gps-cdcl"
solver-version = 1
Gopkg.toml
View file @
5cd773db
...
...
@@ -32,10 +32,6 @@
name
=
"github.com/emicklei/go-restful-swagger12"
revision
=
"7524189396c68dc4b04d53852f9edc00f816b123"
[[constraint]]
name
=
"github.com/fatih/color"
revision
=
"5df930a27be2502f99b292b7cc09ebad4d0891f4"
[[constraint]]
name
=
"github.com/ghodss/yaml"
revision
=
"0ca9ea5df5451ffdf184b4428c902747c2c11cd7"
...
...
vendor/github.com/mattn/go-runewidth/.travis.yml
0 → 100644
View file @
5cd773db
language
:
go
go
:
-
tip
before_install
:
-
go get github.com/mattn/goveralls
-
go get golang.org/x/tools/cmd/cover
script
:
-
$HOME/gopath/bin/goveralls -repotoken lAKAWPzcGsD3A8yBX3BGGtRUdJ6CaGERL
vendor/github.com/mattn/go-runewidth/LICENSE
0 → 100644
View file @
5cd773db
The MIT License (MIT)
Copyright (c) 2016 Yasuhiro Matsumoto
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
vendor/github.com/mattn/go-runewidth/README.mkd
0 → 100644
View file @
5cd773db
go-runewidth
============
[

](https://travis-ci.org/mattn/go-runewidth)
[

](https://coveralls.io/r/mattn/go-runewidth?branch=HEAD)
[

](http://godoc.org/github.com/mattn/go-runewidth)
[

](https://goreportcard.com/report/github.com/mattn/go-runewidth)
Provides functions to get fixed width of the character or string.
Usage
-----
```
go
runewidth
.
StringWidth
(
"つのだ☆HIRO"
)
==
12
```
Author
------
Yasuhiro Matsumoto
License
-------
under the MIT License: http://mattn.mit-license.org/2013
vendor/github.com/mattn/go-runewidth/runewidth.go
0 → 100644
View file @
5cd773db
This diff is collapsed.
Click to expand it.
vendor/github.com/mattn/go-runewidth/runewidth_js.go
0 → 100644
View file @
5cd773db
// +build js
package
runewidth
func
IsEastAsian
()
bool
{
// TODO: Implement this for the web. Detect east asian in a compatible way, and return true.
return
false
}
vendor/github.com/mattn/go-runewidth/runewidth_posix.go
0 → 100644
View file @
5cd773db
// +build !windows,!js
package
runewidth
import
(
"os"
"regexp"
"strings"
)
var
reLoc
=
regexp
.
MustCompile
(
`^[a-z][a-z][a-z]?(?:_[A-Z][A-Z])?\.(.+)`
)
var
mblenTable
=
map
[
string
]
int
{
"utf-8"
:
6
,
"utf8"
:
6
,
"jis"
:
8
,
"eucjp"
:
3
,
"euckr"
:
2
,
"euccn"
:
2
,
"sjis"
:
2
,
"cp932"
:
2
,
"cp51932"
:
2
,
"cp936"
:
2
,
"cp949"
:
2
,
"cp950"
:
2
,
"big5"
:
2
,
"gbk"
:
2
,
"gb2312"
:
2
,
}
func
isEastAsian
(
locale
string
)
bool
{
charset
:=
strings
.
ToLower
(
locale
)
r
:=
reLoc
.
FindStringSubmatch
(
locale
)
if
len
(
r
)
==
2
{
charset
=
strings
.
ToLower
(
r
[
1
])
}
if
strings
.
HasSuffix
(
charset
,
"@cjk_narrow"
)
{
return
false
}
for
pos
,
b
:=
range
[]
byte
(
charset
)
{
if
b
==
'@'
{
charset
=
charset
[
:
pos
]
break
}
}
max
:=
1
if
m
,
ok
:=
mblenTable
[
charset
];
ok
{
max
=
m
}
if
max
>
1
&&
(
charset
[
0
]
!=
'u'
||
strings
.
HasPrefix
(
locale
,
"ja"
)
||
strings
.
HasPrefix
(
locale
,
"ko"
)
||
strings
.
HasPrefix
(
locale
,
"zh"
))
{
return
true
}
return
false
}
// IsEastAsian return true if the current locale is CJK
func
IsEastAsian
()
bool
{
locale
:=
os
.
Getenv
(
"LC_CTYPE"
)
if
locale
==
""
{
locale
=
os
.
Getenv
(
"LANG"
)
}
// ignore C locale
if
locale
==
"POSIX"
||
locale
==
"C"
{
return
false
}
if
len
(
locale
)
>
1
&&
locale
[
0
]
==
'C'
&&
(
locale
[
1
]
==
'.'
||
locale
[
1
]
==
'-'
)
{
return
false
}
return
isEastAsian
(
locale
)
}
vendor/github.com/mattn/go-runewidth/runewidth_windows.go
0 → 100644
View file @
5cd773db
package
runewidth
import
(
"syscall"
)
var
(
kernel32
=
syscall
.
NewLazyDLL
(
"kernel32"
)
procGetConsoleOutputCP
=
kernel32
.
NewProc
(
"GetConsoleOutputCP"
)
)
// IsEastAsian return true if the current locale is CJK
func
IsEastAsian
()
bool
{
r1
,
_
,
_
:=
procGetConsoleOutputCP
.
Call
()
if
r1
==
0
{
return
false
}
switch
int
(
r1
)
{
case
932
,
51932
,
936
,
949
,
950
:
return
true
}
return
false
}
vendor/github.com/olekukonko/tablewriter/.travis.yml
0 → 100644
View file @
5cd773db
language
:
go
go
:
-
1.1
-
1.2
-
1.3
-
1.4
-
1.5
-
1.6
-
1.7
-
1.8
-
tip
vendor/github.com/olekukonko/tablewriter/LICENCE.md
0 → 100644
View file @
5cd773db
Copyright (C) 2014 by Oleku Konko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
\ No newline at end of file
vendor/github.com/olekukonko/tablewriter/README.md
0 → 100644
View file @
5cd773db
ASCII Table Writer
=========
[

](https://travis-ci.org/olekukonko/tablewriter)
[

](https://sourcegraph.com/github.com/olekukonko/tablewriter)
[

](https://godoc.org/github.com/olekukonko/tablewriter)
Generate ASCII table on the fly ... Installation is simple as
go get github.com/olekukonko/tablewriter
#### Features
-
Automatic Padding
-
Support Multiple Lines
-
Supports Alignment
-
Support Custom Separators
-
Automatic Alignment of numbers & percentage
-
Write directly to http , file etc via
`io.Writer`
-
Read directly from CSV file
-
Optional row line via
`SetRowLine`
-
Normalise table header
-
Make CSV Headers optional
-
Enable or disable table border
-
Set custom footer support
-
Optional identical cells merging
-
Set custom caption
-
Optional reflowing of paragrpahs in multi-line cells.
#### Example 1 - Basic
```
go
data
:=
[][]
string
{
[]
string
{
"A"
,
"The Good"
,
"500"
},
[]
string
{
"B"
,
"The Very very Bad Man"
,
"288"
},
[]
string
{
"C"
,
"The Ugly"
,
"120"
},
[]
string
{
"D"
,
"The Gopher"
,
"800"
},
}
table
:=
tablewriter
.
NewWriter
(
os
.
Stdout
)
table
.
SetHeader
([]
string
{
"Name"
,
"Sign"
,
"Rating"
})
for
_
,
v
:=
range
data
{
table
.
Append
(
v
)
}
table
.
Render
()
// Send output
```
##### Output 1
```
+------+-----------------------+--------+
| NAME | SIGN | RATING |
+------+-----------------------+--------+
| A | The Good | 500 |
| B | The Very very Bad Man | 288 |
| C | The Ugly | 120 |
| D | The Gopher | 800 |
+------+-----------------------+--------+
```
#### Example 2 - Without Border / Footer / Bulk Append
```
go
data
:=
[][]
string
{
[]
string
{
"1/1/2014"
,
"Domain name"
,
"2233"
,
"$10.98"
},
[]
string
{
"1/1/2014"
,
"January Hosting"
,
"2233"
,
"$54.95"
},
[]
string
{
"1/4/2014"
,
"February Hosting"
,
"2233"
,
"$51.00"
},
[]
string
{
"1/4/2014"
,
"February Extra Bandwidth"
,
"2233"
,
"$30.00"
},
}
table
:=
tablewriter
.
NewWriter
(
os
.
Stdout
)
table
.
SetHeader
([]
string
{
"Date"
,
"Description"
,
"CV2"
,
"Amount"
})
table
.
SetFooter
([]
string
{
""
,
""
,
"Total"
,
"$146.93"
})
// Add Footer
table
.
SetBorder
(
false
)
// Set Border to false
table
.
AppendBulk
(
data
)
// Add Bulk Data
table
.
Render
()
```
##### Output 2
```
DATE | DESCRIPTION | CV2 | AMOUNT
+----------+--------------------------+-------+---------+
1/1/2014 | Domain name | 2233 | $10.98
1/1/2014 | January Hosting | 2233 | $54.95
1/4/2014 | February Hosting | 2233 | $51.00
1/4/2014 | February Extra Bandwidth | 2233 | $30.00
+----------+--------------------------+-------+---------+
TOTAL | $146 93
+-------+---------+
```
#### Example 3 - CSV
```
go
table
,
_
:=
tablewriter
.
NewCSV
(
os
.
Stdout
,
"test_info.csv"
,
true
)
table
.
SetAlignment
(
tablewriter
.
ALIGN_LEFT
)
// Set Alignment
table
.
Render
()
```
##### Output 3
```
+----------+--------------+------+-----+---------+----------------+
| FIELD | TYPE | NULL | KEY | DEFAULT | EXTRA |
+----------+--------------+------+-----+---------+----------------+
| user_id | smallint(5) | NO | PRI | NULL | auto_increment |
| username | varchar(10) | NO | | NULL | |
| password | varchar(100) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+
```
#### Example 4 - Custom Separator
```
go
table
,
_
:=
tablewriter
.
NewCSV
(
os
.
Stdout
,
"test.csv"
,
true
)
table
.
SetRowLine
(
true
)
// Enable row line
// Change table lines
table
.
SetCenterSeparator
(
"*"
)
table
.
SetColumnSeparator
(
"‡"
)
table
.
SetRowSeparator
(
"-"
)
table
.
SetAlignment
(
tablewriter
.
ALIGN_LEFT
)
table
.
Render
()
```
##### Output 4
```
*------------*-----------*---------*
╪ FIRST NAME ╪ LAST NAME ╪ SSN ╪
*------------*-----------*---------*
╪ John ╪ Barry ╪ 123456 ╪
*------------*-----------*---------*
╪ Kathy ╪ Smith ╪ 687987 ╪
*------------*-----------*---------*
╪ Bob ╪ McCornick ╪ 3979870 ╪
*------------*-----------*---------*
```
#### Example 5 - Markdown Format
```
go
data
:=
[][]
string
{
[]
string
{
"1/1/2014"
,
"Domain name"
,
"2233"
,
"$10.98"
},
[]
string
{
"1/1/2014"
,
"January Hosting"
,
"2233"
,
"$54.95"
},
[]
string
{
"1/4/2014"
,
"February Hosting"
,
"2233"
,
"$51.00"
},
[]
string
{
"1/4/2014"
,
"February Extra Bandwidth"
,
"2233"
,
"$30.00"
},
}
table
:=
tablewriter
.
NewWriter
(
os
.
Stdout
)
table
.
SetHeader
([]
string
{
"Date"
,
"Description"
,
"CV2"
,
"Amount"
})
table
.
SetBorders
(
tablewriter
.
Border
{
Left
:
true
,
Top
:
false
,
Right
:
true
,
Bottom
:
false
})
table
.
SetCenterSeparator
(
"|"
)
table
.
AppendBulk
(
data
)
// Add Bulk Data
table
.
Render
()
```
##### Output 5
```
| DATE | DESCRIPTION | CV2 | AMOUNT |
|----------|--------------------------|------|--------|
| 1/1/2014 | Domain name | 2233 | $10.98 |
| 1/1/2014 | January Hosting | 2233 | $54.95 |
| 1/4/2014 | February Hosting | 2233 | $51.00 |
| 1/4/2014 | February Extra Bandwidth | 2233 | $30.00 |
```
#### Example 6 - Identical cells merging
```
go
data
:=
[][]
string
{
[]
string
{
"1/1/2014"
,
"Domain name"
,
"1234"
,
"$10.98"
},
[]
string
{
"1/1/2014"
,
"January Hosting"
,
"2345"
,
"$54.95"
},
[]
string
{
"1/4/2014"
,
"February Hosting"
,
"3456"
,
"$51.00"
},
[]
string
{
"1/4/2014"
,
"February Extra Bandwidth"
,
"4567"
,
"$30.00"
},
}
table
:=
tablewriter
.
NewWriter
(
os
.
Stdout
)
table
.
SetHeader
([]
string
{
"Date"
,
"Description"
,
"CV2"
,
"Amount"
})
table
.
SetFooter
([]
string
{
""
,
""
,
"Total"
,
"$146.93"
})
table
.
SetAutoMergeCells
(
true
)
table
.
SetRowLine
(
true
)
table
.
AppendBulk
(
data
)
table
.
Render
()
```
##### Output 6
```
+----------+--------------------------+-------+---------+
| DATE | DESCRIPTION | CV2 | AMOUNT |
+----------+--------------------------+-------+---------+
| 1/1/2014 | Domain name | 1234 | $10.98 |
+ +--------------------------+-------+---------+
| | January Hosting | 2345 | $54.95 |
+----------+--------------------------+-------+---------+
| 1/4/2014 | February Hosting | 3456 | $51.00 |
+ +--------------------------+-------+---------+
| | February Extra Bandwidth | 4567 | $30.00 |
+----------+--------------------------+-------+---------+
| TOTAL | $146 93 |
+----------+--------------------------+-------+---------+
```
#### Table with color
```
go
data
:=
[][]
string
{
[]
string
{
"1/1/2014"
,
"Domain name"
,
"2233"
,
"$10.98"
},
[]
string
{
"1/1/2014"
,
"January Hosting"
,
"2233"
,
"$54.95"
},
[]
string
{
"1/4/2014"
,
"February Hosting"
,
"2233"
,
"$51.00"
},
[]
string
{
"1/4/2014"
,
"February Extra Bandwidth"
,
"2233"
,
"$30.00"
},
}
table
:=
tablewriter
.
NewWriter
(
os
.
Stdout
)
table
.
SetHeader
([]
string
{
"Date"
,
"Description"
,
"CV2"
,
"Amount"
})
table
.
SetFooter
([]
string
{
""
,
""
,
"Total"
,
"$146.93"
})
// Add Footer
table
.
SetBorder
(
false
)
// Set Border to false
table
.
SetHeaderColor
(
tablewriter
.
Colors
{
tablewriter
.
Bold
,
tablewriter
.
BgGreenColor
},
tablewriter
.
Colors
{
tablewriter
.
FgHiRedColor
,
tablewriter
.
Bold
,
tablewriter
.
BgBlackColor
},
tablewriter
.
Colors
{
tablewriter
.
BgRedColor
,
tablewriter
.
FgWhiteColor
},
tablewriter
.
Colors
{
tablewriter
.
BgCyanColor
,
tablewriter
.
FgWhiteColor
})
table
.
SetColumnColor
(
tablewriter
.
Colors
{
tablewriter
.
Bold
,
tablewriter
.
FgHiBlackColor
},
tablewriter
.
Colors
{
tablewriter
.
Bold
,
tablewriter
.
FgHiRedColor
},
tablewriter
.
Colors
{
tablewriter
.
Bold
,
tablewriter
.
FgHiBlackColor
},
tablewriter
.
Colors
{
tablewriter
.
Bold
,
tablewriter
.
FgBlackColor
})
table
.
SetFooterColor
(
tablewriter
.
Colors
{},
tablewriter
.
Colors
{},
tablewriter
.
Colors
{
tablewriter
.
Bold
},
tablewriter
.
Colors
{
tablewriter
.
FgHiRedColor
})
table
.
AppendBulk
(
data
)
table
.
Render
()
```
#### Table with color Output

#### Example 6 - Set table caption
```
go
data
:=
[][]
string
{
[]
string
{
"A"
,
"The Good"
,
"500"
},
[]
string
{
"B"
,
"The Very very Bad Man"
,
"288"
},
[]
string
{
"C"
,
"The Ugly"
,
"120"
},
[]
string
{
"D"
,
"The Gopher"
,
"800"
},
}
table
:=
tablewriter
.
NewWriter
(
os
.
Stdout
)
table
.
SetHeader
([]
string
{
"Name"
,
"Sign"
,
"Rating"
})
table
.
SetCaption
(
true
,
"Movie ratings."
)
for
_
,
v
:=
range
data
{
table
.
Append
(
v
)
}
table
.
Render
()
// Send output
```
Note: Caption text will wrap with total width of rendered table.
##### Output 6
```
+------+-----------------------+--------+
| NAME | SIGN | RATING |
+------+-----------------------+--------+
| A | The Good | 500 |
| B | The Very very Bad Man | 288 |
| C | The Ugly | 120 |
| D | The Gopher | 800 |
+------+-----------------------+--------+
Movie ratings.
```
#### TODO
-
~~Import Directly from CSV~~ -
`done`
-
~~Support for
`SetFooter`
~~ -
`done`
-
~~Support for
`SetBorder`
~~ -
`done`
-
~~Support table with uneven rows~~ -
`done`
-
~~Support custom alignment~~
-
General Improvement & Optimisation
-
`NewHTML`
Parse table from HTML
vendor/github.com/olekukonko/tablewriter/csv.go
0 → 100644
View file @
5cd773db
// Copyright 2014 Oleku Konko All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
// This module is a Table Writer API for the Go Programming Language.
// The protocols were written in pure Go and works on windows and unix systems
package
tablewriter
import
(
"encoding/csv"
"io"
"os"
)
// Start A new table by importing from a CSV file
// Takes io.Writer and csv File name
func
NewCSV
(
writer
io
.
Writer
,
fileName
string
,
hasHeader
bool
)
(
*
Table
,
error
)
{
file
,
err
:=
os
.
Open
(
fileName
)
if
err
!=
nil
{
return
&
Table
{},
err
}
defer
file
.
Close
()
csvReader
:=
csv
.
NewReader
(
file
)
t
,
err
:=
NewCSVReader
(
writer
,
csvReader
,
hasHeader
)
return
t
,
err
}
// Start a New Table Writer with csv.Reader
// This enables customisation such as reader.Comma = ';'
// See http://golang.org/src/pkg/encoding/csv/reader.go?s=3213:3671#L94
func
NewCSVReader
(
writer
io
.
Writer
,
csvReader
*
csv
.
Reader
,
hasHeader
bool
)
(
*
Table
,
error
)
{
t
:=
NewWriter
(
writer
)
if
hasHeader
{
// Read the first row
headers
,
err
:=
csvReader
.
Read
()
if
err
!=
nil
{
return
&
Table
{},
err
}
t
.
SetHeader
(
headers
)
}
for
{
record
,
err
:=
csvReader
.
Read
()
if
err
==
io
.
EOF
{
break
}
else
if
err
!=
nil
{
return
&
Table
{},
err
}
t
.
Append
(
record
)
}
return
t
,
nil
}
vendor/github.com/olekukonko/tablewriter/table.go
0 → 100644
View file @
5cd773db
// Copyright 2014 Oleku Konko All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.