Skip to content

Commit 0e5a773

Browse files
committed
print usage when passing invalid args
1 parent c771a92 commit 0e5a773

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/cli.cr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ ip111 = false
77
ip138 = false
88
ipsb = false
99

10-
OptionParser.parse do |parser|
11-
parser.banner = <<-USAGE
10+
usage = <<-USAGE
1211
Usage:
1312
myip ip111 => get ip from http://www.ip111.cn
1413
myip ip138 => get ip info from https://www.ip138.com
1514
myip ipsb => get ip info from https://api.ip.sb/geoip
1615
1716
USAGE
1817

18+
OptionParser.parse do |parser|
19+
parser.banner = usage
1920
parser.on("-h", "--help", "Show this help message and exit") do
2021
puts parser
2122
exit
@@ -45,6 +46,8 @@ USAGE
4546
ip138 = true
4647
elsif args.includes? "ipsb"
4748
ipsb = true
49+
else
50+
STDERR.puts usage
4851
end
4952
end
5053
end

0 commit comments

Comments
 (0)