easy_app_helper 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -19
- data/lib/easy_app_helper/core/base.rb +6 -0
- data/lib/easy_app_helper/core/config.rb +4 -4
- data/lib/easy_app_helper/core/logger.rb +3 -1
- data/lib/easy_app_helper/version.rb +1 -1
- data/test/test_app.rb +2 -2
- 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: e9ce79a31fbe4f16b495bd2294ede7ba73491d2d
|
4
|
+
data.tar.gz: d1acf48488b95bed0a1d738de3ff883bda3b727b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 640e370407ffa4f3e777be1891655c25ba56de8a365c693e1fa7c59839fa14146b986099b20bab3968c116a323b57e0a8dab572d9dccc2e1826fd7732c942160
|
7
|
+
data.tar.gz: a9e0e012fb026e52c1715048f64612fa786db77f9ffcb3eb6909759ec38e6466c5c3c8a66ac3b95b3f982fb71fbc61dfb5c9146aa7369ff2daec9a748d80464b
|
data/README.md
CHANGED
@@ -3,29 +3,30 @@
|
|
3
3
|
**This [gem][EAP] aims at providing useful helpers for command line applications.**
|
4
4
|
|
5
5
|
This is a complete rewrite of the initial easy_app_helper gem. **It is not compatible with
|
6
|
-
apps designed for easy_app_helper prior to version 1.0.0**, although they could be very easily adapted
|
7
|
-
|
8
|
-
(http://docs.rubygems.org/read/chapter/16#page74), don't you ? Older applications should
|
9
|
-
to use the latest version of the 0.x.x series instead.
|
6
|
+
apps designed for easy_app_helper prior to version 1.0.0**, although they could be very easily adapted
|
7
|
+
(anyway you always specify your gem dependencies using the [pessimistic version operator]
|
8
|
+
(http://docs.rubygems.org/read/chapter/16#page74), don't you ?). Older applications should explicitly
|
9
|
+
require to use the latest version of the 0.x.x series instead. The config files themselves remain
|
10
|
+
compatible with all versions of **EasyAppHelper**, as they are actually just plain Yaml files...
|
10
11
|
|
11
|
-
The new **EasyAppHelper** module
|
12
|
+
The new **EasyAppHelper** module provides:
|
12
13
|
|
13
|
-
* A **super charged
|
14
|
+
* A **super charged Config class** that:
|
14
15
|
* Manages **multiple sources of configuration**(command line, multiple config files...) in a **layered config**.
|
15
|
-
* Provides an **easy to customize merge mechanism** for the different **config layers** that
|
16
|
+
* Provides an **easy to customize merge mechanism** for the different **config layers** that renders a "live view"
|
16
17
|
of the merged configuration, while keeping a way to access or modify independently any of them.
|
17
18
|
* Allows **flexibility** when dealing with modification and provides a way to roll back modifications done to config
|
18
19
|
anytime, fully reload it, blast it... Export feature could be very easily added and will probably.
|
19
|
-
* A **Logger tightly coupled with the Config** class, that will behave
|
20
|
-
command line or from any source of the config object...
|
21
|
-
* Embeds [Slop][slop] to handle **command line parameters** and keeps
|
22
|
-
the
|
20
|
+
* A **Logger tightly coupled with the Config** class, that will behave regarding options specified be it from
|
21
|
+
command line or from any source(layer) of the config object...
|
22
|
+
* Embeds [Slop][slop] to handle **command line parameters** and keeps all parameters specified from the command
|
23
|
+
line in a **dedicated layer of the config object**.
|
23
24
|
* A mechanism that ensures that as soon as you access any of the objects or methods exposed by EasyAppHelper,
|
24
25
|
all of them are **fully configured and ready to be used**.
|
25
26
|
|
26
|
-
If you are writing command line applications, I hope you will like because it's very easy to use,
|
27
|
-
possible (you choose when you want to include or use as a module) while providing
|
28
|
-
and command line management.
|
27
|
+
If you are writing command line applications, I hope you will like it because it's very easy to use,
|
28
|
+
and as unobtrusive as possible (you choose when you want to include or use as a module) while providing
|
29
|
+
a ready-for-prod config, logger and command line management.
|
29
30
|
|
30
31
|
|
31
32
|
Currently the only runtime dependency is the cool [Slop gem][slop] which is used to process the command line options.
|
@@ -157,7 +158,7 @@ EasyAppHelper.logger.puts_and_logs "Hi world... 3 is enough."
|
|
157
158
|
**EasyAppHelper** will look for files in numerous places. **Both Unix and Windows places are handled**.
|
158
159
|
All the files are [Yaml][yaml] files but could have names with different extensions.
|
159
160
|
|
160
|
-
You can look in the classes documentation to know exactly which extensions and places the config
|
161
|
+
You can look in the [classes documentation][doc] to know exactly which extensions and places the config
|
161
162
|
files are looked for.
|
162
163
|
|
163
164
|
### System config file
|
@@ -179,9 +180,9 @@ regarding the rules described above, the framework will for the following files
|
|
179
180
|
|
180
181
|
### Application config files
|
181
182
|
|
182
|
-
|
183
|
-
the bare name of the script, but you can replace with whatever you want. Changing
|
184
|
-
the impacted files to be reloaded.
|
183
|
+
Application config file names are determined from the config.script_filename property. It initially contains
|
184
|
+
the bare name of the script(path and extension removed), but you can replace with whatever you want. Changing
|
185
|
+
this property causes actually the impacted files to be reloaded.
|
185
186
|
|
186
187
|
It is in fact a two level configuration. One is global (the :global layer) and the other is at user level (the
|
187
188
|
:user layer).
|
@@ -339,6 +340,25 @@ I, [2013-06-23T19:39:05.712834 #11768] INFO -- My super application: Starting s
|
|
339
340
|
|
340
341
|
So far so good...
|
341
342
|
|
343
|
+
### Specifying command line parameters
|
344
|
+
|
345
|
+
As said, internally **EasyAppHelper** uses the [Slop gem][slop] to handle the command line parameters.
|
346
|
+
You can configure the internal Slop object by calling the add_command_line_section method of the config
|
347
|
+
object. You could create a method that setup your application command line parameters like this:
|
348
|
+
|
349
|
+
```ruby
|
350
|
+
def add_cmd_line_options
|
351
|
+
config.add_command_line_section do |slop|
|
352
|
+
slop.on :u, :useless, 'Stupid option', :argument => false
|
353
|
+
slop.on :anint, 'Stupid option with integer argument', :argument => true, :as => Integer
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
```
|
358
|
+
|
359
|
+
See [Slop gem][slop] API documentation for more options.
|
360
|
+
|
361
|
+
|
342
362
|
### Debugging the framework itself
|
343
363
|
|
344
364
|
If you want, you can even debug what happens during **EasyAppHelper** initialisation, for this you can use the
|
@@ -475,5 +495,5 @@ That's all folks.
|
|
475
495
|
[EAP]: https://rubygems.org/gems/easy_app_helper "**EasyAppHelper** gem"
|
476
496
|
[slop]: https://rubygems.org/gems/slop "Slop gem"
|
477
497
|
[yaml]: http://www.yaml.org/ "The Yaml official site"
|
478
|
-
[
|
498
|
+
[doc]: http://rubydoc.info/github/lbriais/easy_app_helper/master "**EasyAppHelper** documentation"
|
479
499
|
[4]: https://github.com/lbriais/easy_app_helper/wiki "**EasyAppHelper** wiki"
|
@@ -56,6 +56,12 @@ class EasyAppHelper::Core::Base
|
|
56
56
|
@slop_definition.banner = build_banner
|
57
57
|
end
|
58
58
|
|
59
|
+
# helper to add in one command any of the four base properties used
|
60
|
+
# by the logger and the config objects.
|
61
|
+
# @param [String] app_name
|
62
|
+
# @param [String] script_filename
|
63
|
+
# @param [String] app_version
|
64
|
+
# @param [String] app_description
|
59
65
|
def describes_application(app_name: nil, script_filename: nil, app_version: nil, app_description: nil)
|
60
66
|
self.app_name = app_name unless app_name.nil?
|
61
67
|
self.app_version = app_version unless app_version.nil?
|
@@ -17,8 +17,8 @@ require 'yaml'
|
|
17
17
|
# complex rules. First the place where to search them depends on the OS
|
18
18
|
# (Provided by {EasyAppHelper::Core::Config::Places}), and then multiple file extensions are
|
19
19
|
# tested ({EasyAppHelper::Core::Config::CONFIG_FILE_POSSIBLE_EXTENSIONS}). This is basically
|
20
|
-
# performed by the private method {#find_file}. The config specified on command (if any)
|
21
|
-
# same way.
|
20
|
+
# performed by the private method {#find_file}. The config specified on command line (if any)
|
21
|
+
# is loaded the same way.
|
22
22
|
#
|
23
23
|
# == Command line:
|
24
24
|
# Any option can be declared as being callable from the command line. Modules add already some
|
@@ -26,8 +26,8 @@ require 'yaml'
|
|
26
26
|
# {EasyAppHelper::Core::Base#add_command_line_section}).
|
27
27
|
#
|
28
28
|
# Each of the config sources are kept in a separated "layer" and addressed this way using the
|
29
|
-
# #
|
30
|
-
# result of the computation of all the sources. See the #to_hash method to see the order for the
|
29
|
+
# #internal_configs attribute reader. But of course the config object provides a "merged" config
|
30
|
+
# result of the computation of all the sources. See the {#to_hash} method to see the order for the
|
31
31
|
# merge.
|
32
32
|
# Any option can be accessed or modified directly using the {#[]} and {#[]=} methods.
|
33
33
|
# Any change to the global config should be done using the {#[]=} method and is kept in the last separated
|
@@ -23,7 +23,9 @@ class Logger
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
# This is the logger that will be used by the application and any class that include {
|
26
|
+
# This is the logger that will be used by the application and any class that include {EasyAppHelper} module. It is
|
27
|
+
# configured by the {EasyAppHelper::Core::Config Config} object, and provides a temporary logger until the config
|
28
|
+
# is fully loaded.
|
27
29
|
class EasyAppHelper::Core::Logger < Logger
|
28
30
|
include Singleton
|
29
31
|
|
data/test/test_app.rb
CHANGED
@@ -40,8 +40,8 @@ class TestApp
|
|
40
40
|
|
41
41
|
def add_cmd_line_options
|
42
42
|
config.add_command_line_section do |slop|
|
43
|
-
slop.on :
|
44
|
-
slop.on :
|
43
|
+
slop.on :u, :useless, 'Stupid option', :argument => false
|
44
|
+
slop.on :anint, 'Stupid option with integer argument', :argument => true, :as => Integer
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_app_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- L.Briais
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|