Skip to content

Commit 084a055

Browse files
committed
debugging depreciation of cli package in datatools
1 parent 5076793 commit 084a055

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1179
-1175
lines changed

cmd/csvcols/csvcols.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//
21
// csvcols - is a command line that takes each argument in order and outputs a line in CSV format.
32
// It can also take a delimiter and line of text splitting it into a CSV formatted set of columns.
43
//
@@ -16,7 +15,6 @@
1615
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1716
//
1817
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19-
//
2018
package main
2119

2220
import (
@@ -134,7 +132,6 @@ Using options filter a 3 column CSV file for columns 1,3 into 2col.csv
134132
135133
`
136134

137-
138135
// Standard Options
139136
showHelp bool
140137
showLicense bool
@@ -204,7 +201,7 @@ func CSVColumns(in *os.File, out *os.File, eout *os.File, columnNos []int, prefi
204201
if err == io.EOF {
205202
break
206203
}
207-
if err != nil && ! quiet{
204+
if err != nil && !quiet {
208205
fmt.Fprintln(eout, err)
209206

210207
}
@@ -261,24 +258,23 @@ func main() {
261258
out := os.Stdout
262259
eout := os.Stderr
263260

264-
265-
if inputFName != "" {
266-
in, err = os.Open(inputFName)
267-
if err != nil {
268-
fmt.Fprintln(eout, err)
269-
os.Exit(1)
261+
if inputFName != "" {
262+
in, err = os.Open(inputFName)
263+
if err != nil {
264+
fmt.Fprintln(eout, err)
265+
os.Exit(1)
266+
}
267+
defer in.Close()
270268
}
271-
defer in.Close()
272-
}
273269

274-
if outputFName != "" {
275-
out, err := os.Create(outputFName)
276-
if err != nil {
277-
fmt.Fprintln(eout, err)
278-
os.Exit(1)
270+
if outputFName != "" {
271+
out, err = os.Create(outputFName)
272+
if err != nil {
273+
fmt.Fprintln(eout, err)
274+
os.Exit(1)
275+
}
276+
defer out.Close()
279277
}
280-
defer out.Close()
281-
}
282278

283279
// Process options
284280
if showHelp {

cmd/csvfind/csvfind.go

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//
21
// csvfind - is a command line that takes CSV files in returns the rows that match a column value.
32
//
43
// @author R. S. Doiel, <[email protected]>
@@ -15,7 +14,6 @@
1514
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1615
//
1716
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18-
//
1917
package main
2018

2119
import (
@@ -156,7 +154,6 @@ You can also search for phrases in columns.
156154
{app_name} {version}
157155
`
158156

159-
160157
// Standard Options
161158
showHelp bool
162159
showLicense bool
@@ -209,7 +206,6 @@ func main() {
209206
flag.BoolVar(&newLine, "nl", true, "include trailing newline from output")
210207
flag.BoolVar(&newLine, "newline", true, "include trailing newline from output")
211208

212-
213209
// App Options
214210
flag.IntVar(&col, "col", 0, "column to search for match in the CSV file")
215211
flag.IntVar(&col, "cols", 0, "column to search for match in the CSV file")
@@ -226,7 +222,8 @@ func main() {
226222
flag.StringVar(&stopWordsOption, "stop-words", "", "use the colon delimited list of stop words")
227223
flag.BoolVar(&skipHeaderRow, "skip-header-row", true, "skip the header row")
228224
flag.BoolVar(&allowDuplicates, "allow-duplicates", true, "allow duplicates when searching for matches")
229-
flag.BoolVar(&trimSpaces, "trimspace,trimspaces", false, "trim spaces around cell values before comparing")
225+
flag.BoolVar(&trimSpaces, "trimspace", false, "trim spaces around cell values before comparing")
226+
flag.BoolVar(&trimSpaces, "trimspaces", false, "trim spaces around cell values before comparing")
230227
flag.BoolVar(&lazyQuotes, "use-lazy-quotes", false, "use lazy quotes on CSV input")
231228
flag.BoolVar(&trimLeadingSpace, "trim-leading-space", false, "trim leadings space in field(s) for CSV input")
232229

@@ -241,25 +238,24 @@ func main() {
241238
out := os.Stdout
242239
eout := os.Stderr
243240

244-
if inputFName != "" {
245-
in, err := os.Open(inputFName)
246-
if err != nil {
247-
fmt.Fprintln(eout, err)
248-
os.Exit(1)
249-
}
250-
defer in.Close()
251-
252-
}
241+
if inputFName != "" {
242+
in, err = os.Open(inputFName)
243+
if err != nil {
244+
fmt.Fprintln(eout, err)
245+
os.Exit(1)
246+
}
247+
defer in.Close()
253248

254-
if outputFName != "" {
255-
out, err := os.Create(outputFName)
256-
if err != nil {
257-
fmt.Fprintln(eout, err)
258-
os.Exit(1)
259249
}
260-
defer out.Close()
261-
}
262250

251+
if outputFName != "" {
252+
out, err = os.Create(outputFName)
253+
if err != nil {
254+
fmt.Fprintln(eout, err)
255+
os.Exit(1)
256+
}
257+
defer out.Close()
258+
}
263259

264260
// Process options
265261
if showHelp {
@@ -321,7 +317,7 @@ if outputFName != "" {
321317
break
322318
}
323319
if err != nil {
324-
if ! quiet {
320+
if !quiet {
325321
fmt.Fprintf(eout, "%d %s\n", lineNo, err)
326322
}
327323
} else {
@@ -347,7 +343,7 @@ if outputFName != "" {
347343
if strings.Contains(src, target) {
348344
err := csvOut.Write(record)
349345
if err != nil {
350-
if ! quiet {
346+
if !quiet {
351347
fmt.Fprintf(eout, "%d %s\n", lineNo, err)
352348
}
353349
}
@@ -360,7 +356,7 @@ if outputFName != "" {
360356
}
361357
err := csvOut.Write(record)
362358
if err != nil {
363-
if ! quiet {
359+
if !quiet {
364360
fmt.Fprintf(eout, "%d %s\n", lineNo, err)
365361
}
366362
}
@@ -369,7 +365,7 @@ if outputFName != "" {
369365
if strings.Compare(src, target) == 0 {
370366
err := csvOut.Write(record)
371367
if err != nil {
372-
if ! quiet {
368+
if !quiet {
373369
fmt.Fprintf(eout, "%d %s\n", lineNo, err)
374370
}
375371
}
@@ -379,7 +375,7 @@ if outputFName != "" {
379375
break
380376
}
381377
} else {
382-
if ! quiet {
378+
if !quiet {
383379
fmt.Fprintf(eout, "%d line skipped, missing column %d\n", lineNo, col)
384380
}
385381
}

cmd/csvrows/csvrows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func main() {
215215
}
216216

217217
if outputFName != "" {
218-
out, err := os.Create(outputFName)
218+
out, err = os.Create(outputFName)
219219
if err != nil {
220220
fmt.Fprintln(eout, err)
221221
os.Exit(1)

cmd/range/range.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,16 @@ func main() {
191191
flag.BoolVar(&showVersion, "version", false, "display version")
192192

193193
flag.BoolVar(&quiet, "quiet", false, "suppress error messages")
194-
flag.BoolVar(&newLine, "nl,newline", false, "if true add a trailing newline")
195-
flag.BoolVar(&newLine, "nl,newline", false, "if true add a trailing newline")
194+
flag.BoolVar(&newLine, "nl", false, "if true add a trailing newline")
195+
flag.BoolVar(&newLine, "newline", false, "if true add a trailing newline")
196196

197197
// App specific options
198-
flag.IntVar(&start, "s,start", 0, startUsage)
199-
flag.IntVar(&start, "s,start", 0, startUsage)
200-
flag.IntVar(&end, "e,end", 0, endUsage)
201-
flag.IntVar(&end, "e,end", 0, endUsage)
202-
flag.IntVar(&increment, "inc,increment", 1, incUsage)
203-
flag.IntVar(&increment, "inc,increment", 1, incUsage)
198+
flag.IntVar(&start, "s", 0, startUsage)
199+
flag.IntVar(&start, "start", 0, startUsage)
200+
flag.IntVar(&end, "e", 0, endUsage)
201+
flag.IntVar(&end, "end", 0, endUsage)
202+
flag.IntVar(&increment, "inc", 1, incUsage)
203+
flag.IntVar(&increment, "increment", 1, incUsage)
204204
flag.BoolVar(&randomElement, "random", false, "Pick a range value from range")
205205

206206
// Parse env and options

0 commit comments

Comments
 (0)