csd 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. data/COPYING +1 -2
  2. data/README.rdoc +7 -1
  3. data/Rakefile +7 -2
  4. data/VERSION +1 -1
  5. data/csd.gemspec +18 -216
  6. data/lib/csd.rb +6 -16
  7. data/lib/csd/application.rb +2 -2
  8. data/lib/csd/application/default.rb +15 -14
  9. data/lib/csd/application/default/base.rb +1 -1
  10. data/lib/csd/application/minisip.rb +43 -11
  11. data/lib/csd/application/minisip/about.yml +5 -5
  12. data/lib/csd/application/minisip/base.rb +82 -70
  13. data/lib/csd/application/minisip/error.rb +1 -1
  14. data/lib/csd/application/minisip/options/common.rb +1 -1
  15. data/lib/csd/application/minisip/options/compile.rb +1 -1
  16. data/lib/csd/application/minisip/options/package.rb +1 -1
  17. data/lib/csd/application/minisip/unix.rb +40 -27
  18. data/lib/csd/application/minisip/unix/darwin.rb +12 -0
  19. data/lib/csd/application/minisip/unix/linux.rb +1 -11
  20. data/lib/csd/application/minisip/unix/linux/debian.rb +14 -25
  21. data/lib/csd/application/minisip/unix/linux/debian/ubuntu10.rb +12 -13
  22. data/lib/csd/applications.rb +5 -5
  23. data/lib/csd/commands.rb +164 -89
  24. data/lib/csd/container.rb +61 -0
  25. data/lib/csd/error.rb +10 -1
  26. data/lib/csd/extensions.rb +3 -2
  27. data/lib/csd/extensions/core/array.rb +29 -1
  28. data/lib/csd/extensions/core/dir.rb +15 -24
  29. data/lib/csd/extensions/core/object.rb +10 -2
  30. data/lib/csd/extensions/core/option_parser.rb +22 -3
  31. data/lib/csd/extensions/core/pathname.rb +30 -2
  32. data/lib/csd/extensions/core/string.rb +51 -4
  33. data/lib/csd/extensions/gem/platform.rb +18 -3
  34. data/lib/csd/{options.rb → options_parser.rb} +16 -20
  35. data/lib/csd/path_container.rb +24 -0
  36. data/lib/csd/user_interface.rb +2 -0
  37. data/lib/csd/user_interface/base.rb +26 -0
  38. data/lib/csd/user_interface/cli.rb +37 -0
  39. data/lib/csd/vendor/active_support/MIT-LICENSE +20 -0
  40. data/lib/csd/vendor/active_support/inflector.rb +155 -0
  41. data/lib/csd/vendor/term/GPL2-LICENSE +339 -0
  42. data/lib/csd/vendor/term/ansicolor.rb +113 -0
  43. data/lib/csd/version.rb +13 -4
  44. data/test/application/test_minisip.rb +45 -0
  45. data/test/functional/test_applications.rb +10 -16
  46. data/test/functional/test_commands.rb +260 -23
  47. data/test/unit/test_string.rb +1 -1
  48. metadata +18 -216
  49. data/lib/active_support.rb +0 -75
  50. data/lib/active_support/all.rb +0 -3
  51. data/lib/active_support/backtrace_cleaner.rb +0 -94
  52. data/lib/active_support/base64.rb +0 -42
  53. data/lib/active_support/basic_object.rb +0 -21
  54. data/lib/active_support/benchmarkable.rb +0 -60
  55. data/lib/active_support/buffered_logger.rb +0 -132
  56. data/lib/active_support/builder.rb +0 -6
  57. data/lib/active_support/cache.rb +0 -626
  58. data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
  59. data/lib/active_support/cache/file_store.rb +0 -188
  60. data/lib/active_support/cache/mem_cache_store.rb +0 -191
  61. data/lib/active_support/cache/memory_store.rb +0 -159
  62. data/lib/active_support/cache/strategy/local_cache.rb +0 -164
  63. data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
  64. data/lib/active_support/callbacks.rb +0 -600
  65. data/lib/active_support/concern.rb +0 -29
  66. data/lib/active_support/configurable.rb +0 -36
  67. data/lib/active_support/core_ext.rb +0 -3
  68. data/lib/active_support/core_ext/array.rb +0 -7
  69. data/lib/active_support/core_ext/array/access.rb +0 -46
  70. data/lib/active_support/core_ext/array/conversions.rb +0 -164
  71. data/lib/active_support/core_ext/array/extract_options.rb +0 -29
  72. data/lib/active_support/core_ext/array/grouping.rb +0 -100
  73. data/lib/active_support/core_ext/array/random_access.rb +0 -20
  74. data/lib/active_support/core_ext/array/uniq_by.rb +0 -17
  75. data/lib/active_support/core_ext/array/wrap.rb +0 -22
  76. data/lib/active_support/core_ext/benchmark.rb +0 -7
  77. data/lib/active_support/core_ext/big_decimal.rb +0 -1
  78. data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -27
  79. data/lib/active_support/core_ext/cgi.rb +0 -1
  80. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -19
  81. data/lib/active_support/core_ext/class.rb +0 -4
  82. data/lib/active_support/core_ext/class/attribute.rb +0 -67
  83. data/lib/active_support/core_ext/class/attribute_accessors.rb +0 -63
  84. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
  85. data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -232
  86. data/lib/active_support/core_ext/class/subclasses.rb +0 -55
  87. data/lib/active_support/core_ext/date/acts_like.rb +0 -8
  88. data/lib/active_support/core_ext/date/calculations.rb +0 -240
  89. data/lib/active_support/core_ext/date/conversions.rb +0 -99
  90. data/lib/active_support/core_ext/date/freeze.rb +0 -31
  91. data/lib/active_support/core_ext/date_time/acts_like.rb +0 -13
  92. data/lib/active_support/core_ext/date_time/calculations.rb +0 -113
  93. data/lib/active_support/core_ext/date_time/conversions.rb +0 -102
  94. data/lib/active_support/core_ext/date_time/zones.rb +0 -17
  95. data/lib/active_support/core_ext/enumerable.rb +0 -119
  96. data/lib/active_support/core_ext/exception.rb +0 -3
  97. data/lib/active_support/core_ext/file.rb +0 -2
  98. data/lib/active_support/core_ext/file/atomic.rb +0 -41
  99. data/lib/active_support/core_ext/file/path.rb +0 -5
  100. data/lib/active_support/core_ext/float.rb +0 -1
  101. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  102. data/lib/active_support/core_ext/hash.rb +0 -8
  103. data/lib/active_support/core_ext/hash/conversions.rb +0 -150
  104. data/lib/active_support/core_ext/hash/deep_merge.rb +0 -16
  105. data/lib/active_support/core_ext/hash/diff.rb +0 -13
  106. data/lib/active_support/core_ext/hash/except.rb +0 -24
  107. data/lib/active_support/core_ext/hash/indifferent_access.rb +0 -14
  108. data/lib/active_support/core_ext/hash/keys.rb +0 -45
  109. data/lib/active_support/core_ext/hash/reverse_merge.rb +0 -28
  110. data/lib/active_support/core_ext/hash/slice.rb +0 -38
  111. data/lib/active_support/core_ext/integer.rb +0 -3
  112. data/lib/active_support/core_ext/integer/inflections.rb +0 -14
  113. data/lib/active_support/core_ext/integer/multiple.rb +0 -6
  114. data/lib/active_support/core_ext/integer/time.rb +0 -39
  115. data/lib/active_support/core_ext/kernel.rb +0 -5
  116. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  117. data/lib/active_support/core_ext/kernel/debugger.rb +0 -16
  118. data/lib/active_support/core_ext/kernel/reporting.rb +0 -62
  119. data/lib/active_support/core_ext/kernel/requires.rb +0 -26
  120. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
  121. data/lib/active_support/core_ext/load_error.rb +0 -23
  122. data/lib/active_support/core_ext/logger.rb +0 -146
  123. data/lib/active_support/core_ext/module.rb +0 -12
  124. data/lib/active_support/core_ext/module/aliasing.rb +0 -70
  125. data/lib/active_support/core_ext/module/anonymous.rb +0 -24
  126. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
  127. data/lib/active_support/core_ext/module/attr_internal.rb +0 -32
  128. data/lib/active_support/core_ext/module/attribute_accessors.rb +0 -66
  129. data/lib/active_support/core_ext/module/delegation.rb +0 -146
  130. data/lib/active_support/core_ext/module/deprecation.rb +0 -9
  131. data/lib/active_support/core_ext/module/introspection.rb +0 -88
  132. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  133. data/lib/active_support/core_ext/module/reachable.rb +0 -10
  134. data/lib/active_support/core_ext/module/remove_method.rb +0 -6
  135. data/lib/active_support/core_ext/module/synchronization.rb +0 -42
  136. data/lib/active_support/core_ext/name_error.rb +0 -18
  137. data/lib/active_support/core_ext/numeric.rb +0 -2
  138. data/lib/active_support/core_ext/numeric/bytes.rb +0 -44
  139. data/lib/active_support/core_ext/numeric/time.rb +0 -77
  140. data/lib/active_support/core_ext/object.rb +0 -14
  141. data/lib/active_support/core_ext/object/acts_like.rb +0 -10
  142. data/lib/active_support/core_ext/object/blank.rb +0 -76
  143. data/lib/active_support/core_ext/object/conversions.rb +0 -4
  144. data/lib/active_support/core_ext/object/duplicable.rb +0 -65
  145. data/lib/active_support/core_ext/object/extending.rb +0 -11
  146. data/lib/active_support/core_ext/object/instance_variables.rb +0 -67
  147. data/lib/active_support/core_ext/object/misc.rb +0 -2
  148. data/lib/active_support/core_ext/object/returning.rb +0 -42
  149. data/lib/active_support/core_ext/object/to_param.rb +0 -49
  150. data/lib/active_support/core_ext/object/to_query.rb +0 -27
  151. data/lib/active_support/core_ext/object/try.rb +0 -36
  152. data/lib/active_support/core_ext/object/with_options.rb +0 -26
  153. data/lib/active_support/core_ext/proc.rb +0 -14
  154. data/lib/active_support/core_ext/process.rb +0 -1
  155. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  156. data/lib/active_support/core_ext/range.rb +0 -4
  157. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  158. data/lib/active_support/core_ext/range/conversions.rb +0 -21
  159. data/lib/active_support/core_ext/range/include_range.rb +0 -21
  160. data/lib/active_support/core_ext/range/overlaps.rb +0 -8
  161. data/lib/active_support/core_ext/regexp.rb +0 -5
  162. data/lib/active_support/core_ext/rexml.rb +0 -46
  163. data/lib/active_support/core_ext/string.rb +0 -12
  164. data/lib/active_support/core_ext/string/access.rb +0 -99
  165. data/lib/active_support/core_ext/string/behavior.rb +0 -7
  166. data/lib/active_support/core_ext/string/conversions.rb +0 -61
  167. data/lib/active_support/core_ext/string/encoding.rb +0 -11
  168. data/lib/active_support/core_ext/string/exclude.rb +0 -6
  169. data/lib/active_support/core_ext/string/filters.rb +0 -49
  170. data/lib/active_support/core_ext/string/inflections.rb +0 -149
  171. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  172. data/lib/active_support/core_ext/string/multibyte.rb +0 -72
  173. data/lib/active_support/core_ext/string/output_safety.rb +0 -109
  174. data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -4
  175. data/lib/active_support/core_ext/string/xchar.rb +0 -18
  176. data/lib/active_support/core_ext/time/acts_like.rb +0 -8
  177. data/lib/active_support/core_ext/time/calculations.rb +0 -282
  178. data/lib/active_support/core_ext/time/conversions.rb +0 -85
  179. data/lib/active_support/core_ext/time/marshal.rb +0 -56
  180. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
  181. data/lib/active_support/core_ext/time/zones.rb +0 -78
  182. data/lib/active_support/core_ext/uri.rb +0 -22
  183. data/lib/active_support/dependencies.rb +0 -628
  184. data/lib/active_support/dependencies/autoload.rb +0 -50
  185. data/lib/active_support/deprecation.rb +0 -18
  186. data/lib/active_support/deprecation/behaviors.rb +0 -38
  187. data/lib/active_support/deprecation/method_wrappers.rb +0 -29
  188. data/lib/active_support/deprecation/proxy_wrappers.rb +0 -74
  189. data/lib/active_support/deprecation/reporting.rb +0 -56
  190. data/lib/active_support/duration.rb +0 -105
  191. data/lib/active_support/gzip.rb +0 -25
  192. data/lib/active_support/hash_with_indifferent_access.rb +0 -145
  193. data/lib/active_support/i18n.rb +0 -8
  194. data/lib/active_support/inflections.rb +0 -56
  195. data/lib/active_support/inflector.rb +0 -7
  196. data/lib/active_support/inflector/inflections.rb +0 -211
  197. data/lib/active_support/inflector/methods.rb +0 -141
  198. data/lib/active_support/inflector/transliterate.rb +0 -97
  199. data/lib/active_support/json.rb +0 -2
  200. data/lib/active_support/json/backends/jsongem.rb +0 -43
  201. data/lib/active_support/json/backends/yajl.rb +0 -40
  202. data/lib/active_support/json/backends/yaml.rb +0 -90
  203. data/lib/active_support/json/decoding.rb +0 -51
  204. data/lib/active_support/json/encoding.rb +0 -254
  205. data/lib/active_support/json/variable.rb +0 -11
  206. data/lib/active_support/lazy_load_hooks.rb +0 -27
  207. data/lib/active_support/locale/en.yml +0 -36
  208. data/lib/active_support/memoizable.rb +0 -103
  209. data/lib/active_support/message_encryptor.rb +0 -71
  210. data/lib/active_support/message_verifier.rb +0 -62
  211. data/lib/active_support/multibyte.rb +0 -44
  212. data/lib/active_support/multibyte/chars.rb +0 -480
  213. data/lib/active_support/multibyte/exceptions.rb +0 -8
  214. data/lib/active_support/multibyte/unicode.rb +0 -393
  215. data/lib/active_support/multibyte/utils.rb +0 -60
  216. data/lib/active_support/notifications.rb +0 -81
  217. data/lib/active_support/notifications/fanout.rb +0 -93
  218. data/lib/active_support/notifications/instrumenter.rb +0 -56
  219. data/lib/active_support/option_merger.rb +0 -25
  220. data/lib/active_support/ordered_hash.rb +0 -158
  221. data/lib/active_support/ordered_options.rb +0 -27
  222. data/lib/active_support/railtie.rb +0 -100
  223. data/lib/active_support/rescuable.rb +0 -114
  224. data/lib/active_support/ruby/shim.rb +0 -22
  225. data/lib/active_support/secure_random.rb +0 -199
  226. data/lib/active_support/string_inquirer.rb +0 -21
  227. data/lib/active_support/test_case.rb +0 -42
  228. data/lib/active_support/testing/assertions.rb +0 -82
  229. data/lib/active_support/testing/declarative.rb +0 -40
  230. data/lib/active_support/testing/default.rb +0 -9
  231. data/lib/active_support/testing/deprecation.rb +0 -55
  232. data/lib/active_support/testing/isolation.rb +0 -154
  233. data/lib/active_support/testing/pending.rb +0 -48
  234. data/lib/active_support/testing/performance.rb +0 -455
  235. data/lib/active_support/testing/setup_and_teardown.rb +0 -111
  236. data/lib/active_support/time.rb +0 -34
  237. data/lib/active_support/time/autoload.rb +0 -5
  238. data/lib/active_support/time_with_zone.rb +0 -341
  239. data/lib/active_support/values/time_zone.rb +0 -377
  240. data/lib/active_support/values/unicode_tables.dat +0 -0
  241. data/lib/active_support/version.rb +0 -10
  242. data/lib/active_support/whiny_nil.rb +0 -60
  243. data/lib/active_support/xml_mini.rb +0 -158
  244. data/lib/active_support/xml_mini/jdom.rb +0 -168
  245. data/lib/active_support/xml_mini/libxml.rb +0 -80
  246. data/lib/active_support/xml_mini/libxmlsax.rb +0 -85
  247. data/lib/active_support/xml_mini/nokogiri.rb +0 -78
  248. data/lib/active_support/xml_mini/nokogirisax.rb +0 -83
  249. data/lib/active_support/xml_mini/rexml.rb +0 -129
  250. data/lib/csd/extensions/core/file.rb +0 -14
  251. data/lib/csd/global_open_struct.rb +0 -19
  252. data/lib/csd/path.rb +0 -32
  253. data/lib/csd/ui.rb +0 -2
  254. data/lib/csd/ui/cli.rb +0 -8
  255. data/lib/csd/ui/ui.rb +0 -45
  256. data/lib/term/ansicolor.rb +0 -102
  257. data/lib/term/ansicolor/.keep +0 -0
  258. data/lib/term/ansicolor/version.rb +0 -10
@@ -0,0 +1,61 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ module CSD
4
+ class << self
5
+ # This method chooses and holds the user interface instance.
6
+ #
7
+ def ui
8
+ @@ui ||= UserInterface::CLI.new
9
+ end
10
+
11
+ # This method chooses and holds the command execution instance.
12
+ #
13
+ def cmd
14
+ @@cmd ||= Commands.new
15
+ end
16
+
17
+ # This holds the container for paths.
18
+ #
19
+ def path
20
+ @@path ||= PathContainer.new
21
+ end
22
+
23
+ # This holds the container for argument options.
24
+ #
25
+ def options
26
+ @@options ||= OptionsParser.new
27
+ end
28
+ end
29
+
30
+ # A wrapper for the UI class to be able to run all methods as class methods.
31
+ #
32
+ class UI
33
+ def self.method_missing(meth, *args, &block)
34
+ ::CSD.ui.send(meth, *args, &block)
35
+ end
36
+ end
37
+
38
+ # A wrapper for the Commands class to be able to run all methods as class methods.
39
+ #
40
+ class Cmd
41
+ def self.method_missing(meth, *args, &block)
42
+ ::CSD.cmd.send(meth, *args, &block)
43
+ end
44
+ end
45
+
46
+ # A wrapper for the Path class to be able to run all methods as class methods.
47
+ #
48
+ class Path
49
+ def self.method_missing(meth, *args, &block)
50
+ ::CSD.path.send(meth, *args, &block)
51
+ end
52
+ end
53
+
54
+ # A wrapper for the Options class to be able to run all methods as class methods.
55
+ #
56
+ class Options
57
+ def self.method_missing(meth, *args, &block)
58
+ ::CSD.options.send(meth, *args, &block)
59
+ end
60
+ end
61
+ end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # -*- encoding: UTF-8 -*-
2
+
2
3
  module CSD
3
4
  # In this module we will keep all types of errors in a readable hierarchy
4
5
  #
@@ -24,9 +25,17 @@ module CSD
24
25
  class NoAction < CSDError; status_code(12); end
25
26
  end
26
27
 
28
+ # Errors in this module are related to the Application Module Framework
29
+ #
27
30
  module Application
28
31
  class OptionsSyntax < CSDError; status_code(200); end
29
32
  end
33
+
34
+ # Errors in this module are raised by the User Interface
35
+ # TODO: This has to go :)
36
+ module UI
37
+ class Die < CSDError; status_code(1000); end
38
+ end
30
39
 
31
40
  end
32
41
  end
@@ -1,2 +1,3 @@
1
- # encoding: utf-8
2
- Dir.glob(File.join(File.dirname(__FILE__), 'extensions', '**', '*.rb')) { |file| require file }
1
+ # -*- encoding: UTF-8 -*-
2
+ Dir[File.join(File.dirname(__FILE__), 'extensions', 'core', '*.rb')].sort.each { |path| require "csd/extensions/core/#{File.basename(path, '.rb')}" }
3
+ Dir[File.join(File.dirname(__FILE__), 'extensions', 'gem', '*.rb')].sort.each { |path| require "csd/extensions/gem/#{File.basename(path, '.rb')}" }
@@ -1,9 +1,37 @@
1
- # encoding: utf-8
1
+ # -*- encoding: UTF-8 -*-
2
+
2
3
  module CSD
4
+ # This namespace is given to modifications to the ruby language or other gems. Its purpose is to
5
+ # simplify working with simple objects, such as Arrays, Files, etc.
6
+ #
3
7
  module Extensions
8
+ # This namespace is given to all extensions made to the Ruby Core or the Ruby Standard Library.
9
+ #
4
10
  module Core
11
+ # This module comprises extensions to the Array object.
12
+ #
5
13
  module Array
6
14
 
15
+ # Equal to <tt>self[1]</tt>.
16
+ def second
17
+ self[1]
18
+ end
19
+
20
+ # Equal to <tt>self[2]</tt>.
21
+ def third
22
+ self[2]
23
+ end
24
+
25
+ # Equal to <tt>self[3]</tt>.
26
+ def fourth
27
+ self[3]
28
+ end
29
+
30
+ # Equal to <tt>self[4]</tt>.
31
+ def fifth
32
+ self[4]
33
+ end
34
+
7
35
  end
8
36
  end
9
37
  end
@@ -1,11 +1,25 @@
1
- # encoding: utf-8
1
+ # -*- encoding: UTF-8 -*-
2
2
  require 'pathname'
3
3
 
4
4
  module CSD
5
5
  module Extensions
6
6
  module Core
7
+ # This module comprises extensions to the Dir object.
8
+ #
7
9
  module Dir
8
10
 
11
+ # This method returns the names of all children-directories (i.e. first generation of descendants)
12
+ # of a directory in either an +Array+, or in a block. It does the same thing as
13
+ # +Pathname.children_directories+ but returns just the name and not the entire path to the children directories.
14
+ #
15
+ # ==== Examples
16
+ #
17
+ # Dir.directories('/home/user') # => ['Desktop', 'Documents', ...]
18
+ #
19
+ # Dir.directories('/home/user') do |dir|
20
+ # puts dir
21
+ # end
22
+ #
9
23
  def directories(path, &block)
10
24
  if block_given?
11
25
  ::Pathname.new(path).children_directories { |pathname| yield pathname.basename.to_s }
@@ -14,29 +28,6 @@ module CSD
14
28
  end
15
29
  end
16
30
 
17
- # Returns all direct subdirectories of +path+ with their entire path
18
- #
19
- #def directories(path, &block)
20
- # result = []
21
- # glob(::File.join(path, '*')).each do |dir|
22
- # if (::File.directory?(dir) and dir != '.' and dir != '..')
23
- # block_given? ? yield(dir) : result << dir
24
- # end
25
- # end
26
- # result
27
- #end
28
-
29
- #def directories(path, absolute=false, &block)
30
- # result = []
31
- # entries(path) do |entry|
32
- # if (::File.directory?(entry) and entry != '.' and entry != '..')
33
- # dir = absolute? ? File.join(path, entry) : entry
34
- # block_given? ? yield(dir) : result << dir
35
- # end
36
- # end
37
- # result
38
- #end
39
-
40
31
  end
41
32
  end
42
33
  end
@@ -1,10 +1,18 @@
1
- # encoding: utf-8
1
+ # -*- encoding: UTF-8 -*-
2
+
2
3
  module CSD
3
4
  module Extensions
4
5
  module Core
6
+ # This module comprises extensions to Object (the parent of all classes).
7
+ #
5
8
  module Object
6
9
 
7
- # Creates a Pathname object from the current object. Preferrably from Strings and Hashes.
10
+ # Creates a Pathname object from the current object.
11
+ #
12
+ # ==== Examples
13
+ #
14
+ # '/my/path'.pathnamify # => #<Pathname:my/path>
15
+ # my_pathname_object.pathnamify # => #<Pathname:my/path>
8
16
  #
9
17
  def pathnamify
10
18
  case self
@@ -1,26 +1,45 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), 'string')
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'csd/extensions/core/string'
3
3
  require 'optparse'
4
4
 
5
5
  module CSD
6
6
  module Extensions
7
7
  module Core
8
+ # This module comprises extensions to OptionParser objects.
9
+ #
8
10
  module OptionParser
9
11
 
12
+ # Inserts a new line to the options help output.
13
+ #
10
14
  def newline
11
15
  separator ''
12
16
  end
13
17
 
18
+ # Inserts a new line and a headline to the options help output.
19
+ #
14
20
  def headline(text)
15
21
  newline
16
22
  separator(text)
17
23
  end
18
24
 
25
+ # Inserts an indented headline to the options help output.
26
+ #
19
27
  def subheadline(text)
20
28
  separator(@summary_indent + text)
21
29
  end
22
30
 
23
- def list_item(item='', description='', &block)
31
+ # This method creates a line with two columns. The +item+ will be in the first
32
+ # column and be indented. The +description+ will be in the second column.
33
+ #
34
+ # ==== Examples
35
+ #
36
+ # OptionParser.new do |opts|
37
+ # opts.headline 'List of Applications'
38
+ # opts.list_item 'MiniSIP', 'An open-source high-definition video conferencing client.'
39
+ # opts.list_item 'OpenSIP', 'An open-source SIP server.'
40
+ # end
41
+ #
42
+ def list_item(item='', description='')
24
43
  separator(summary_indent + item.ljust(summary_width + 1) + description)
25
44
  end
26
45
 
@@ -1,11 +1,24 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), 'string')
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'csd/extensions/core/string'
3
3
 
4
4
  module CSD
5
5
  module Extensions
6
6
  module Core
7
+ # This module comprises extensions to Pathname objects.
8
+ #
7
9
  module Pathname
8
10
 
11
+ # This method returns the full paths to all children-directories (i.e. first generation of descendants)
12
+ # of a directory in either an +Array+, or in a block.
13
+ #
14
+ # ==== Examples
15
+ #
16
+ # Dir.directories('/home/user') # => ['/home/user/Desktop', '/home/user/Documents', ...]
17
+ #
18
+ # Dir.directories('/home/user') do |dir|
19
+ # puts dir
20
+ # end
21
+ #
9
22
  def children_directories(&block)
10
23
  result = []
11
24
  children.map do |child|
@@ -15,10 +28,25 @@ module CSD
15
28
  result
16
29
  end
17
30
 
31
+ # Converts a Pathname object into a +String+ and wraps it into two quotation
32
+ # marks (according to the +String#enquite+ method). This method is useful for
33
+ # printing a path in a readable way in a command-line user interface.
34
+ #
18
35
  def enquote
19
36
  to_s.enquote
20
37
  end
21
38
 
39
+ # Verifies whether the current directory (i.e. +pwd+) is the path of this Pathname
40
+ # object. Returns +true+ or +false+.
41
+ #
42
+ # ==== Examples
43
+ #
44
+ # Dir.chdir('/home/user')
45
+ # Pathname.new('/home/user').current_path? # => true
46
+ # Pathname.new('/home/user/../user').current_path? # => true
47
+ # Pathname.new('/lib').current_path? # => false
48
+ # Pathname.new('/i/do/not/exist').current_path? # => false
49
+ #
22
50
  def current_path?
23
51
  self.exist? and self.realpath == self.class.getwd.realpath
24
52
  end
@@ -1,21 +1,68 @@
1
- # encoding: utf-8
2
- require 'term/ansicolor'
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'csd/vendor/term/ansicolor'
3
+ require 'csd/vendor/active_support/inflector'
3
4
 
4
5
  module CSD
5
6
  module Extensions
6
7
  module Core
8
+ # This module comprises extensions to String objects.
9
+ #
7
10
  module String
8
-
11
+
12
+ # Adds a double-quote to the beginning and the end of a +String+.
13
+ #
14
+ # ==== Example
15
+ #
16
+ # 'Hello World'.enquote # => '"Hello World"'
17
+ #
9
18
  def enquote
10
19
  %Q{"#{self}"}
11
20
  end
12
21
 
22
+ # See CSD::Vendor::ActiveSupport::Inflector#constantize
23
+ #
24
+ def constantize
25
+ Vendor::ActiveSupport::Inflector.constantize(self)
26
+ end
27
+
28
+ # See CSD::Vendor::ActiveSupport::Inflector#camelize
29
+ #
30
+ def camelize
31
+ Vendor::ActiveSupport::Inflector.camelize(self)
32
+ end
33
+
34
+ # See CSD::Vendor::ActiveSupport::Inflector#demodulize
35
+ #
36
+ def demodulize
37
+ Vendor::ActiveSupport::Inflector.demodulize(self)
38
+ end
39
+
40
+ # See CSD::Vendor::ActiveSupport::Inflector#underscore. Note that there is
41
+ # a name conflict with <tt>String#underscore</tt> provided by CSD::Vendor::Term::ANSIColor,
42
+ # which is why this method is renamed to +underscorize+.
43
+ #
44
+ def underscorize
45
+ Vendor::ActiveSupport::Inflector.underscore(self)
46
+ end
47
+
48
+ # Just an alias to the more logical wording of this method
49
+ #
50
+ def starts_with?(*args) #:nodoc:
51
+ start_with?(*args)
52
+ end
53
+
54
+ # Just an alias to the more logical wording of this method
55
+ #
56
+ def ends_with?(*args) #:nodoc:
57
+ end_with?(*args)
58
+ end
59
+
13
60
  end
14
61
  end
15
62
  end
16
63
  end
17
64
 
18
65
  class String #:nodoc:
19
- include Term::ANSIColor
66
+ include CSD::Vendor::Term::ANSIColor
20
67
  include CSD::Extensions::Core::String
21
68
  end
@@ -1,16 +1,31 @@
1
- # encoding: utf-8
1
+ # -*- encoding: UTF-8 -*-
2
+
2
3
  module CSD
3
4
  module Extensions
5
+ # This namespace is given to all extensions made to third-party Gems.
6
+ #
4
7
  module Gem
8
+ # This module comprises extensions to the Array object.
9
+ #
5
10
  module Platform
6
11
 
12
+ # This method returns a human-readable string for the current OS and CPU architecture.
13
+ #
7
14
  def humanize
8
15
  version_string = version ? ", version #{version}" : ''
9
- "#{os} (CPU: #{cpu}#{version_string})"
16
+ "#{os} (#{cpu}#{version_string})"
10
17
  end
11
18
 
19
+ # On linux systems, this method returns the current kernel version.
20
+ #
12
21
  def kernel_version
13
- Cmd.run('uname -v', :silent => true).chop if os == 'linux'
22
+ Cmd.run('uname --kernel-version', :silent => true).output.chop if os == 'linux'
23
+ end
24
+
25
+ # On linux systems, this method returns the current kernel release.
26
+ #
27
+ def kernel_release
28
+ Cmd.run('uname --kernel-release', :silent => true).output.chop if os == 'linux'
14
29
  end
15
30
 
16
31
  end
@@ -1,45 +1,40 @@
1
- # encoding: utf-8
2
- # Ruby standard library
1
+ # -*- encoding: UTF-8 -*-
3
2
  require 'optparse'
4
3
  require 'optparse/time'
5
4
  require 'ostruct'
6
- # Vendor
7
- require 'active_support/core_ext/string/inflections'
8
- require 'active_support/core_ext/string/starts_ends_with'
9
- require 'active_support/core_ext/array'
10
- # CSD
11
5
  require 'csd/extensions'
12
- Dir.glob(File.join(File.dirname(__FILE__), '*.rb')) { |file| require file }
13
6
 
14
7
  module CSD
15
8
  # A class that handles the command line option parsing and manipulation
16
9
  #
17
- class Options < GlobalOpenStruct
10
+ class OptionsParser < OpenStruct
18
11
 
19
- def self.parse!
12
+ def parse!
20
13
  clear
21
14
  parse_literals
22
15
  define_actions_and_scopes
23
16
  parse_options
24
17
  end
25
18
 
26
- def self.valid_action?
27
- public_actions = actions[:public] ? self.actions[:public].map { |pair| pair.keys.first } : []
28
- developer_actions = actions[:developer] ? self.actions[:developer].map { |pair| pair.keys.first } : []
19
+ def valid_action?
20
+ public_actions = actions['public'] ? self.actions['public'].map { |pair| pair.keys.first } : []
21
+ developer_actions = actions['developer'] ? self.actions['developer'].map { |pair| pair.keys.first } : []
29
22
  all_actions = public_actions + developer_actions
30
23
  all_actions.include?(self.action)
31
24
  end
32
25
 
33
- def self.define_actions_and_scopes
26
+ def define_actions_and_scopes
34
27
  if Applications.current
35
28
  # Here we overwrite the default supported actions and scopes with the application specific ones
29
+ UI.debug "Loading actions of #{Applications.current}."
36
30
  self.actions = Applications.current.actions
37
31
  # At this point we know that the first argument is no option, but *some* action (may it be valid or not)
32
+ UI.debug "Loading scopes of #{Applications.current}."
38
33
  self.scopes = Applications.current.scopes(self.action)
39
34
  end
40
35
  end
41
36
 
42
- def self.clear
37
+ def clear
43
38
  # First we define all valid actions and scopes
44
39
  self.actions = []
45
40
  self.scopes = []
@@ -52,14 +47,15 @@ module CSD
52
47
  self.dry = false
53
48
  self.reveal = false
54
49
  self.verbose = false
55
- self.debug = false
56
50
  self.silent = false
57
51
  self.developer = false
52
+ # Shortcut to allow for debugging the options parser itself
53
+ self.debug = (ARGV.include?('--debug') or ARGV.include?('-d'))
58
54
  end
59
55
 
60
56
  # Here we check for literals, i.e. "help", ACTION and APPLICATION.
61
57
  #
62
- def self.parse_literals
58
+ def parse_literals
63
59
  # First let's see whether we are in help mode, i.e. whether the first argument is `help´.
64
60
  # If so, we would like to remove it from the ARGV list.
65
61
  if ARGV.first == 'help'
@@ -85,7 +81,7 @@ module CSD
85
81
  # Parse all options that the user gave as command parameter. Note that this function strips the options
86
82
  # from ARGV and leaves only literal (non-option) parameters (i.e. actions/applications/scopes; strings without -- and -).
87
83
  #
88
- def self.parse_options
84
+ def parse_options
89
85
  OptionParser.new do |opts|
90
86
  self.banner = Applications.current ? "ADVANCED HELP FOR #{Applications.current.name}" : "Usage: ".bold + "ai [help] [TASK] APPLICATION [OPTIONS]"
91
87
  opts.banner = self.banner.magenta.bold
@@ -102,7 +98,7 @@ module CSD
102
98
  # Here we load application-specific options file.
103
99
  # TODO: There must be a better way for this in general than to eval the raw ruby code
104
100
  begin
105
- unless Applications.current.options(self.action).size.blank?
101
+ unless Applications.current.options(self.action).size == 0
106
102
  opts.headline "#{self.action.to_s.upcase} #{Applications.current.name.upcase} OPTIONS".green.bold
107
103
  eval Applications.current.options(self.action)
108
104
  else
@@ -140,7 +136,7 @@ module CSD
140
136
  self.help = value
141
137
  end
142
138
  opts.on_tail("-v", "--version", "Show version") do
143
- puts "CSD Gem Version: #{CSD::VERSION}".blue
139
+ puts "CSD Gem Version: #{CSD::Version}".blue
144
140
  exit
145
141
  end
146
142
  self.helptext = opts.help