-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool
executable file
·53 lines (44 loc) · 990 Bytes
/
tool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
require 'fileutils'
require 'slop'
opts = Slop.parse do |o|
o.on '-h', '--help' do
puts o
exit
end
end
TEMPLATE = <<EOF
#!/usr/bin/env ruby
require 'slop'
opts = Slop.parse do |o|
# o.integer '-p', '--port',
# "The port to run the server on (default: 8000)",
# default: 8000
o.on '-h', '--help' do
puts o
exit
end
end
command = opts.arguments.shift
if command === "hello"
puts "Hello, CLI."
else
puts "\nERROR: Unknown command '\#{command}'\\n\\n"
puts opts
exit 1
end
EOF
command = opts.arguments.shift
if command === "new"
new_tool_name = opts.arguments.first
filename = File.expand_path(new_tool_name, "~/bin")
puts "Creating #{filename}..."
File.open(filename, "w+") { |f| f.write(TEMPLATE) }
FileUtils.chmod "+x", filename
puts "Done."
exit(0)
else
puts "\nERROR: Unknown command '#{command}'\n\n"
puts opts
exit 1
end