Skip to content

Commit ebcc93d

Browse files
author
Mariano Gappa
committed
Checks for arguments before consuming STDIN. #5
1 parent 58bd0ba commit ebcc93d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

main.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ type database struct {
2222
func main() {
2323
databases := mustReadDatabasesConfigFile()
2424

25+
if len(os.Args[1:]) == 0 {
26+
usage("Target database unspecified; where should I run the query?")
27+
}
28+
2529
sql := readInput(os.Stdin)
2630
if len(sql) <= 3 {
2731
usage("No SQL to run. Exiting.")
2832
}
2933

30-
if len(os.Args[1:]) == 0 {
31-
usage("Target database unspecified; where should I run the query?")
32-
}
33-
3434
targetDatabases := []string{}
3535
for _, k := range os.Args[1:] {
3636
if _, ok := databases[k]; k != "all" && !ok {

usage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ e.g.
2525
2626
echo "SELECT * FROM users WHERE name = 'John'" | sql all
2727
28-
For more detailed help, please go to: https://github.com/MarianoGappa/sql
28+
For more detailed help, please go to: https://github.com/marianogappa/sql
2929
`)
3030
os.Exit(1)
3131
}

0 commit comments

Comments
 (0)