bales 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bales/application.rb +11 -8
- data/lib/bales/command/help.rb +5 -0
- data/lib/bales/command.rb +54 -0
- data/lib/bales/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4301c3b933852b3c9cd2f1e66b2adc6c31fa5e7f
|
4
|
+
data.tar.gz: 41e05ffb0f56874d16f38508d038d337a507a0b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbfbacab09a7b0b517f23703fa811106091625006a1e273447a7814464c99702a85c3611442a78b219f3ec81c3ed2287aaca545a079bc2c5660f198592b4f1d5
|
7
|
+
data.tar.gz: 402eb19431e501717fdd54a9202ba898d0865379dda6f689b7609e56ee0f806b34f58d36fdafd5c2b6e6fcbca3c213e99a2ac5e9fc70188f516803dd83f11cea
|
data/lib/bales/application.rb
CHANGED
@@ -130,21 +130,15 @@ module Bales
|
|
130
130
|
command ||= default_command
|
131
131
|
opts, args = command.parse_opts result
|
132
132
|
return command, args, opts
|
133
|
-
end
|
134
|
-
|
135
|
-
##
|
136
|
-
# Parses ARGV (or some other array if you specify one) for a
|
137
|
-
# command to run and its arguments/options, then runs the command.
|
138
|
-
def self.parse_and_run(argv=ARGV)
|
139
|
-
command, args, opts = parse argv
|
140
|
-
run command, *args, **opts
|
141
133
|
rescue OptionParser::MissingArgument
|
142
134
|
flag = $!.message.gsub("missing argument: ", '')
|
143
135
|
puts "#{$0}: error: option needs an argument (#{flag})"
|
136
|
+
puts "Usage: #{command.usage}"
|
144
137
|
exit!
|
145
138
|
rescue OptionParser::InvalidOption
|
146
139
|
flag = $!.message.gsub("invalid option: ", '')
|
147
140
|
puts "#{$0}: error: unknown option (#{flag})"
|
141
|
+
puts "Usage: #{command.usage}"
|
148
142
|
exit!
|
149
143
|
rescue ArgumentError
|
150
144
|
raise unless $!.message.match(/wrong number of arguments/)
|
@@ -154,9 +148,18 @@ module Bales
|
|
154
148
|
.gsub(")", '')
|
155
149
|
.split(" for ")
|
156
150
|
puts "#{$0}: error: expected #{expected} args but got #{received}"
|
151
|
+
puts "Usage: #{command.usage}"
|
157
152
|
exit!
|
158
153
|
end
|
159
154
|
|
155
|
+
##
|
156
|
+
# Parses ARGV (or some other array if you specify one) for a
|
157
|
+
# command to run and its arguments/options, then runs the command.
|
158
|
+
def self.parse_and_run(argv=ARGV)
|
159
|
+
command, args, opts = parse argv
|
160
|
+
run command, *args, **opts
|
161
|
+
end
|
162
|
+
|
160
163
|
private
|
161
164
|
|
162
165
|
def self.parse_command_name(argv)
|
data/lib/bales/command/help.rb
CHANGED
@@ -13,6 +13,7 @@ class Bales::Command::Help < Bales::Command
|
|
13
13
|
target = basename
|
14
14
|
end
|
15
15
|
|
16
|
+
print_usage(target)
|
16
17
|
print_summary(target)
|
17
18
|
print_options(target)
|
18
19
|
print_commands(target)
|
@@ -109,6 +110,10 @@ class Bales::Command::Help < Bales::Command
|
|
109
110
|
print "Description:\n#{command.description}\n\n"
|
110
111
|
end
|
111
112
|
|
113
|
+
def self.print_usage(command)
|
114
|
+
print "Usage: #{command.usage}\n\n"
|
115
|
+
end
|
116
|
+
|
112
117
|
def self.print_commands(namespace)
|
113
118
|
cmds = commands(namespace)
|
114
119
|
|
data/lib/bales/command.rb
CHANGED
@@ -93,6 +93,60 @@ module Bales
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
##
|
97
|
+
# Translates the command's class name to a more complete name
|
98
|
+
# passed on the command line, including the subcommand, all
|
99
|
+
# commands leading to it, and the root command.
|
100
|
+
def self.full_name
|
101
|
+
parts = self
|
102
|
+
.name
|
103
|
+
.split('::')
|
104
|
+
.map { |p| p.gsub(/(.)([A-Z])/, '\1-\2').downcase }
|
105
|
+
parts = parts[2..-1].join(' ')
|
106
|
+
"#{$0} #{parts}"
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Print the command's usage statement.
|
111
|
+
def self.usage
|
112
|
+
usage = []
|
113
|
+
|
114
|
+
# Name
|
115
|
+
usage << full_name
|
116
|
+
|
117
|
+
# Arguments
|
118
|
+
method(:run).parameters.each do |type, name|
|
119
|
+
# We don't handle keys and keyrests, since they're going to be
|
120
|
+
# taken care of once we start dealing with options.
|
121
|
+
case type
|
122
|
+
when :req then usage << "<#{name}>"
|
123
|
+
when :opt then usage << "[<#{name}>]"
|
124
|
+
when :rest then usage << "[<#{name}> ...]"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Options
|
129
|
+
options.each_pair do |opt, args|
|
130
|
+
case
|
131
|
+
when (args[:type] <= TrueClass or args[:type] <= FalseClass)
|
132
|
+
if args.key?(:short_form)
|
133
|
+
usage << "[(#{args[:long_form]}|#{args[:short_form]})]"
|
134
|
+
else
|
135
|
+
usage << "[#{args[:long_form]}]"
|
136
|
+
end
|
137
|
+
else
|
138
|
+
if args.key?(:short_form)
|
139
|
+
usage << "[(#{args[:long_form]}|#{args[:short_form]}) " \
|
140
|
+
"<#{args[:arg]}>]"
|
141
|
+
else
|
142
|
+
usage << "[#{args[:long_form]} <#{args[:arg]}>]"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
usage.join(' ')
|
148
|
+
end
|
149
|
+
|
96
150
|
##
|
97
151
|
# Creates a new subcommand of the current command. Identical in
|
98
152
|
# usage to +Bales::Application.command+, the only significant
|
data/lib/bales/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bales
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan S. Northrup
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A framework for building command-line applications
|
14
14
|
email:
|