Commit 8674edcf authored by Dmitry Mozzherin's avatar Dmitry Mozzherin
Browse files

Close #79 make CSV the default format for CLI

parent 4f1698e3
Pipeline #143652466 passed with stages
in 3 minutes and 52 seconds
......@@ -4,8 +4,9 @@
## [v0.14.0]
- Add [#81]: Add year range in format "1888/89"
- Add [#81]: Add year range in format "1888/89".
- Add [#80]: Add Cardinality to parser outputs.
- Add [#79]: Make CSV the default format for CLI.
- Add [#78]: Take into account `non-virus` names that look like virus names.
## [v0.13.1]
......
......@@ -13,12 +13,12 @@ const (
// Pretty is a JSON nested easy to read format.
Pretty
// Simple is a flat format with only few most 'popular' fields.
Simple
CSV
// Debug is a format that shows complete and truncated AST for debugging.
Debug
)
var formats = []string{"compact", "pretty", "simple", "debug"}
var formats = []string{"compact", "pretty", "csv", "debug"}
func (of Format) String() string {
return formats[of]
......
......@@ -66,7 +66,7 @@ func OptRemoveHTML(r bool) Option {
// NewGNparser constructor function takes options and returns
// configured GNparser.
func NewGNparser(opts ...Option) GNparser {
gnp := GNparser{workersNum: runtime.NumCPU(), Format: Compact, removeHTML: true}
gnp := GNparser{workersNum: runtime.NumCPU(), Format: CSV, removeHTML: true}
for _, opt := range opts {
opt(&gnp)
}
......@@ -147,7 +147,7 @@ func (gnp GNparser) ParseAndFormat(s string) (string, error) {
return "", err
}
s = string(bs)
case Simple:
case CSV:
s = output.ToCSV(gnp.ToSlice())
}
return s, nil
......
......@@ -47,14 +47,15 @@ Parses scientific names into their semantic elements.
To see version:
gnparser -v
To parse one name:
To parse one name in CSV format
gnparser "Homo sapiens Linnaeus 1753" [flags]
or (the same)
gnparser "Homo sapiens Linnaeus 1753" -f csv [flags]
To parse one name using simple format
gnparser "Homo sapiens Linnaeus 1753" -f simple
Simple format has the following fields:
ID|Verbatim|CanonicalFull|CanonicalSimple|CanonicalStem|Authors|Year|Quality
To parse one name using JSON format:
gnparser "Homo sapiens Linnaeus 1753" -f compact [flags]
or
gnparser "Homo sapiens Linnaeus 1753" -f pretty [flags]
To parse many names from a file (one name per line):
gnparser names.txt [flags] > parsed_names.txt
......@@ -282,7 +283,7 @@ func parseFile(gnp gnparser.GNparser, f io.Reader, jobs int,
func processResults(gnp gnparser.GNparser, out <-chan *gnparser.ParseResult,
wg *sync.WaitGroup) {
defer wg.Done()
if gnp.Format == gnparser.Simple {
if gnp.Format == gnparser.CSV {
fmt.Println(output.CSVHeader())
}
for r := range out {
......@@ -299,7 +300,7 @@ func parseString(gnp gnparser.GNparser, data string) {
log.Fatal(err)
os.Exit(1)
}
if gnp.Format == gnparser.Simple {
if gnp.Format == gnparser.CSV {
fmt.Println(output.CSVHeader())
}
fmt.Println(res)
......
......@@ -49,7 +49,7 @@ var _ = Describe("Main", func() {
c.Run()
Expect(c.Success()).To(BeTrue())
Expect(c.Stdout()).
To(HavePrefix(`{"parsed":true,"quality":1,`))
To(HavePrefix(`Id,Verbatim,Cardinality,CanonicalFull`))
})
})
Describe("Stdin", func() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment