csd 0.0.15 → 0.0.16
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.
- data/.gitignore +1 -0
- data/COPYING +367 -0
- data/Rakefile +10 -10
- data/VERSION +1 -1
- data/bin/ai +19 -0
- data/csd.gemspec +257 -35
- data/lib/active_support.rb +75 -0
- data/lib/active_support/all.rb +3 -0
- data/lib/active_support/backtrace_cleaner.rb +94 -0
- data/lib/active_support/base64.rb +42 -0
- data/lib/active_support/basic_object.rb +21 -0
- data/lib/active_support/benchmarkable.rb +60 -0
- data/lib/active_support/buffered_logger.rb +132 -0
- data/lib/active_support/builder.rb +6 -0
- data/lib/active_support/cache.rb +626 -0
- data/lib/active_support/cache/compressed_mem_cache_store.rb +13 -0
- data/lib/active_support/cache/file_store.rb +188 -0
- data/lib/active_support/cache/mem_cache_store.rb +191 -0
- data/lib/active_support/cache/memory_store.rb +159 -0
- data/lib/active_support/cache/strategy/local_cache.rb +164 -0
- data/lib/active_support/cache/synchronized_memory_store.rb +11 -0
- data/lib/active_support/callbacks.rb +600 -0
- data/lib/active_support/concern.rb +29 -0
- data/lib/active_support/configurable.rb +36 -0
- data/lib/active_support/core_ext.rb +3 -0
- data/lib/active_support/core_ext/array.rb +7 -0
- data/lib/active_support/core_ext/array/access.rb +46 -0
- data/lib/active_support/core_ext/array/conversions.rb +164 -0
- data/lib/active_support/core_ext/array/extract_options.rb +29 -0
- data/lib/active_support/core_ext/array/grouping.rb +100 -0
- data/lib/active_support/core_ext/array/random_access.rb +20 -0
- data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
- data/lib/active_support/core_ext/array/wrap.rb +22 -0
- data/lib/active_support/core_ext/benchmark.rb +7 -0
- data/lib/active_support/core_ext/big_decimal.rb +1 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +27 -0
- data/lib/active_support/core_ext/cgi.rb +1 -0
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +19 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/class/attribute.rb +67 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +63 -0
- data/lib/active_support/core_ext/class/delegating_attributes.rb +44 -0
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +232 -0
- data/lib/active_support/core_ext/class/subclasses.rb +55 -0
- data/lib/active_support/core_ext/date/acts_like.rb +8 -0
- data/lib/active_support/core_ext/date/calculations.rb +240 -0
- data/lib/active_support/core_ext/date/conversions.rb +99 -0
- data/lib/active_support/core_ext/date/freeze.rb +31 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +13 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +113 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +102 -0
- data/lib/active_support/core_ext/date_time/zones.rb +17 -0
- data/lib/active_support/core_ext/enumerable.rb +119 -0
- data/lib/active_support/core_ext/exception.rb +3 -0
- data/lib/active_support/core_ext/file.rb +2 -0
- data/lib/active_support/core_ext/file/atomic.rb +41 -0
- data/lib/active_support/core_ext/file/path.rb +5 -0
- data/lib/active_support/core_ext/float.rb +1 -0
- data/lib/active_support/core_ext/float/rounding.rb +19 -0
- data/lib/active_support/core_ext/hash.rb +8 -0
- data/lib/active_support/core_ext/hash/conversions.rb +150 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +16 -0
- data/lib/active_support/core_ext/hash/diff.rb +13 -0
- data/lib/active_support/core_ext/hash/except.rb +24 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +14 -0
- data/lib/active_support/core_ext/hash/keys.rb +45 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +28 -0
- data/lib/active_support/core_ext/hash/slice.rb +38 -0
- data/lib/active_support/core_ext/integer.rb +3 -0
- data/lib/active_support/core_ext/integer/inflections.rb +14 -0
- data/lib/active_support/core_ext/integer/multiple.rb +6 -0
- data/lib/active_support/core_ext/integer/time.rb +39 -0
- data/lib/active_support/core_ext/kernel.rb +5 -0
- data/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
- data/lib/active_support/core_ext/kernel/debugger.rb +16 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +62 -0
- data/lib/active_support/core_ext/kernel/requires.rb +26 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
- data/lib/active_support/core_ext/load_error.rb +23 -0
- data/lib/active_support/core_ext/logger.rb +146 -0
- data/lib/active_support/core_ext/module.rb +12 -0
- data/lib/active_support/core_ext/module/aliasing.rb +70 -0
- data/lib/active_support/core_ext/module/anonymous.rb +24 -0
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +32 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +66 -0
- data/lib/active_support/core_ext/module/delegation.rb +146 -0
- data/lib/active_support/core_ext/module/deprecation.rb +9 -0
- data/lib/active_support/core_ext/module/introspection.rb +88 -0
- data/lib/active_support/core_ext/module/method_names.rb +14 -0
- data/lib/active_support/core_ext/module/reachable.rb +10 -0
- data/lib/active_support/core_ext/module/remove_method.rb +6 -0
- data/lib/active_support/core_ext/module/synchronization.rb +42 -0
- data/lib/active_support/core_ext/name_error.rb +18 -0
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +44 -0
- data/lib/active_support/core_ext/numeric/time.rb +77 -0
- data/lib/active_support/core_ext/object.rb +14 -0
- data/lib/active_support/core_ext/object/acts_like.rb +10 -0
- data/lib/active_support/core_ext/object/blank.rb +76 -0
- data/lib/active_support/core_ext/object/conversions.rb +4 -0
- data/lib/active_support/core_ext/object/duplicable.rb +65 -0
- data/lib/active_support/core_ext/object/extending.rb +11 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +67 -0
- data/lib/active_support/core_ext/object/misc.rb +2 -0
- data/lib/active_support/core_ext/object/returning.rb +42 -0
- data/lib/active_support/core_ext/object/to_param.rb +49 -0
- data/lib/active_support/core_ext/object/to_query.rb +27 -0
- data/lib/active_support/core_ext/object/try.rb +36 -0
- data/lib/active_support/core_ext/object/with_options.rb +26 -0
- data/lib/active_support/core_ext/proc.rb +14 -0
- data/lib/active_support/core_ext/process.rb +1 -0
- data/lib/active_support/core_ext/process/daemon.rb +23 -0
- data/lib/active_support/core_ext/range.rb +4 -0
- data/lib/active_support/core_ext/range/blockless_step.rb +29 -0
- data/lib/active_support/core_ext/range/conversions.rb +21 -0
- data/lib/active_support/core_ext/range/include_range.rb +21 -0
- data/lib/active_support/core_ext/range/overlaps.rb +8 -0
- data/lib/active_support/core_ext/regexp.rb +5 -0
- data/lib/active_support/core_ext/rexml.rb +46 -0
- data/lib/active_support/core_ext/string.rb +12 -0
- data/lib/active_support/core_ext/string/access.rb +99 -0
- data/lib/active_support/core_ext/string/behavior.rb +7 -0
- data/lib/active_support/core_ext/string/conversions.rb +61 -0
- data/lib/active_support/core_ext/string/encoding.rb +11 -0
- data/lib/active_support/core_ext/string/exclude.rb +6 -0
- data/lib/active_support/core_ext/string/filters.rb +49 -0
- data/lib/active_support/core_ext/string/inflections.rb +149 -0
- data/lib/active_support/core_ext/string/interpolation.rb +2 -0
- data/lib/active_support/core_ext/string/multibyte.rb +72 -0
- data/lib/active_support/core_ext/string/output_safety.rb +109 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -0
- data/lib/active_support/core_ext/string/xchar.rb +18 -0
- data/lib/active_support/core_ext/time/acts_like.rb +8 -0
- data/lib/active_support/core_ext/time/calculations.rb +282 -0
- data/lib/active_support/core_ext/time/conversions.rb +85 -0
- data/lib/active_support/core_ext/time/marshal.rb +56 -0
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +10 -0
- data/lib/active_support/core_ext/time/zones.rb +78 -0
- data/lib/active_support/core_ext/uri.rb +22 -0
- data/lib/active_support/dependencies.rb +628 -0
- data/lib/active_support/dependencies/autoload.rb +50 -0
- data/lib/active_support/deprecation.rb +18 -0
- data/lib/active_support/deprecation/behaviors.rb +38 -0
- data/lib/active_support/deprecation/method_wrappers.rb +29 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +74 -0
- data/lib/active_support/deprecation/reporting.rb +56 -0
- data/lib/active_support/duration.rb +105 -0
- data/lib/active_support/gzip.rb +25 -0
- data/lib/active_support/hash_with_indifferent_access.rb +145 -0
- data/lib/active_support/i18n.rb +8 -0
- data/lib/active_support/inflections.rb +56 -0
- data/lib/active_support/inflector.rb +7 -0
- data/lib/active_support/inflector/inflections.rb +211 -0
- data/lib/active_support/inflector/methods.rb +141 -0
- data/lib/active_support/inflector/transliterate.rb +97 -0
- data/lib/active_support/json.rb +2 -0
- data/lib/active_support/json/backends/jsongem.rb +43 -0
- data/lib/active_support/json/backends/yajl.rb +40 -0
- data/lib/active_support/json/backends/yaml.rb +90 -0
- data/lib/active_support/json/decoding.rb +51 -0
- data/lib/active_support/json/encoding.rb +254 -0
- data/lib/active_support/json/variable.rb +11 -0
- data/lib/active_support/lazy_load_hooks.rb +27 -0
- data/lib/active_support/locale/en.yml +36 -0
- data/lib/active_support/memoizable.rb +103 -0
- data/lib/active_support/message_encryptor.rb +71 -0
- data/lib/active_support/message_verifier.rb +62 -0
- data/lib/active_support/multibyte.rb +44 -0
- data/lib/active_support/multibyte/chars.rb +480 -0
- data/lib/active_support/multibyte/exceptions.rb +8 -0
- data/lib/active_support/multibyte/unicode.rb +393 -0
- data/lib/active_support/multibyte/utils.rb +60 -0
- data/lib/active_support/notifications.rb +81 -0
- data/lib/active_support/notifications/fanout.rb +93 -0
- data/lib/active_support/notifications/instrumenter.rb +56 -0
- data/lib/active_support/option_merger.rb +25 -0
- data/lib/active_support/ordered_hash.rb +158 -0
- data/lib/active_support/ordered_options.rb +27 -0
- data/lib/active_support/railtie.rb +100 -0
- data/lib/active_support/rescuable.rb +114 -0
- data/lib/active_support/ruby/shim.rb +22 -0
- data/lib/active_support/secure_random.rb +199 -0
- data/lib/active_support/string_inquirer.rb +21 -0
- data/lib/active_support/test_case.rb +42 -0
- data/lib/active_support/testing/assertions.rb +82 -0
- data/lib/active_support/testing/declarative.rb +40 -0
- data/lib/active_support/testing/default.rb +9 -0
- data/lib/active_support/testing/deprecation.rb +55 -0
- data/lib/active_support/testing/isolation.rb +154 -0
- data/lib/active_support/testing/pending.rb +48 -0
- data/lib/active_support/testing/performance.rb +455 -0
- data/lib/active_support/testing/setup_and_teardown.rb +111 -0
- data/lib/active_support/time.rb +34 -0
- data/lib/active_support/time/autoload.rb +5 -0
- data/lib/active_support/time_with_zone.rb +341 -0
- data/lib/active_support/values/time_zone.rb +377 -0
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +10 -0
- data/lib/active_support/whiny_nil.rb +60 -0
- data/lib/active_support/xml_mini.rb +158 -0
- data/lib/active_support/xml_mini/jdom.rb +168 -0
- data/lib/active_support/xml_mini/libxml.rb +80 -0
- data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
- data/lib/active_support/xml_mini/nokogiri.rb +78 -0
- data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
- data/lib/active_support/xml_mini/rexml.rb +129 -0
- data/lib/csd.rb +82 -2
- data/lib/csd/application.rb +2 -0
- data/lib/csd/application/default.rb +51 -0
- data/lib/csd/application/default/base.rb +15 -0
- data/lib/csd/application/minisip.rb +25 -0
- data/lib/csd/application/minisip/about.yml +14 -0
- data/lib/csd/application/minisip/base.rb +161 -0
- data/lib/csd/application/minisip/error.rb +11 -0
- data/lib/csd/application/minisip/options/common.rb +0 -0
- data/lib/csd/application/minisip/options/compile.rb +59 -0
- data/lib/csd/{applications → application}/minisip/unix/base.rb +10 -11
- data/lib/csd/application/opensips/about.yml +2 -0
- data/lib/csd/applications.rb +55 -0
- data/lib/csd/commands.rb +88 -65
- data/lib/csd/error.rb +31 -0
- data/lib/csd/extensions.rb +1 -0
- data/lib/{extensions → csd/extensions}/core/array.rb +2 -2
- data/lib/csd/extensions/core/dir.rb +46 -0
- data/lib/{extensions → csd/extensions}/core/file.rb +2 -2
- data/lib/{extensions → csd/extensions}/core/object.rb +2 -2
- data/lib/csd/extensions/core/option_parser.rb +33 -0
- data/lib/{extensions → csd/extensions}/core/pathname.rb +12 -3
- data/lib/{extensions → csd/extensions}/core/string.rb +2 -2
- data/lib/{extensions → csd/extensions}/gem/platform.rb +6 -2
- data/lib/csd/global_open_struct.rb +18 -0
- data/lib/csd/options.rb +124 -95
- data/lib/csd/path.rb +31 -0
- data/lib/csd/ui.rb +1 -0
- data/lib/csd/ui/cli.rb +7 -0
- data/lib/csd/ui/ui.rb +46 -0
- data/lib/csd/version.rb +9 -0
- data/lib/term/ansicolor.rb +102 -0
- data/lib/term/ansicolor/.keep +0 -0
- data/lib/term/ansicolor/version.rb +10 -0
- data/test/functional/test_applications.rb +86 -0
- data/test/functional/test_commands.rb +42 -29
- data/test/functional/test_options.rb +98 -0
- data/test/helper.rb +14 -0
- data/test/unit/test_dir.rb +38 -0
- data/test/unit/test_pathname.rb +32 -0
- metadata +253 -40
- data/LICENSE +0 -20
- data/bin/csd +0 -8
- data/lib/csd/applications/base.rb +0 -33
- data/lib/csd/applications/minisip/base.rb +0 -125
- data/lib/csd/applications/minisip/init.rb +0 -20
- data/lib/csd/init.rb +0 -69
- data/lib/csd/path_container.rb +0 -15
- data/publish +0 -29
data/lib/csd/error.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module CSD
|
2
|
+
# In this module we will keep all types of errors in a readable hierarchy
|
3
|
+
#
|
4
|
+
module Error
|
5
|
+
|
6
|
+
# All Exceptions raised by CSD must be children of this class.
|
7
|
+
#
|
8
|
+
class CSDError < StandardError
|
9
|
+
def self.status_code(code = nil)
|
10
|
+
return @code unless code
|
11
|
+
@code = code
|
12
|
+
end
|
13
|
+
|
14
|
+
def status_code
|
15
|
+
self.class.status_code
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Errors in this module are related to command-line options
|
20
|
+
#
|
21
|
+
module Argument
|
22
|
+
class NoApplication < CSDError; status_code(11); end
|
23
|
+
class NoAction < CSDError; status_code(12); end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Application
|
27
|
+
class OptionsSyntax < CSDError; status_code(200); end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'extensions', '**', '*.rb')) { |file| require file }
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module CSD
|
4
|
+
module Extensions
|
5
|
+
module Core
|
6
|
+
module Dir
|
7
|
+
|
8
|
+
def directories(path, &block)
|
9
|
+
if block_given?
|
10
|
+
::Pathname.new(path).children_directories { |pathname| yield pathname.basename.to_s }
|
11
|
+
else
|
12
|
+
::Pathname.new(path).children_directories.map { |pathname| pathname.basename.to_s }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns all direct subdirectories of +path+ with their entire path
|
17
|
+
#
|
18
|
+
#def directories(path, &block)
|
19
|
+
# result = []
|
20
|
+
# glob(::File.join(path, '*')).each do |dir|
|
21
|
+
# if (::File.directory?(dir) and dir != '.' and dir != '..')
|
22
|
+
# block_given? ? yield(dir) : result << dir
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# result
|
26
|
+
#end
|
27
|
+
|
28
|
+
#def directories(path, absolute=false, &block)
|
29
|
+
# result = []
|
30
|
+
# entries(path) do |entry|
|
31
|
+
# if (::File.directory?(entry) and entry != '.' and entry != '..')
|
32
|
+
# dir = absolute? ? File.join(path, entry) : entry
|
33
|
+
# block_given? ? yield(dir) : result << dir
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# result
|
37
|
+
#end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Dir #:nodoc:
|
45
|
+
extend CSD::Extensions::Core::Dir
|
46
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'string')
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module CSD
|
5
|
+
module Extensions
|
6
|
+
module Core
|
7
|
+
module OptionParser
|
8
|
+
|
9
|
+
def newline
|
10
|
+
separator ''
|
11
|
+
end
|
12
|
+
|
13
|
+
def headline(text)
|
14
|
+
newline
|
15
|
+
separator(text)
|
16
|
+
end
|
17
|
+
|
18
|
+
def subheadline(text)
|
19
|
+
separator(@summary_indent + text)
|
20
|
+
end
|
21
|
+
|
22
|
+
def list_item(item='', description='', &block)
|
23
|
+
separator(summary_indent + item.ljust(summary_width + 1) + description)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class OptionParser #:nodoc:
|
32
|
+
include CSD::Extensions::Core::OptionParser
|
33
|
+
end
|
@@ -1,10 +1,19 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'string')
|
2
2
|
|
3
|
-
module
|
3
|
+
module CSD
|
4
4
|
module Extensions
|
5
5
|
module Core
|
6
6
|
module Pathname
|
7
|
-
|
7
|
+
|
8
|
+
def children_directories(&block)
|
9
|
+
result = []
|
10
|
+
children.map do |child|
|
11
|
+
next unless child.directory?
|
12
|
+
block_given? ? yield(child) : result << child
|
13
|
+
end
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
8
17
|
def enquote
|
9
18
|
to_s.enquote
|
10
19
|
end
|
@@ -19,5 +28,5 @@ module Csd
|
|
19
28
|
end
|
20
29
|
|
21
30
|
class Pathname #:nodoc:
|
22
|
-
include
|
31
|
+
include CSD::Extensions::Core::Pathname
|
23
32
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'term/ansicolor'
|
2
2
|
|
3
|
-
module
|
3
|
+
module CSD
|
4
4
|
module Extensions
|
5
5
|
module Core
|
6
6
|
module String
|
@@ -16,5 +16,5 @@ end
|
|
16
16
|
|
17
17
|
class String #:nodoc:
|
18
18
|
include Term::ANSIColor
|
19
|
-
include
|
19
|
+
include CSD::Extensions::Core::String
|
20
20
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module CSD
|
2
2
|
module Extensions
|
3
3
|
module Gem
|
4
4
|
module Platform
|
@@ -7,6 +7,10 @@ module Csd
|
|
7
7
|
version_string = version ? ", version #{version}" : ''
|
8
8
|
"#{os} (CPU: #{cpu}#{version_string})"
|
9
9
|
end
|
10
|
+
|
11
|
+
def kernel_version
|
12
|
+
Cmd.run('uname -v', :silent => true).chop if os == 'linux'
|
13
|
+
end
|
10
14
|
|
11
15
|
end
|
12
16
|
end
|
@@ -15,6 +19,6 @@ end
|
|
15
19
|
|
16
20
|
module Gem
|
17
21
|
class Platform #:nodoc:
|
18
|
-
include
|
22
|
+
include CSD::Extensions::Gem::Platform
|
19
23
|
end
|
20
24
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module CSD
|
2
|
+
class GlobalOpenStruct
|
3
|
+
|
4
|
+
def self.method_missing(meth, *args, &block)
|
5
|
+
if meth.to_s.ends_with?('=')
|
6
|
+
class_variable_set("@@#{meth.to_s.chop}".to_sym, *args)
|
7
|
+
else
|
8
|
+
begin
|
9
|
+
class_variable_get("@@#{meth}".to_sym)
|
10
|
+
rescue NameError => e
|
11
|
+
#UI.debug "The option `#{meth}´ was accessed but not available." # FIXME: This line causes a recursion error :)
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/csd/options.rb
CHANGED
@@ -1,120 +1,149 @@
|
|
1
|
+
# Ruby standard library
|
1
2
|
require 'optparse'
|
2
3
|
require 'optparse/time'
|
3
4
|
require 'ostruct'
|
5
|
+
# Vendor
|
6
|
+
require 'active_support/core_ext/string/inflections'
|
7
|
+
require 'active_support/core_ext/string/starts_ends_with'
|
8
|
+
require 'active_support/core_ext/array'
|
9
|
+
# CSD
|
10
|
+
require 'csd/extensions'
|
11
|
+
Dir.glob(File.join(File.dirname(__FILE__), '*.rb')) { |file| require file }
|
4
12
|
|
5
|
-
module
|
6
|
-
class
|
13
|
+
module CSD
|
14
|
+
# A class that handles the command line option parsing and manipulation
|
15
|
+
#
|
16
|
+
class Options < GlobalOpenStruct
|
17
|
+
|
18
|
+
def self.parse!
|
19
|
+
clear
|
20
|
+
parse_literals
|
21
|
+
define_actions_and_scopes
|
22
|
+
parse_options
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.valid_action?
|
26
|
+
public_actions = actions[:public] ? self.actions[:public].map { |pair| pair.keys.first } : []
|
27
|
+
developer_actions = actions[:developer] ? self.actions[:developer].map { |pair| pair.keys.first } : []
|
28
|
+
all_actions = public_actions + developer_actions
|
29
|
+
all_actions.include?(self.action)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.define_actions_and_scopes
|
33
|
+
if Applications.current
|
34
|
+
# Here we overwrite the default supported actions and scopes with the application specific ones
|
35
|
+
self.actions = Applications.current.actions
|
36
|
+
# At this point we know that the first argument is no option, but *some* action (may it be valid or not)
|
37
|
+
self.scopes = Applications.current.scopes(self.action)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.clear
|
42
|
+
# First we define all valid actions and scopes
|
43
|
+
self.actions = []
|
44
|
+
self.scopes = []
|
45
|
+
# Then we define the default literals
|
46
|
+
self.help = false
|
47
|
+
self.application = nil
|
48
|
+
self.action = nil
|
49
|
+
# Now we define the default options
|
50
|
+
self.yes = false
|
51
|
+
self.dry = false
|
52
|
+
self.reveal = false
|
53
|
+
self.verbose = false
|
54
|
+
self.debug = false
|
55
|
+
self.silent = false
|
56
|
+
self.developer = false
|
57
|
+
end
|
7
58
|
|
59
|
+
# Here we check for literals, i.e. "help", ACTION and APPLICATION.
|
8
60
|
#
|
9
|
-
|
61
|
+
def self.parse_literals
|
62
|
+
# First let's see whether we are in help mode, i.e. whether the first argument is `help´.
|
63
|
+
# If so, we would like to remove it from the ARGV list.
|
64
|
+
if ARGV.first == 'help'
|
65
|
+
self.help = true
|
66
|
+
ARGV.shift
|
67
|
+
end
|
68
|
+
# The action and the application name are the other literals we're interested in at this point.
|
69
|
+
# Note: If there is no application specified, there is pretty much nothing we can do for the user.
|
70
|
+
if Applications.current and Applications.current.name == ARGV.first
|
71
|
+
# The application name is the first argument (i.e. there is no action specified at all)
|
72
|
+
# Let's store the application name and remove it from the argument line
|
73
|
+
self.application = ARGV.shift
|
74
|
+
elsif Applications.current and Applications.current.name == ARGV.second
|
75
|
+
# The second argument is the application name. This means that the first argument must be the
|
76
|
+
# action or happens to be some option. In case it's no option, lets take it as desired action.
|
77
|
+
unless ARGV.first.starts_with?('-')
|
78
|
+
self.action = ARGV.shift
|
79
|
+
self.application = ARGV.shift # Removing the application name from the argument list
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Parse all options that the user gave as command parameter. Note that this function strips the options
|
85
|
+
# from ARGV and leaves only literal (non-option) parameters (i.e. actions/applications/scopes; strings without -- and -).
|
10
86
|
#
|
11
|
-
def self.
|
12
|
-
# Default options
|
13
|
-
options = OpenStruct.new
|
14
|
-
options.temp = false
|
15
|
-
options.silent = false
|
16
|
-
options.dry = false
|
17
|
-
options.bootstrap = true
|
18
|
-
options.configure = true
|
19
|
-
options.make = true
|
20
|
-
options.make_install = true
|
21
|
-
options.owner = nil
|
22
|
-
options.apt_get = true
|
23
|
-
options.yes = false
|
24
|
-
|
25
|
-
# Parse the command line options
|
87
|
+
def self.parse_options
|
26
88
|
OptionParser.new do |opts|
|
27
|
-
|
28
|
-
opts.
|
29
|
-
opts.separator "Actions:"
|
30
|
-
opts.separator " install"
|
31
|
-
opts.separator ""
|
32
|
-
opts.separator "Applications:"
|
33
|
-
opts.separator " minisip"
|
34
|
-
opts.separator ""
|
35
|
-
opts.separator "Options:"
|
36
|
-
|
37
|
-
opts.on("-t", "--temp",
|
38
|
-
"Use a subdirectory in the system's temporary directory",
|
39
|
-
"to download files and not the current directory") do |value|
|
40
|
-
options.temp = value
|
41
|
-
end
|
42
|
-
|
43
|
-
opts.on("-d", "--dry","Don't execute any commands, just show them") do |value|
|
44
|
-
options.dry = value
|
45
|
-
end
|
89
|
+
self.banner = Applications.current ? "ADVANCED HELP FOR #{Applications.current.name}" : "Usage: ".bold + "ai [help] [TASK] APPLICATION [OPTIONS]"
|
90
|
+
opts.banner = self.banner.magenta.bold
|
46
91
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
opts.on("-nb", "--no-bootstrap","Don't run any bootstrap commands") do |value|
|
56
|
-
options.bootstrap = value
|
57
|
-
end
|
58
|
-
|
59
|
-
opts.on("-nc", "--no-configure","Don't run any configure commands") do |value|
|
60
|
-
options.configure = value
|
61
|
-
end
|
62
|
-
|
63
|
-
opts.on("-nm", "--no-make","Don't run any make commands") do |value|
|
64
|
-
options.make = value
|
65
|
-
end
|
66
|
-
|
67
|
-
opts.on("-nmi", "--no-make-install","Don't run any make install commands") do |value|
|
68
|
-
options.make_install = value
|
92
|
+
unless Applications.current
|
93
|
+
opts.headline "EXAMPLE COMMANDS".green.bold
|
94
|
+
opts.list_item 'ai', 'Lists all available applications'
|
95
|
+
opts.list_item 'ai minisip', 'Lists available tasks for the application MiniSIP'
|
96
|
+
opts.list_item 'ai minisip --developer', 'Lists advanced AI tasks for the application MiniSIP'
|
97
|
+
opts.list_item 'ai compile minisip', 'Downloads MiniSIP and compiles it'
|
98
|
+
opts.list_item 'ai help compile minisip', 'Shows more details about the different compiling options'
|
69
99
|
end
|
100
|
+
|
101
|
+
# Here we load application-specific options file.
|
102
|
+
# TODO: There must be a better way for this in general than to eval the raw ruby code
|
103
|
+
begin
|
104
|
+
unless Applications.current.options(self.action).size.blank?
|
105
|
+
opts.headline "#{self.action.upcase} #{Applications.current.name.upcase} OPTIONS".green.bold
|
106
|
+
eval Applications.current.options(self.action)
|
107
|
+
else
|
108
|
+
UI.debug "There were no options to be loaded from #{Applications.current}"
|
109
|
+
end
|
110
|
+
rescue SyntaxError => e
|
111
|
+
raise Error::Application::OptionsSyntax, "The individual options of #{Applications.current.inspect} could not be parsed (SyntaxError)."
|
112
|
+
end if Applications.current
|
70
113
|
|
71
|
-
|
72
|
-
|
114
|
+
# And here we load all general options
|
115
|
+
options_prepend = Applications.current ? 'GENERAL ' : nil
|
116
|
+
opts.headline "#{options_prepend}OPTIONS".green.bold
|
117
|
+
opts.on("-y", "--yes", "Answer all questions with `yes´ (batch mode)") do |value|
|
118
|
+
self.yes = value
|
73
119
|
end
|
74
|
-
|
75
|
-
|
76
|
-
options.owner = value
|
120
|
+
opts.on("-p", "--dry","Don't actually execute any commands (preview mode)") do |value|
|
121
|
+
self.dry = value
|
77
122
|
end
|
78
|
-
|
79
|
-
|
80
|
-
"Defines the working directory manually.",
|
81
|
-
"(This will override the --temp option)") do |value|
|
82
|
-
options.path = value
|
123
|
+
opts.on("-r", "--reveal","List all commands that normally would be executed in this operation") do |value|
|
124
|
+
self.reveal = value
|
83
125
|
end
|
84
|
-
|
85
|
-
|
86
|
-
opts.on("-d", "--debug","Show debugging information") do |value|
|
87
|
-
options.quiet = value
|
126
|
+
opts.on("-e", "--verbose","Show more elaborate output") do |value|
|
127
|
+
self.verbose = value
|
88
128
|
end
|
89
|
-
|
90
|
-
|
91
|
-
options.quiet = value
|
129
|
+
opts.on("-d", "--debug","Show more elaborate output and debugging information") do |value|
|
130
|
+
self.debug = value
|
92
131
|
end
|
93
|
-
|
94
132
|
opts.on("-s", "--silent","Don't show any output") do |value|
|
95
|
-
|
133
|
+
self.silent = value
|
96
134
|
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
135
|
+
opts.on_tail("-a", "--developer", "Activating advanced AI functionality (developers only)") do |value|
|
136
|
+
self.developer = value
|
137
|
+
end
|
138
|
+
opts.on_tail("-h", "--help", "Show detailed help (regarding the given ACTION and APPLICATION)") do |value|
|
139
|
+
self.help = value
|
101
140
|
end
|
102
|
-
|
103
141
|
opts.on_tail("-v", "--version", "Show version") do
|
104
|
-
|
142
|
+
print "CSD Gem Version: #{opts.version}".blue
|
105
143
|
exit
|
106
144
|
end
|
107
|
-
|
108
|
-
|
109
|
-
#.parse!
|
110
|
-
|
111
|
-
if options.owner
|
112
|
-
chmod = options.owner.split(':')
|
113
|
-
options.owner = chmod.first
|
114
|
-
options.group = chmod.last
|
115
|
-
end
|
116
|
-
|
117
|
-
options
|
145
|
+
self.helptext = opts.help
|
146
|
+
end.parse!
|
118
147
|
end
|
119
148
|
|
120
149
|
end
|