Skip to content

Commit

Permalink
feat: simplfied cmd/string/string.go, dropped cli package requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdoiel committed Jan 11, 2023
1 parent 084a055 commit 9e20b54
Show file tree
Hide file tree
Showing 29 changed files with 79 additions and 240 deletions.
4 changes: 2 additions & 2 deletions cmd/csv2json/csv2json.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
os.Exit(1)
}
defer in.Close()
}
if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/csv2mdtable/csv2mdtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
os.Exit(1)
}
defer in.Close()
}
if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/csv2xlsx/csv2xlsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -223,7 +223,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/csvcleaner/csvcleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -233,7 +233,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/csvcols/csvcols.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -267,7 +267,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/csvfind/csvfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -248,7 +248,7 @@ func main() {

}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/csvjoin/csvjoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ func main() {
eout := os.Stderr


if outputFName != "" {
out, err := os.Create(outputFName)
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/csvrows/csvrows.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -214,7 +214,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/finddir/finddir.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/findfile/findfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/json2toml/json2toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -184,7 +184,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/json2yaml/json2yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -171,7 +171,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/jsoncols/jsoncols.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,19 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
fmt.Fprintf(eout, "input error %q, %q\n", inputFName, err)
os.Exit(1)
}
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintf(eout, "output error %q, %q\n", outputFName, err)
fmt.Fprintln(eout, err)
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/jsonjoin/jsonjoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout,err)
Expand All @@ -143,7 +143,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/jsonmunge/jsonmunge.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -165,7 +165,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/jsonrange/jsonrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if inputFName != "" {
if inputFName != "" && inputFName != "-" {
in, err = os.Open(inputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand All @@ -388,7 +388,7 @@ func main() {
defer in.Close()
}

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mergepath/mergepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/range/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func main() {
eout := os.Stderr


if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/reldate/reldate.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func main() {
out := os.Stdout
eout := os.Stderr

if outputFName != "" {
if outputFName != "" && outputFName != "-" {
out, err = os.Create(outputFName)
if err != nil {
fmt.Fprintln(eout, err)
Expand Down
Loading

0 comments on commit 9e20b54

Please sign in to comment.