bales 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +71 -29
- data/lib/bales/application.rb +5 -0
- data/lib/bales/version.rb +1 -1
- metadata +9 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6ada6a857baba9d741859d2ec38d4992e6b9e4b409dd3bb7d0aacce7a6b129b
|
4
|
+
data.tar.gz: 1cbc31b944a5bd783aa563d36477bc15bcabaa5a44d7d6a7f03a586d7d02fd3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c4b688015b19d0b11a110729ec6b955e6c11e2ca3cf01f2bec922a9aa03203798bd34fe1efb84f599c89e9cc235939d19e812057348b508b6abf1ff230d7b93
|
7
|
+
data.tar.gz: 1c52425d3d50315b2fcf93d78a603bc47df4a2afa083a4646c92edfad7289fb0e7f11e4e6b421035719cae1a2b81267035581404ebfda511241e2145b8b65a84
|
data/README.md
CHANGED
@@ -44,7 +44,7 @@ module SimpleApp
|
|
44
44
|
if victims.none?
|
45
45
|
puts "You have been smacked#{suffix}."
|
46
46
|
else
|
47
|
-
puts "#{
|
47
|
+
victims.each {|v| puts "#{v} has been smacked#{suffix}."}
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -67,7 +67,8 @@ end
|
|
67
67
|
SimpleApp::Application.parse_and_run
|
68
68
|
```
|
69
69
|
|
70
|
-
And like this (assuming the above script lives in
|
70
|
+
And like this (assuming the above script lives in
|
71
|
+
`/usr/local/bin/simple-app`)!
|
71
72
|
|
72
73
|
```
|
73
74
|
$ simple-app
|
@@ -92,54 +93,95 @@ Bruce has been smacked with a fish.
|
|
92
93
|
## So how does it work?
|
93
94
|
|
94
95
|
* Come up with a name for your app, like `MyApp`
|
95
|
-
|
96
|
+
|
97
|
+
* Create an `Application` class under that namespace which inherits
|
98
|
+
from `Bales::Application`
|
99
|
+
|
96
100
|
* Use the DSL (or define classes manually, if that's your thing)
|
97
101
|
|
98
|
-
Basically, a Bales app is just a bunch of classes with some fairy dust
|
102
|
+
Basically, a Bales app is just a bunch of classes with some fairy dust
|
103
|
+
that turns them into runnable commands. Bales will check the
|
104
|
+
namespace that your subclass of `Bales::Application` lives in for a
|
105
|
+
`Command` namespace, then search there for available commands.
|
99
106
|
|
100
107
|
The application has a few available DSL-ish functions for you to play with.
|
101
108
|
|
102
|
-
* `version`: sets your app's version number. If you use semantic
|
103
|
-
|
109
|
+
* `version`: sets your app's version number. If you use semantic
|
110
|
+
versioning, you can query this with the `major_version`,
|
111
|
+
`minor_version`, and `patch_level` class methods.
|
104
112
|
|
105
|
-
|
113
|
+
* `command "foo" { ... }`: defines a subcommand called "foo", which
|
114
|
+
turns into a class called `MyApp::Command::Foo` (if you picked the
|
115
|
+
name `MyApp` above). If you provide a block, said block will be
|
116
|
+
evaluated in the class' context (see below for things you can do in
|
117
|
+
said context).
|
106
118
|
|
107
|
-
*
|
108
|
-
* `:type`: a valid Ruby class, like `String`. For a boolean, you should provide either `TrueClass` or `FalseClass`, which - when set - will set the option in question to `true` or `false` (respectively).
|
109
|
-
* `:short_form`: a short flag, like `'-v'`. You must specify this if you want a short flag.
|
110
|
-
* `:long_form`: a long flag, like `'--verbose'`. This will be created from the option's name if you don't override it here.
|
111
|
-
* `:description`: a quick description of the option, like `"Whether or not to be verbose"`.
|
112
|
-
* `action`: defines what the command should do when it's called. This is provided in the form of a block. Said block should accept two arguments (an array of arguments and a hash of options), though you don't *have* to name them with pipes and stuff if you know that your command won't take any arguments or options.
|
113
|
-
* `description`: sets a long description of what your command does. Should be a string.
|
114
|
-
* `summary`: sets a short description of what your command does. Should be a string. Should also be shorter than `:description`, though this isn't strictly necessary.
|
119
|
+
Meanwhile, commands *also* have some DSL-ish functions to play around with.
|
115
120
|
|
116
|
-
|
121
|
+
* `option`: defines a command-line option, like `--verbose` or `-f` or
|
122
|
+
something. It takes the name of the option (which becomes a key in
|
123
|
+
your command's options hash) and some named parameters:
|
124
|
+
|
125
|
+
* `:type`: a valid Ruby class, like `String`. For a boolean, you
|
126
|
+
should provide either `TrueClass` or `FalseClass`, which - when
|
127
|
+
set - will set the option in question to `true` or `false`
|
128
|
+
(respectively).
|
129
|
+
|
130
|
+
* `:short_form`: a short flag, like `'-v'`. You must specify this
|
131
|
+
if you want a short flag.
|
132
|
+
|
133
|
+
* `:long_form`: a long flag, like `'--verbose'`. This will be
|
134
|
+
created from the option's name if you don't override it here.
|
135
|
+
|
136
|
+
* `:description`: a quick description of the option, like `"Whether
|
137
|
+
or not to be verbose"`.
|
138
|
+
|
139
|
+
* `action`: defines what the command should do when it's called. This
|
140
|
+
is provided in the form of a block. Said block should accept two
|
141
|
+
arguments (an array of arguments and a hash of options), though you
|
142
|
+
don't *have* to name them with pipes and stuff if you know that your
|
143
|
+
command won't take any arguments or options.
|
144
|
+
|
145
|
+
* `description`: sets a long description of what your command does.
|
146
|
+
Should be a string.
|
147
|
+
|
148
|
+
* `summary`: sets a short description of what your command does.
|
149
|
+
Should be a string. Should also be shorter than `:description`,
|
150
|
+
though this isn't strictly necessary.
|
151
|
+
|
152
|
+
Some of the command functions (`option`, `action`, `description`,
|
153
|
+
`summary`) can also be used from within the application class; doing
|
154
|
+
so will define and configure a "root command", which is what is run if
|
155
|
+
you run your app without any arguments.
|
117
156
|
|
118
157
|
## What can this thing already do?
|
119
158
|
|
120
159
|
* Create a working command-line app
|
121
|
-
|
160
|
+
|
161
|
+
* Automatically produce subcommands (recursively, in fact) based on
|
162
|
+
the namespaces of the corresponding `Bales::Command` subclasses
|
163
|
+
|
122
164
|
* Provide a DSL defining commands and options
|
123
165
|
|
124
166
|
## What might this thing someday do in the future?
|
125
167
|
|
126
168
|
* Provide some helpers to wrap things like HighLine, curses, etc.
|
127
|
-
|
169
|
+
|
170
|
+
* Provide some additional flexibility in how options are specified
|
171
|
+
without requiring users to completely reimplement a command's option
|
172
|
+
parsing functions
|
128
173
|
|
129
174
|
## What kind of a silly name is "Bales", anyway?
|
130
175
|
|
131
|
-
It's shamelessly stolen^H^H^H^H^H^Hborrowed from Jason R. Clark's
|
176
|
+
It's shamelessly stolen^H^H^H^H^H^Hborrowed from Jason R. Clark's
|
177
|
+
"Testing the Multiverse" talk at Ruby on Ales 2015 (which, if you
|
178
|
+
haven't watched, you [totally
|
179
|
+
should](http://confreaks.tv/videos/roa2015-testing-the-multiverse)).
|
180
|
+
Sorry, Jason. Hope you don't mind.
|
132
181
|
|
133
|
-
Ironically enough, despite ripping off the name from a talk about Ruby
|
182
|
+
Ironically enough, despite ripping off the name from a talk about Ruby
|
183
|
+
testing, Bales currently lacks any formal test suite. Hm...
|
134
184
|
|
135
185
|
## What's the license?
|
136
186
|
|
137
|
-
MIT License
|
138
|
-
|
139
|
-
Copyright (c) 2015 Ryan S. Northrup
|
140
|
-
|
141
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
142
|
-
|
143
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
144
|
-
|
145
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
187
|
+
MIT License; see COPYING for details.
|
data/lib/bales/application.rb
CHANGED
@@ -157,6 +157,11 @@ module Bales
|
|
157
157
|
# command to run and its arguments/options, then runs the command.
|
158
158
|
def self.parse_and_run(argv=ARGV)
|
159
159
|
command, args, opts = parse argv
|
160
|
+
# OptionParser includes nil values for missing options, so we
|
161
|
+
# need to make sure those don't clobber the command's defaults.
|
162
|
+
command.method(:run).parameters.select {|p| p[0] == :key}.map do |p|
|
163
|
+
opts.delete p[1] if opts[p[1]].nil?
|
164
|
+
end
|
160
165
|
run command, *args, **opts
|
161
166
|
end
|
162
167
|
|
data/lib/bales/version.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bales
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan S. Northrup
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A framework for building command-line applications
|
14
14
|
email:
|
15
|
-
-
|
15
|
+
- northrup@yellowapple.us
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
@@ -27,24 +27,23 @@ homepage: http://github.com/YellowApple/bales
|
|
27
27
|
licenses:
|
28
28
|
- MIT
|
29
29
|
metadata: {}
|
30
|
-
post_install_message:
|
30
|
+
post_install_message:
|
31
31
|
rdoc_options: []
|
32
32
|
require_paths:
|
33
33
|
- lib
|
34
34
|
required_ruby_version: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
44
|
requirements: []
|
45
|
-
|
46
|
-
|
47
|
-
signing_key:
|
45
|
+
rubygems_version: 3.1.2
|
46
|
+
signing_key:
|
48
47
|
specification_version: 4
|
49
48
|
summary: Ruby on Bales
|
50
49
|
test_files: []
|