nub 0.0.48 → 0.0.49
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +322 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 757c7944db42389b17656703cc9c8b6df373f3ec79e7298989253ad52870a752
|
4
|
+
data.tar.gz: 9fbc726b7cc82d44d2df5504ae771de52818ec29ee4ce752ecd1d746da73a41d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee2b451e9be8457b849bc4b39e7fe4b6fdfc8fbab16bc6cf329cec9f7cd9ba046bf4947e7f4c9890a7575fd41f73db74d750f055a9809cc62da4f8bf48a268b6
|
7
|
+
data.tar.gz: acced59dc0cd5d00eab6ae31a0f9deb5e9198b3e7e27062378e5100dae1ab15ca56c90f407655ca98d493bb147ee909afb6fbec94df05e09aa3c778cbcc6cb5b
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 phR0ze
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,322 @@
|
|
1
|
+
# ruby-nub
|
2
|
+
Collection of ruby utils I've used in several of my projects and wanted re-usable
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/phR0ze/ruby-nub.svg)](https://travis-ci.org/phR0ze/ruby-nub)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/nub.svg)](https://badge.fury.io/rb/nub)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/github/phR0ze/ruby-nub/badge.svg?branch=master)](https://coveralls.io/github/phR0ze/ruby-nub?branch=master)
|
7
|
+
[![Dependency Status](https://beta.gemnasium.com/badges/github.com/phR0ze/ruby-nub.svg)](https://beta.gemnasium.com/projects/github.com/phR0ze/ruby-nub)
|
8
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
9
|
+
|
10
|
+
### Table of Contents
|
11
|
+
* [Deploy](#deploy)
|
12
|
+
* [Commander](#commander)
|
13
|
+
* [Commands](#commands)
|
14
|
+
* [Options](#options)
|
15
|
+
* [Help](#help)
|
16
|
+
* [Config](#config)
|
17
|
+
* [Ruby Gem Creation](#ruby-gem-creation)
|
18
|
+
* [Package Layout](#package-layout)
|
19
|
+
* [Build Gem](#build-gem)
|
20
|
+
* [Install Gem](#install-gem)
|
21
|
+
* [Push Gem](#push-gem)
|
22
|
+
* [Integrate with Travis-CI](#integrate-with-travis-ci)
|
23
|
+
* [Install Travis Client](#install-travis-client)
|
24
|
+
* [Deploy Ruby Gem on Tag](#deploy-ruby-gem-on-tag)
|
25
|
+
|
26
|
+
## Deploy <a name="deploy"></a>
|
27
|
+
Run: `bundle install --system`
|
28
|
+
|
29
|
+
## Commander <a name="commander"></a>
|
30
|
+
Commander was created mainly because all available options parsers seemed complicated and overweight
|
31
|
+
and partly because I enjoyed understanding every bit going into it. Commander offers ***git*** like
|
32
|
+
command syntax that is becoming so popular. Personally I like the syntax as it feels cleaner and
|
33
|
+
faster to type.
|
34
|
+
|
35
|
+
There are two kinds of paramaters that commander deals with ***commands*** and ***options***.
|
36
|
+
Commands are specific named parameters that may or may not have options specific to it. Commands
|
37
|
+
have their own help to display their usage and available options.
|
38
|
+
|
39
|
+
### Commands <a name="commands"></a>
|
40
|
+
Commands are defined via configuration as key words that trigger different branches of functionality
|
41
|
+
for the application. Each command may have zero or more options that modify how this behaveior is
|
42
|
+
invoked. Whenever more than one command is used in the command line expression the expression is
|
43
|
+
interpreted as being a ***chained command expression***. Chained command expressions are executed
|
44
|
+
left to right, such that you can execute the ***clean*** command then the ***build*** command or
|
45
|
+
more in a single command line expression. Each command in a chained command expression may have its
|
46
|
+
own specific options (those coming after the command but before the next command) or if options are
|
47
|
+
omitted the required options from the next command will be used. The chained command options syntax
|
48
|
+
allows one to have a cleaner multi-command line expression with reusable options. Options are said
|
49
|
+
to apply in a chained command syntax when they are of the same type in the positional case or same
|
50
|
+
type and name in the named case.
|
51
|
+
|
52
|
+
***Global*** options are options that are added with the ***add_global*** function and will show up
|
53
|
+
set in the commands results using the ***:global*** symbol. Global options are given on the command
|
54
|
+
line before anything else.
|
55
|
+
|
56
|
+
***Shared*** options are options that are added with the command ***add_shared*** function before
|
57
|
+
any commands and are added to all commands.
|
58
|
+
|
59
|
+
***Commander.new*** must be run from the app's executable file for it to pick up the app's filename
|
60
|
+
properly.
|
61
|
+
|
62
|
+
Example ruby configuration:
|
63
|
+
```ruby
|
64
|
+
if __FILE__ == $0
|
65
|
+
examples = "Clean all: sudo ./#{app} clean all\n".colorize(:green)
|
66
|
+
|
67
|
+
# Creates a new instance of commander
|
68
|
+
cmdr = Commander.new(examples:examples)
|
69
|
+
|
70
|
+
# Add global options
|
71
|
+
cmdr.add_global([
|
72
|
+
Option.new('-d|--debug', 'Debug output')
|
73
|
+
])
|
74
|
+
|
75
|
+
# Create two commands with a chainable positional option
|
76
|
+
cmdr.add('clean', 'Clean build', options:[
|
77
|
+
Option.new(nil, 'Clean given components', allowed:['all', 'iso'])
|
78
|
+
])
|
79
|
+
cmdr.add('build', 'Build components', options:[
|
80
|
+
Option.new(nil, 'Build given components')
|
81
|
+
])
|
82
|
+
cmdr.parse!
|
83
|
+
|
84
|
+
debug = cmdr[:global][:debug]
|
85
|
+
clean(cmdr[:clean][:clean0], debug:debug) if cmdr[:clean]
|
86
|
+
build(cmdr[:build][:build0], debug:debug) if cmdr[:build]
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
Example command line expressions:
|
91
|
+
```bash
|
92
|
+
# Chained commands 'clean' and 'build' share the 'all' positional option, thus 'clean' will be
|
93
|
+
# executed first with the 'all' option then 'build' will be executed second with the 'all' option.
|
94
|
+
./app clean build all
|
95
|
+
# Chained commands 'clean' and 'build' with their own specific 'all' positional option which is
|
96
|
+
# exactly equivalent to the previous usage
|
97
|
+
./app clean all build all
|
98
|
+
```
|
99
|
+
|
100
|
+
### Options <a name="options"></a>
|
101
|
+
There are two kinds of options available for use, ***positional*** and ***named***. Positional
|
102
|
+
options are identified by the absence of preceding dash/dashes and interpreted according to the
|
103
|
+
order in which they were found. Positional options are a value being passed into the application.
|
104
|
+
Named options have a name that is prefixed with a dash (short hand) or two dashes (long hand) e.g.
|
105
|
+
***-h*** or ***--help*** and may simply be a flag or pass in a value. Option values require a
|
106
|
+
***type*** so that Commander can interpret how to use them. The supported value types are
|
107
|
+
***Flag, Integer, String, Array***. Values may be checked or not checked via the ***allowed***
|
108
|
+
config param. Positional options default to type String while named options default to type Flag.
|
109
|
+
Positional options are named internally with the command concatted with a an int for order ***e.g.
|
110
|
+
clean0*** zero based. Positional params are always required.
|
111
|
+
|
112
|
+
**Long Hand** form is always required for named options, short hand may or may not be given.
|
113
|
+
|
114
|
+
**Values** are indicated by the hint given e.g. ***-s|--skip=COMPONENTS*** indicates there is an
|
115
|
+
incoming value/values to be expected because of the hint ***COMPONENTS***.
|
116
|
+
|
117
|
+
Example ruby configuration:
|
118
|
+
```ruby
|
119
|
+
# Creates a new instance of commander with app settings as given
|
120
|
+
cmdr = Commander.new('app-name', 'app-version', 'examples')
|
121
|
+
# Create command with a positional argument
|
122
|
+
cmdr.add('clean', 'Clean build', options:[
|
123
|
+
Option.new(nil, 'Clean given components', allowed:['all', 'iso', 'image']),,,,
|
124
|
+
Option.new('-d|--debug', 'Debug mode'),
|
125
|
+
Option.new('-s|--skip=COMPONENT', 'Skip the given components', allowed:['iso', 'image'], type:String)
|
126
|
+
])
|
127
|
+
# Create command with a single positional option with an allowed check for value
|
128
|
+
cmdr.add('build', 'Build components', options:[
|
129
|
+
Option.new(nil, 'Build given components', allowed:['all', 'iso', 'image'])
|
130
|
+
])
|
131
|
+
cmdr.parse!
|
132
|
+
```
|
133
|
+
|
134
|
+
Example command line expressions:
|
135
|
+
```bash
|
136
|
+
# The parameter 'all' coming after the command 'clean' is a positional option with a default type of
|
137
|
+
# String that is checked against the optional 'allowed' values configuration
|
138
|
+
./app clean all
|
139
|
+
# The parameter '-d' coming after the command 'clean' is a named option using short hand form with
|
140
|
+
# an input type defaulted to Flag (i.e. a simple flag)
|
141
|
+
./app clean -d
|
142
|
+
# The parameter '--debug' coming after the command 'clean' is a named option using long hand form with
|
143
|
+
# an input type defaulted to Flag (i.e. a simple flag); exactly equivalent to the former expression
|
144
|
+
./app clean --debug
|
145
|
+
# The parameter '-s' coming after the command 'clean' is a named option using short hand form with
|
146
|
+
# an input value 'iso' of type String
|
147
|
+
./app clean -s iso
|
148
|
+
# The parameter '--skip' coming after the command 'clean' is a named option using long hand form
|
149
|
+
# with an input value 'iso' of type String; exactly equivalent to the former expression
|
150
|
+
./app clean --skip=iso
|
151
|
+
```
|
152
|
+
|
153
|
+
### Help <a name="help"></a>
|
154
|
+
Help for your appliation and commands is automatically supported with the ***-h*** and ***--help***
|
155
|
+
flags and is generated from the app ***name***, ***version***, ***examples***, ***commands***,
|
156
|
+
***descriptions*** and ***options*** given in Commander's configuration. Examples is just a free
|
157
|
+
form string that is displayed before usage so user's have an idea of how to put together the
|
158
|
+
commands and options. Allowed checks are added to the end of option descriptions in parenthesis.
|
159
|
+
Type and required indicators are added after allowed check descriptions.
|
160
|
+
|
161
|
+
Example ruby configuration:
|
162
|
+
```ruby
|
163
|
+
# Creates a new instance of commander with app settings as given
|
164
|
+
app = 'builder'
|
165
|
+
examples = "Full Build: ./#{app} clean build all\n".colorize(:green)
|
166
|
+
examples += "ISO/Image Build: ./#{app} clean build iso,image\n".colorize(:green)
|
167
|
+
cmdr = Commander.new(app, '0.0.1', examples)
|
168
|
+
# Create command with a positional argument
|
169
|
+
cmdr.add('list', 'List components')
|
170
|
+
cmdr.add('clean', 'Clean components', options:[
|
171
|
+
Option.new(nil, 'Clean given components', allowed:['all', 'iso', 'image', 'boot'], type:Array),
|
172
|
+
Option.new('-d|--debug', 'Debug mode'),
|
173
|
+
Option.new('-m|--min=MINIMUM', 'Set the minimum clean', allowed:[1, 2, 3], type:Integer),
|
174
|
+
Option.new('-s|--skip=COMPONENTS', 'Skip the given components', allowed:['iso', 'image'], type:Array)
|
175
|
+
])
|
176
|
+
# Create command with a single positional option with an allowed check for value
|
177
|
+
cmdr.add('build', 'Build components', options:[
|
178
|
+
Option.new(nil, 'Build given components', allowed:['all', 'iso', 'image', 'boot'], type:Array)
|
179
|
+
])
|
180
|
+
cmdr.parse!
|
181
|
+
```
|
182
|
+
|
183
|
+
App help would look like:
|
184
|
+
```bash
|
185
|
+
builder_v0.0.1
|
186
|
+
--------------------------------------------------------------------------------
|
187
|
+
Examples:
|
188
|
+
Full Build: ./builder clean build all
|
189
|
+
Image/ISO Build: ./builder clean build iso,image
|
190
|
+
|
191
|
+
Usage: ./builder [commands] [options]
|
192
|
+
-h|help Print command/options help: Flag
|
193
|
+
COMMANDS:
|
194
|
+
list List components
|
195
|
+
clean Clean components
|
196
|
+
build Build components
|
197
|
+
|
198
|
+
see './builder COMMAND --help' for specific command help
|
199
|
+
```
|
200
|
+
|
201
|
+
Command help for ***./builder list --help*** would look like:
|
202
|
+
```bash
|
203
|
+
builder_v0.0.1
|
204
|
+
--------------------------------------------------------------------------------
|
205
|
+
List components
|
206
|
+
|
207
|
+
Usage: ./builder list [options]
|
208
|
+
-h|--help Print command/options help: Flag
|
209
|
+
```
|
210
|
+
|
211
|
+
Command help for ***./builder clean --help*** would look like:
|
212
|
+
```bash
|
213
|
+
builder_v0.0.1
|
214
|
+
--------------------------------------------------------------------------------
|
215
|
+
Clean components
|
216
|
+
|
217
|
+
Usage: ./builder clean [options]
|
218
|
+
clean0 Clean given components (all,iso,image,boot): Array, Required
|
219
|
+
-h|--help Print command/options help: Flag
|
220
|
+
-d|--debug Debug mode: Flag
|
221
|
+
-m|--min=MINIMUM Set the minimum clean (1,2,3): Integer
|
222
|
+
-s|--skip=COMPONENTS Skip the given components (iso,image): Array
|
223
|
+
```
|
224
|
+
|
225
|
+
Command help for ***./builder build --help*** would look like:
|
226
|
+
```bash
|
227
|
+
builder_v0.0.1
|
228
|
+
--------------------------------------------------------------------------------
|
229
|
+
Build components
|
230
|
+
|
231
|
+
Usage: ./builder build [options]
|
232
|
+
build0 Build given components (all,iso,image,boot): String, Required
|
233
|
+
-h|--help Print command/options help
|
234
|
+
```
|
235
|
+
|
236
|
+
**Required**
|
237
|
+
Options can be required using the ***required:true*** options param
|
238
|
+
|
239
|
+
## Config <a name="config"></a>
|
240
|
+
Config is a simple YAML wrapper with some extra features. Since it implements the ***Singleton***
|
241
|
+
pattern you can easily use it through out your app without carrying around instances everywhere.
|
242
|
+
It creates config files in memory and saves them to the config ***~/.config*** directory when saved
|
243
|
+
unless the given config exists along side the app's path. If the config file already exists it simply reads it.
|
244
|
+
|
245
|
+
Initialize once on entry of your app and leverage throughout:
|
246
|
+
```ruby
|
247
|
+
Config.init("openvpn.yml")
|
248
|
+
```
|
249
|
+
|
250
|
+
## Ruby Gem Creation <a name="ruby-gem-creation"></a>
|
251
|
+
http://guides.rubygems.org/make-your-own-gem/
|
252
|
+
|
253
|
+
This is my first ruby gem and am documenting what I did here
|
254
|
+
|
255
|
+
### Package Layout <a name="package-layout"></a>
|
256
|
+
All the ruby code will be in the sub directory ***lib***
|
257
|
+
|
258
|
+
* ***lib*** is where your gem's actual code should reside
|
259
|
+
* ***nub.gemspec*** is your interface to RubyGems.org all the data provided here is used by the gem
|
260
|
+
repo
|
261
|
+
|
262
|
+
### Build Gem <a name="build-gem"></a>
|
263
|
+
```
|
264
|
+
gem build nub.gemspec
|
265
|
+
```
|
266
|
+
|
267
|
+
### Install Gem <a name="install-gem"></a>
|
268
|
+
```
|
269
|
+
gem install nub-0.0.1.gem
|
270
|
+
```
|
271
|
+
|
272
|
+
### Push Gem <a name="push-gem"></a>
|
273
|
+
Once you've built and tested your gem and are happy with it push it to RubyGems.org
|
274
|
+
|
275
|
+
```bash
|
276
|
+
# Download your user credentials
|
277
|
+
curl -u phR0ze https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
|
278
|
+
# Enter host password for user 'phR0ze':
|
279
|
+
# Revoke read permission from everyone but you
|
280
|
+
chmod og-r ~/.gem/credentials
|
281
|
+
# Push gem
|
282
|
+
gem push nub-0.0.1.gem
|
283
|
+
# List out your gems takes about a min
|
284
|
+
gem list -r nub
|
285
|
+
```
|
286
|
+
|
287
|
+
## Integrate with Travis-CI <a name="integrate-with-travis-ci"></a>
|
288
|
+
Example project https://github.com/Integralist/Sinderella
|
289
|
+
|
290
|
+
### Install Travis Client <a name="install-travis-client"></a>
|
291
|
+
```bash
|
292
|
+
sudo gem install travis --no-user-install
|
293
|
+
```
|
294
|
+
|
295
|
+
### Deploy Ruby Gem on Tag <a name="deploy-ruby-gem-on-tag"></a>
|
296
|
+
Create the file ***.travis.yml***
|
297
|
+
|
298
|
+
* Using ***cache: bundler*** builds the dependencies once and then reuses them in future builds.
|
299
|
+
* Script ***rake*** is actually the default for ***ruby*** but calling it out for clarity to run unit tests
|
300
|
+
* Deploying using the ***rubygems*** provider on tags
|
301
|
+
|
302
|
+
```yaml
|
303
|
+
language: ruby
|
304
|
+
sudo: false
|
305
|
+
cache: bundler
|
306
|
+
rvm:
|
307
|
+
- 2.5.0
|
308
|
+
before_install:
|
309
|
+
- gem update --system
|
310
|
+
script:
|
311
|
+
- rake
|
312
|
+
deploy:
|
313
|
+
provider: rubygems
|
314
|
+
api_key:
|
315
|
+
secure: <encrypted key>
|
316
|
+
gem: nub
|
317
|
+
on:
|
318
|
+
tags: true
|
319
|
+
notifications:
|
320
|
+
email: false
|
321
|
+
```
|
322
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.49
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Crummett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -100,6 +100,8 @@ executables: []
|
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
|
+
- LICENSE
|
104
|
+
- README.md
|
103
105
|
- lib/nub.rb
|
104
106
|
- lib/nub/commander.rb
|
105
107
|
- lib/nub/config.rb
|