From f2e69603a50079f6b72d0c92daceed15b7e1bc73 Mon Sep 17 00:00:00 2001 From: Neil O'Toole Date: Wed, 19 Aug 2020 14:46:04 -0600 Subject: [PATCH] minor doc tidy (#63) --- README.md | 6 +++--- cli/output/tablew/README.md | 15 --------------- cli/output/tablew/notifywriter.go | 10 ++++++---- cli/output/tablew/{table.go => tablew.go} | 14 ++++++++++++++ libsq/source/files.go | 5 +++++ libsq/source/files_test.go | 22 +++++++++++----------- 6 files changed, 39 insertions(+), 33 deletions(-) delete mode 100644 cli/output/tablew/README.md rename cli/output/tablew/{table.go => tablew.go} (87%) diff --git a/README.md b/README.md index 548f6bde..e5043e62 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # sq: swiss army knife for data -`sq` is a swiss army knife for data. `sq` provides uniform access to +`sq` provides uniform access to structured data sources like traditional SQL-style databases, or document formats such as CSV or Excel. `sq` can perform cross-source joins, execute database-native SQL, and output to a multitude of formats including JSON, -Excel, CSV, HTML markdown and XML, or output directly to a SQL database. +Excel, CSV, HTML, Markdown and XML, or output directly to a SQL database. `sq` can inspect sources to see metadata about the source structure (tables, -columns, size) and has commands for frequent database operations such as copying +columns, size) and has commands for common database operations such as copying or dropping tables. ## Usage diff --git a/cli/output/tablew/README.md b/cli/output/tablew/README.md deleted file mode 100644 index f6d5010e..00000000 --- a/cli/output/tablew/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Package `tablew` - -Package `tablew` implements text table output writers. - -The actual rendering of the text table is handled by a modified version of -[`olekukonko/tablewriter`](https://github.com/olekukonko/tablewriter), -which can be found in the `internal` sub-package. At the time, `tablewriter` -didn't provide all the functionality that sq required. However, -that package has been significantly developed since then -fork, and it may be possible that we could dispense with the forked -version entirely and directly use a newer version of `tablewriter`. - -This entire package could use a rewrite, a lot has changed with sq -since this package was first created. So, if you see code in here -that doesn't make sense to you, you're probably judging it correctly. diff --git a/cli/output/tablew/notifywriter.go b/cli/output/tablew/notifywriter.go index e55d3523..30599729 100644 --- a/cli/output/tablew/notifywriter.go +++ b/cli/output/tablew/notifywriter.go @@ -7,18 +7,20 @@ import ( "github.com/neilotoole/sq/libsq/notify" ) -type NotifyWriter struct { +type notifyWriter struct { tbl *table } -func NewNotifyWriter(out io.Writer, fm *output.Formatting, header bool) *NotifyWriter { +// NewNotifyWriter implements output.NotificationWriter. +func NewNotifyWriter(out io.Writer, fm *output.Formatting, header bool) output.NotificationWriter { tbl := &table{out: out, header: header, fm: fm} - w := &NotifyWriter{tbl: tbl} + w := ¬ifyWriter{tbl: tbl} w.tbl.reset() return w } -func (w *NotifyWriter) NotifyDestinations(dests []notify.Destination) error { +// NotifyDestinations implements output.NotificationWriter. +func (w *notifyWriter) NotifyDestinations(dests []notify.Destination) error { w.tbl.tblImpl.SetHeader([]string{"NOTIFIER", "TYPE", "TARGET"}) var rows [][]string diff --git a/cli/output/tablew/table.go b/cli/output/tablew/tablew.go similarity index 87% rename from cli/output/tablew/table.go rename to cli/output/tablew/tablew.go index c317cff3..1fa8598e 100644 --- a/cli/output/tablew/table.go +++ b/cli/output/tablew/tablew.go @@ -1,3 +1,16 @@ +// Package tablew implements text table output writers. +// +// The actual rendering of the text table is handled by a modified +// version ofolekukonko/tablewriter which can be found in the internal +// sub-package. At the time, tablewriter didn't provide all the +// functionality that sq required. However, that package has been +// significantly developed since then fork, and it may be possible +// that we could dispense with the forked version entirely and directly +// use a newer version of tablewriter. +// +// This entire package could use a rewrite, a lot has changed with sq +// since this package was first created. So, if you see code in here +// that doesn't make sense to you, you're probably judging it correctly. package tablew import ( @@ -13,6 +26,7 @@ import ( "github.com/neilotoole/sq/libsq/stringz" ) +// table encapsulates the type table struct { fm *output.Formatting out io.Writer diff --git a/libsq/source/files.go b/libsq/source/files.go index e8a94e21..68488742 100644 --- a/libsq/source/files.go +++ b/libsq/source/files.go @@ -139,6 +139,11 @@ func (fs *Files) addFile(f *os.File, key string) (fscache.ReadAtCloser, error) { return nil, errz.Errorf("failed to add to fscache (possibly previously added): %s", key) } + // TODO: Problematically, we copy the entire contents of f into fscache. + // If f is a large file (e.g. piped over stdin), this means that + // everything is held up until f is fully copied. Hopefully we can + // do something with fscache so that the readers returned from + // fscache can lazily read from f. copied, err := io.Copy(w, f) if err != nil { fs.log.WarnIfCloseError(r) diff --git a/libsq/source/files_test.go b/libsq/source/files_test.go index 40ce9052..6bf36170 100644 --- a/libsq/source/files_test.go +++ b/libsq/source/files_test.go @@ -74,17 +74,17 @@ func TestFiles_DetectType(t *testing.T) { wantOK bool wantErr bool }{ - //{loc: proj.Abs(sakila.PathSL3), wantType: sqlite3.Type, wantOK: true}, - //{loc: proj.Abs("drivers/sqlite3/testdata/sakila_db"), wantType: sqlite3.Type, wantOK: true}, - //{loc: proj.Abs(testsrc.PathXLSXTestHeader), wantType: xlsx.Type, wantOK: true}, - //{loc: proj.Abs("drivers/xlsx/testdata/test_header_xlsx"), wantType: xlsx.Type, wantOK: true}, - //{loc: proj.Abs("drivers/xlsx/testdata/test_noheader.xlsx"), wantType: xlsx.Type, wantOK: true}, - //{loc: proj.Abs("drivers/csv/testdata/person.csv"), wantType: csv.TypeCSV, wantOK: true}, - //{loc: proj.Abs("drivers/csv/testdata/person_noheader.csv"), wantType: csv.TypeCSV, wantOK: true}, - //{loc: proj.Abs("drivers/csv/testdata/person_csv"), wantType: csv.TypeCSV, wantOK: true}, - //{loc: proj.Abs("drivers/csv/testdata/person.tsv"), wantType: csv.TypeTSV, wantOK: true}, - //{loc: proj.Abs("drivers/csv/testdata/person_noheader.tsv"), wantType: csv.TypeTSV, wantOK: true}, - //{loc: proj.Abs("drivers/csv/testdata/person_tsv"), wantType: csv.TypeTSV, wantOK: true}, + {loc: proj.Abs(sakila.PathSL3), wantType: sqlite3.Type, wantOK: true}, + {loc: proj.Abs("drivers/sqlite3/testdata/sakila_db"), wantType: sqlite3.Type, wantOK: true}, + {loc: proj.Abs(testsrc.PathXLSXTestHeader), wantType: xlsx.Type, wantOK: true}, + {loc: proj.Abs("drivers/xlsx/testdata/test_header_xlsx"), wantType: xlsx.Type, wantOK: true}, + {loc: proj.Abs("drivers/xlsx/testdata/test_noheader.xlsx"), wantType: xlsx.Type, wantOK: true}, + {loc: proj.Abs("drivers/csv/testdata/person.csv"), wantType: csv.TypeCSV, wantOK: true}, + {loc: proj.Abs("drivers/csv/testdata/person_noheader.csv"), wantType: csv.TypeCSV, wantOK: true}, + {loc: proj.Abs("drivers/csv/testdata/person_csv"), wantType: csv.TypeCSV, wantOK: true}, + {loc: proj.Abs("drivers/csv/testdata/person.tsv"), wantType: csv.TypeTSV, wantOK: true}, + {loc: proj.Abs("drivers/csv/testdata/person_noheader.tsv"), wantType: csv.TypeTSV, wantOK: true}, + {loc: proj.Abs("drivers/csv/testdata/person_tsv"), wantType: csv.TypeTSV, wantOK: true}, {loc: proj.Abs("README.md"), wantType: source.TypeNone, wantOK: false}, }