auser-poolparty 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/bin/cloud-compile +6 -1
- data/config/jeweler.rb +1 -3
- data/lib/cloud_providers/cloud_provider_instance.rb +11 -1
- data/lib/dependency_resolvers/chef/resources/chef_recipe.rb +51 -0
- data/lib/dependency_resolvers/chef.rb +12 -3
- data/lib/mixins/callbacks.rb +6 -2
- data/lib/poolparty/plugins/apache2/passenger_site.rb +2 -2
- data/test/fixtures/chef/recipes/sudo/attributes/sudoers.rb +30 -0
- data/test/fixtures/chef/recipes/sudo/recipes/default.rb +33 -0
- data/test/fixtures/chef/recipes/sudo/templates/default/sudoers.erb +22 -0
- data/test/lib/dependency_resolvers/chef/resources/chef_recipe_test.rb +21 -0
- data/test/lib/dependency_resolvers/chef_test.rb +8 -1
- data/vendor/gems/thrift/CHANGELOG +1 -0
- data/vendor/gems/thrift/Makefile.am +25 -6
- data/vendor/gems/thrift/Manifest +81 -0
- data/vendor/gems/thrift/README +17 -111
- data/vendor/gems/thrift/Rakefile +104 -0
- data/vendor/gems/thrift/{lib/hs/Setup.lhs → benchmark/Benchmark.thrift} +5 -4
- data/vendor/gems/thrift/benchmark/benchmark.rb +271 -0
- data/vendor/gems/thrift/benchmark/client.rb +74 -0
- data/vendor/gems/thrift/benchmark/server.rb +82 -0
- data/vendor/gems/thrift/benchmark/thin_server.rb +44 -0
- data/vendor/gems/thrift/ext/binary_protocol_accelerated.c +474 -0
- data/vendor/gems/thrift/{lib/cocoa/src/protocol/TProtocolException.m → ext/binary_protocol_accelerated.h} +1 -4
- data/vendor/gems/thrift/ext/compact_protocol.c +665 -0
- data/vendor/gems/thrift/{lib/cocoa/src/protocol/TProtocolException.h → ext/compact_protocol.h} +1 -6
- data/vendor/gems/thrift/ext/constants.h +95 -0
- data/vendor/gems/thrift/{contrib/fb303/Makefile.am → ext/extconf.rb} +8 -13
- data/vendor/gems/thrift/{compiler/cpp/src/platform.h → ext/macros.h} +18 -13
- data/vendor/gems/thrift/ext/memory_buffer.c +76 -0
- data/vendor/gems/thrift/{lib/csharp/src/Protocol/TMessageType.cs → ext/memory_buffer.h} +2 -13
- data/vendor/gems/thrift/ext/protocol.c +185 -0
- data/vendor/gems/thrift/{lib/csharp/src/TProcessor.cs → ext/protocol.h} +2 -11
- data/vendor/gems/thrift/ext/struct.c +606 -0
- data/vendor/gems/thrift/ext/struct.h +67 -0
- data/vendor/gems/thrift/ext/thrift_native.c +194 -0
- data/vendor/gems/thrift/lib/thrift/client.rb +62 -0
- data/vendor/gems/thrift/{contrib/fb303/py/fb303_scripts/__init__.py → lib/thrift/core_ext/fixnum.rb} +13 -4
- data/vendor/gems/thrift/{contrib/fb303/global_footer.mk → lib/thrift/core_ext.rb} +4 -2
- data/vendor/gems/thrift/lib/thrift/exceptions.rb +82 -0
- data/vendor/gems/thrift/lib/thrift/processor.rb +57 -0
- data/vendor/gems/thrift/lib/thrift/protocol/base_protocol.rb +290 -0
- data/vendor/gems/thrift/lib/thrift/protocol/binary_protocol.rb +225 -0
- data/vendor/gems/thrift/{cleanup.sh → lib/thrift/protocol/binary_protocol_accelerated.rb} +19 -42
- data/vendor/gems/thrift/lib/thrift/protocol/compact_protocol.rb +422 -0
- data/vendor/gems/thrift/lib/thrift/serializer/deserializer.rb +33 -0
- data/vendor/gems/thrift/{bootstrap.sh → lib/thrift/serializer/serializer.rb} +17 -18
- data/vendor/gems/thrift/lib/thrift/server/base_server.rb +31 -0
- data/vendor/gems/thrift/lib/thrift/server/mongrel_http_server.rb +58 -0
- data/vendor/gems/thrift/lib/thrift/server/nonblocking_server.rb +296 -0
- data/vendor/gems/thrift/lib/thrift/server/simple_server.rb +43 -0
- data/vendor/gems/thrift/lib/thrift/server/thread_pool_server.rb +75 -0
- data/vendor/gems/thrift/lib/thrift/server/threaded_server.rb +47 -0
- data/vendor/gems/thrift/lib/thrift/struct.rb +298 -0
- data/vendor/gems/thrift/{contrib/fb303/bootstrap.sh → lib/thrift/thrift_native.rb} +5 -7
- data/vendor/gems/thrift/lib/{erl/Makefile → thrift/transport/base_server_transport.rb} +20 -20
- data/vendor/gems/thrift/lib/thrift/transport/base_transport.rb +70 -0
- data/vendor/gems/thrift/lib/thrift/transport/buffered_transport.rb +77 -0
- data/vendor/gems/thrift/lib/thrift/transport/framed_transport.rb +90 -0
- data/vendor/gems/thrift/lib/thrift/transport/http_client_transport.rb +45 -0
- data/vendor/gems/thrift/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/vendor/gems/thrift/lib/thrift/transport/memory_buffer_transport.rb +96 -0
- data/vendor/gems/thrift/lib/thrift/transport/server_socket.rb +63 -0
- data/vendor/gems/thrift/lib/thrift/transport/socket.rb +136 -0
- data/vendor/gems/thrift/lib/{java/Makefile.am → thrift/transport/unix_server_socket.rb} +39 -17
- data/vendor/gems/thrift/{contrib/fb303/global_header.mk → lib/thrift/transport/unix_socket.rb} +23 -21
- data/vendor/gems/thrift/lib/thrift/types.rb +101 -0
- data/vendor/gems/thrift/lib/thrift.rb +59 -0
- data/vendor/gems/thrift/script/proto_benchmark.rb +121 -0
- data/vendor/gems/thrift/{lib/Makefile.am → script/read_struct.rb} +24 -36
- data/vendor/gems/thrift/{contrib/fb303/py/setup.py → script/write_struct.rb} +8 -5
- data/vendor/gems/thrift/setup.rb +1585 -0
- data/vendor/gems/thrift/spec/ThriftSpec.thrift +84 -0
- data/vendor/gems/thrift/spec/base_protocol_spec.rb +160 -0
- data/vendor/gems/thrift/spec/base_transport_spec.rb +351 -0
- data/vendor/gems/thrift/{contrib/fb303/py/Makefile.am → spec/binary_protocol_accelerated_spec.rb} +22 -25
- data/vendor/gems/thrift/spec/binary_protocol_spec.rb +63 -0
- data/vendor/gems/thrift/spec/binary_protocol_spec_shared.rb +375 -0
- data/vendor/gems/thrift/spec/client_spec.rb +100 -0
- data/vendor/gems/thrift/spec/compact_protocol_spec.rb +117 -0
- data/vendor/gems/thrift/spec/exception_spec.rb +142 -0
- data/vendor/gems/thrift/spec/http_client_spec.rb +49 -0
- data/vendor/gems/thrift/spec/mongrel_http_server_spec.rb +117 -0
- data/vendor/gems/thrift/spec/nonblocking_server_spec.rb +265 -0
- data/vendor/gems/thrift/spec/processor_spec.rb +83 -0
- data/vendor/gems/thrift/spec/serializer_spec.rb +69 -0
- data/vendor/gems/thrift/spec/server_socket_spec.rb +80 -0
- data/vendor/gems/thrift/spec/server_spec.rb +160 -0
- data/vendor/gems/thrift/spec/socket_spec.rb +61 -0
- data/vendor/gems/thrift/spec/socket_spec_shared.rb +104 -0
- data/vendor/gems/thrift/spec/spec_helper.rb +60 -0
- data/vendor/gems/thrift/spec/struct_spec.rb +252 -0
- data/vendor/gems/thrift/spec/types_spec.rb +116 -0
- data/vendor/gems/thrift/spec/unix_socket_spec.rb +108 -0
- data/vendor/gems/trollop/FAQ.txt +84 -0
- data/vendor/gems/trollop/History.txt +101 -0
- data/vendor/gems/trollop/Manifest.txt +7 -0
- data/vendor/gems/trollop/README.txt +40 -0
- data/vendor/gems/trollop/Rakefile +36 -0
- data/vendor/gems/trollop/lib/trollop.rb +739 -0
- data/vendor/gems/trollop/release-script.txt +13 -0
- data/vendor/gems/trollop/test/test_trollop.rb +1048 -0
- data/vendor/gems/trollop/www/index.html +172 -0
- metadata +123 -347
- data/vendor/gems/thrift/CHANGES +0 -35
- data/vendor/gems/thrift/CONTRIBUTORS +0 -77
- data/vendor/gems/thrift/DISCLAIMER +0 -6
- data/vendor/gems/thrift/LICENSE +0 -202
- data/vendor/gems/thrift/NEWS +0 -79
- data/vendor/gems/thrift/NOTICE +0 -26
- data/vendor/gems/thrift/aclocal/ax_boost_base.m4 +0 -198
- data/vendor/gems/thrift/aclocal/ax_javac_and_java.m4 +0 -107
- data/vendor/gems/thrift/aclocal/ax_lib_event.m4 +0 -194
- data/vendor/gems/thrift/aclocal/ax_lib_zlib.m4 +0 -173
- data/vendor/gems/thrift/aclocal/ax_signed_right_shift.m4 +0 -127
- data/vendor/gems/thrift/aclocal/ax_thrift_internal.m4 +0 -39
- data/vendor/gems/thrift/compiler/cpp/Makefile.am +0 -136
- data/vendor/gems/thrift/compiler/cpp/README +0 -39
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_cocoa_generator.cc +0 -2331
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_cpp_generator.cc +0 -3003
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_csharp_generator.cc +0 -1700
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_erl_generator.cc +0 -932
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_generator.cc +0 -173
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_generator.h +0 -321
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_hs_generator.cc +0 -1445
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_html_generator.cc +0 -637
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_java_generator.cc +0 -3069
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_ocaml_generator.cc +0 -1673
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_oop_generator.h +0 -77
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_perl_generator.cc +0 -1812
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_php_generator.cc +0 -2281
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_py_generator.cc +0 -2310
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_rb_generator.cc +0 -1114
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_st_generator.cc +0 -1071
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_xsd_generator.cc +0 -354
- data/vendor/gems/thrift/compiler/cpp/src/globals.h +0 -117
- data/vendor/gems/thrift/compiler/cpp/src/main.cc +0 -1207
- data/vendor/gems/thrift/compiler/cpp/src/main.h +0 -103
- data/vendor/gems/thrift/compiler/cpp/src/md5.c +0 -381
- data/vendor/gems/thrift/compiler/cpp/src/md5.h +0 -91
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_base_type.h +0 -137
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_const.h +0 -59
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_const_value.h +0 -121
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_container.h +0 -56
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_doc.h +0 -51
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_enum.h +0 -59
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_enum_value.h +0 -64
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_field.h +0 -150
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_function.h +0 -93
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_list.h +0 -56
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_map.h +0 -64
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_program.h +0 -223
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_scope.h +0 -86
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_service.h +0 -68
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_set.h +0 -55
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_struct.h +0 -127
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_type.h +0 -176
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_typedef.h +0 -70
- data/vendor/gems/thrift/compiler/cpp/src/thriftl.ll +0 -303
- data/vendor/gems/thrift/compiler/cpp/src/thrifty.yy +0 -1140
- data/vendor/gems/thrift/configure.ac +0 -255
- data/vendor/gems/thrift/contrib/fb303/LICENSE +0 -16
- data/vendor/gems/thrift/contrib/fb303/README +0 -37
- data/vendor/gems/thrift/contrib/fb303/acinclude.m4 +0 -258
- data/vendor/gems/thrift/contrib/fb303/aclocal/ax_boost_base.m4 +0 -198
- data/vendor/gems/thrift/contrib/fb303/configure.ac +0 -115
- data/vendor/gems/thrift/contrib/fb303/cpp/FacebookBase.cpp +0 -124
- data/vendor/gems/thrift/contrib/fb303/cpp/FacebookBase.h +0 -103
- data/vendor/gems/thrift/contrib/fb303/cpp/Makefile.am +0 -84
- data/vendor/gems/thrift/contrib/fb303/cpp/ServiceTracker.cpp +0 -481
- data/vendor/gems/thrift/contrib/fb303/cpp/ServiceTracker.h +0 -215
- data/vendor/gems/thrift/contrib/fb303/if/fb303.thrift +0 -112
- data/vendor/gems/thrift/contrib/fb303/java/FacebookBase.java +0 -103
- data/vendor/gems/thrift/contrib/fb303/java/build.xml +0 -84
- data/vendor/gems/thrift/contrib/fb303/php/FacebookBase.php +0 -89
- data/vendor/gems/thrift/contrib/fb303/py/fb303/FacebookBase.py +0 -82
- data/vendor/gems/thrift/contrib/fb303/py/fb303_scripts/fb303_simple_mgmt.py +0 -195
- data/vendor/gems/thrift/contrib/thrift.el +0 -126
- data/vendor/gems/thrift/contrib/thrift.spec +0 -206
- data/vendor/gems/thrift/contrib/thrift.vim +0 -91
- data/vendor/gems/thrift/contrib/thrift_dump.cpp +0 -91
- data/vendor/gems/thrift/doc/lgpl-2.1.txt +0 -504
- data/vendor/gems/thrift/doc/otp-base-license.txt +0 -20
- data/vendor/gems/thrift/doc/thrift.bnf +0 -96
- data/vendor/gems/thrift/doc/thrift.tex +0 -1057
- data/vendor/gems/thrift/lib/cocoa/README +0 -21
- data/vendor/gems/thrift/lib/cocoa/src/TApplicationException.h +0 -44
- data/vendor/gems/thrift/lib/cocoa/src/TApplicationException.m +0 -130
- data/vendor/gems/thrift/lib/cocoa/src/TException.h +0 -34
- data/vendor/gems/thrift/lib/cocoa/src/TException.m +0 -64
- data/vendor/gems/thrift/lib/cocoa/src/TProcessor.h +0 -29
- data/vendor/gems/thrift/lib/cocoa/src/TProcessorFactory.h +0 -27
- data/vendor/gems/thrift/lib/cocoa/src/TSharedProcessorFactory.h +0 -27
- data/vendor/gems/thrift/lib/cocoa/src/TSharedProcessorFactory.m +0 -51
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TBinaryProtocol.h +0 -51
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TBinaryProtocol.m +0 -477
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocol.h +0 -148
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolFactory.h +0 -29
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolUtil.h +0 -29
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolUtil.m +0 -104
- data/vendor/gems/thrift/lib/cocoa/src/server/TSocketServer.h +0 -50
- data/vendor/gems/thrift/lib/cocoa/src/server/TSocketServer.m +0 -153
- data/vendor/gems/thrift/lib/cocoa/src/transport/THTTPClient.h +0 -42
- data/vendor/gems/thrift/lib/cocoa/src/transport/THTTPClient.m +0 -159
- data/vendor/gems/thrift/lib/cocoa/src/transport/TNSFileHandleTransport.h +0 -35
- data/vendor/gems/thrift/lib/cocoa/src/transport/TNSFileHandleTransport.m +0 -91
- data/vendor/gems/thrift/lib/cocoa/src/transport/TNSStreamTransport.h +0 -38
- data/vendor/gems/thrift/lib/cocoa/src/transport/TNSStreamTransport.m +0 -89
- data/vendor/gems/thrift/lib/cocoa/src/transport/TSocketClient.h +0 -32
- data/vendor/gems/thrift/lib/cocoa/src/transport/TSocketClient.m +0 -58
- data/vendor/gems/thrift/lib/cocoa/src/transport/TTransport.h +0 -36
- data/vendor/gems/thrift/lib/cocoa/src/transport/TTransportException.h +0 -30
- data/vendor/gems/thrift/lib/cocoa/src/transport/TTransportException.m +0 -43
- data/vendor/gems/thrift/lib/cpp/Makefile.am +0 -158
- data/vendor/gems/thrift/lib/cpp/README +0 -67
- data/vendor/gems/thrift/lib/cpp/src/TLogging.h +0 -163
- data/vendor/gems/thrift/lib/cpp/src/TProcessor.h +0 -53
- data/vendor/gems/thrift/lib/cpp/src/TReflectionLocal.h +0 -96
- data/vendor/gems/thrift/lib/cpp/src/Thrift.cpp +0 -148
- data/vendor/gems/thrift/lib/cpp/src/Thrift.h +0 -191
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Exception.h +0 -60
- data/vendor/gems/thrift/lib/cpp/src/concurrency/FunctionRunner.h +0 -77
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Monitor.cpp +0 -137
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Monitor.h +0 -84
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Mutex.cpp +0 -160
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Mutex.h +0 -114
- data/vendor/gems/thrift/lib/cpp/src/concurrency/PosixThreadFactory.cpp +0 -314
- data/vendor/gems/thrift/lib/cpp/src/concurrency/PosixThreadFactory.h +0 -130
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Thread.h +0 -125
- data/vendor/gems/thrift/lib/cpp/src/concurrency/ThreadManager.cpp +0 -493
- data/vendor/gems/thrift/lib/cpp/src/concurrency/ThreadManager.h +0 -169
- data/vendor/gems/thrift/lib/cpp/src/concurrency/TimerManager.cpp +0 -284
- data/vendor/gems/thrift/lib/cpp/src/concurrency/TimerManager.h +0 -122
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Util.cpp +0 -55
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Util.h +0 -100
- data/vendor/gems/thrift/lib/cpp/src/concurrency/test/Tests.cpp +0 -155
- data/vendor/gems/thrift/lib/cpp/src/concurrency/test/ThreadFactoryTests.h +0 -354
- data/vendor/gems/thrift/lib/cpp/src/concurrency/test/ThreadManagerTests.h +0 -379
- data/vendor/gems/thrift/lib/cpp/src/concurrency/test/TimerManagerTests.h +0 -155
- data/vendor/gems/thrift/lib/cpp/src/processor/PeekProcessor.cpp +0 -122
- data/vendor/gems/thrift/lib/cpp/src/processor/PeekProcessor.h +0 -77
- data/vendor/gems/thrift/lib/cpp/src/processor/StatsProcessor.h +0 -264
- data/vendor/gems/thrift/lib/cpp/src/protocol/TBase64Utils.cpp +0 -79
- data/vendor/gems/thrift/lib/cpp/src/protocol/TBase64Utils.h +0 -42
- data/vendor/gems/thrift/lib/cpp/src/protocol/TBinaryProtocol.cpp +0 -394
- data/vendor/gems/thrift/lib/cpp/src/protocol/TBinaryProtocol.h +0 -254
- data/vendor/gems/thrift/lib/cpp/src/protocol/TCompactProtocol.cpp +0 -736
- data/vendor/gems/thrift/lib/cpp/src/protocol/TCompactProtocol.h +0 -279
- data/vendor/gems/thrift/lib/cpp/src/protocol/TDebugProtocol.cpp +0 -346
- data/vendor/gems/thrift/lib/cpp/src/protocol/TDebugProtocol.h +0 -225
- data/vendor/gems/thrift/lib/cpp/src/protocol/TDenseProtocol.cpp +0 -762
- data/vendor/gems/thrift/lib/cpp/src/protocol/TDenseProtocol.h +0 -253
- data/vendor/gems/thrift/lib/cpp/src/protocol/TJSONProtocol.cpp +0 -998
- data/vendor/gems/thrift/lib/cpp/src/protocol/TJSONProtocol.h +0 -340
- data/vendor/gems/thrift/lib/cpp/src/protocol/TOneWayProtocol.h +0 -304
- data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocol.h +0 -438
- data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocolException.h +0 -104
- data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocolTap.h +0 -187
- data/vendor/gems/thrift/lib/cpp/src/server/TNonblockingServer.cpp +0 -750
- data/vendor/gems/thrift/lib/cpp/src/server/TNonblockingServer.h +0 -435
- data/vendor/gems/thrift/lib/cpp/src/server/TServer.cpp +0 -38
- data/vendor/gems/thrift/lib/cpp/src/server/TServer.h +0 -213
- data/vendor/gems/thrift/lib/cpp/src/server/TSimpleServer.cpp +0 -118
- data/vendor/gems/thrift/lib/cpp/src/server/TSimpleServer.h +0 -70
- data/vendor/gems/thrift/lib/cpp/src/server/TThreadPoolServer.cpp +0 -217
- data/vendor/gems/thrift/lib/cpp/src/server/TThreadPoolServer.h +0 -79
- data/vendor/gems/thrift/lib/cpp/src/server/TThreadedServer.cpp +0 -243
- data/vendor/gems/thrift/lib/cpp/src/server/TThreadedServer.h +0 -74
- data/vendor/gems/thrift/lib/cpp/src/transport/TBufferTransports.cpp +0 -370
- data/vendor/gems/thrift/lib/cpp/src/transport/TBufferTransports.h +0 -667
- data/vendor/gems/thrift/lib/cpp/src/transport/TFDTransport.cpp +0 -77
- data/vendor/gems/thrift/lib/cpp/src/transport/TFDTransport.h +0 -73
- data/vendor/gems/thrift/lib/cpp/src/transport/TFileTransport.cpp +0 -953
- data/vendor/gems/thrift/lib/cpp/src/transport/TFileTransport.h +0 -442
- data/vendor/gems/thrift/lib/cpp/src/transport/THttpClient.cpp +0 -348
- data/vendor/gems/thrift/lib/cpp/src/transport/THttpClient.h +0 -111
- data/vendor/gems/thrift/lib/cpp/src/transport/TServerSocket.cpp +0 -368
- data/vendor/gems/thrift/lib/cpp/src/transport/TServerSocket.h +0 -76
- data/vendor/gems/thrift/lib/cpp/src/transport/TServerTransport.h +0 -92
- data/vendor/gems/thrift/lib/cpp/src/transport/TShortReadTransport.h +0 -96
- data/vendor/gems/thrift/lib/cpp/src/transport/TSimpleFileTransport.cpp +0 -54
- data/vendor/gems/thrift/lib/cpp/src/transport/TSimpleFileTransport.h +0 -41
- data/vendor/gems/thrift/lib/cpp/src/transport/TSocket.cpp +0 -591
- data/vendor/gems/thrift/lib/cpp/src/transport/TSocket.h +0 -242
- data/vendor/gems/thrift/lib/cpp/src/transport/TSocketPool.cpp +0 -235
- data/vendor/gems/thrift/lib/cpp/src/transport/TSocketPool.h +0 -191
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransport.h +0 -224
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransportException.cpp +0 -31
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransportException.h +0 -117
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransportUtils.cpp +0 -178
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransportUtils.h +0 -287
- data/vendor/gems/thrift/lib/cpp/src/transport/TZlibTransport.cpp +0 -299
- data/vendor/gems/thrift/lib/cpp/src/transport/TZlibTransport.h +0 -219
- data/vendor/gems/thrift/lib/cpp/thrift-nb.pc.in +0 -30
- data/vendor/gems/thrift/lib/cpp/thrift-z.pc.in +0 -30
- data/vendor/gems/thrift/lib/cpp/thrift.pc.in +0 -29
- data/vendor/gems/thrift/lib/csharp/Makefile.am +0 -70
- data/vendor/gems/thrift/lib/csharp/README +0 -26
- data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/Properties/AssemblyInfo.cs +0 -55
- data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs +0 -242
- data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/ThriftMSBuildTask.csproj +0 -62
- data/vendor/gems/thrift/lib/csharp/src/Collections/THashSet.cs +0 -142
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TBase.cs +0 -34
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TBinaryProtocol.cs +0 -392
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TField.cs +0 -58
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TList.cs +0 -50
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TMap.cs +0 -58
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TMessage.cs +0 -58
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocol.cs +0 -87
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolException.cs +0 -61
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolFactory.cs +0 -29
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolUtil.cs +0 -94
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TSet.cs +0 -50
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TStruct.cs +0 -42
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TType.cs +0 -40
- data/vendor/gems/thrift/lib/csharp/src/Server/TServer.cs +0 -135
- data/vendor/gems/thrift/lib/csharp/src/Server/TSimpleServer.cs +0 -148
- data/vendor/gems/thrift/lib/csharp/src/Server/TThreadPoolServer.cs +0 -186
- data/vendor/gems/thrift/lib/csharp/src/Server/TThreadedServer.cs +0 -234
- data/vendor/gems/thrift/lib/csharp/src/TApplicationException.cs +0 -131
- data/vendor/gems/thrift/lib/csharp/src/Thrift.csproj +0 -73
- data/vendor/gems/thrift/lib/csharp/src/Thrift.sln +0 -35
- data/vendor/gems/thrift/lib/csharp/src/Transport/TBufferedTransport.cs +0 -100
- data/vendor/gems/thrift/lib/csharp/src/Transport/TServerSocket.cs +0 -157
- data/vendor/gems/thrift/lib/csharp/src/Transport/TServerTransport.cs +0 -39
- data/vendor/gems/thrift/lib/csharp/src/Transport/TSocket.cs +0 -144
- data/vendor/gems/thrift/lib/csharp/src/Transport/TStreamTransport.cs +0 -103
- data/vendor/gems/thrift/lib/csharp/src/Transport/TTransport.cs +0 -66
- data/vendor/gems/thrift/lib/csharp/src/Transport/TTransportException.cs +0 -64
- data/vendor/gems/thrift/lib/csharp/src/Transport/TTransportFactory.cs +0 -38
- data/vendor/gems/thrift/lib/erl/README +0 -56
- data/vendor/gems/thrift/lib/erl/build/beamver +0 -59
- data/vendor/gems/thrift/lib/erl/build/buildtargets.mk +0 -15
- data/vendor/gems/thrift/lib/erl/build/colors.mk +0 -24
- data/vendor/gems/thrift/lib/erl/build/docs.mk +0 -12
- data/vendor/gems/thrift/lib/erl/build/mime.types +0 -98
- data/vendor/gems/thrift/lib/erl/build/otp.mk +0 -146
- data/vendor/gems/thrift/lib/erl/build/otp_subdir.mk +0 -85
- data/vendor/gems/thrift/lib/erl/build/raw_test.mk +0 -29
- data/vendor/gems/thrift/lib/erl/include/thrift_constants.hrl +0 -54
- data/vendor/gems/thrift/lib/erl/include/thrift_protocol.hrl +0 -31
- data/vendor/gems/thrift/lib/erl/src/Makefile +0 -116
- data/vendor/gems/thrift/lib/erl/src/test_handler.erl +0 -26
- data/vendor/gems/thrift/lib/erl/src/test_service.erl +0 -29
- data/vendor/gems/thrift/lib/erl/src/thrift.app.src +0 -44
- data/vendor/gems/thrift/lib/erl/src/thrift.appup.src +0 -1
- data/vendor/gems/thrift/lib/erl/src/thrift_base64_transport.erl +0 -64
- data/vendor/gems/thrift/lib/erl/src/thrift_binary_protocol.erl +0 -325
- data/vendor/gems/thrift/lib/erl/src/thrift_buffered_transport.erl +0 -180
- data/vendor/gems/thrift/lib/erl/src/thrift_client.erl +0 -384
- data/vendor/gems/thrift/lib/erl/src/thrift_disk_log_transport.erl +0 -118
- data/vendor/gems/thrift/lib/erl/src/thrift_file_transport.erl +0 -87
- data/vendor/gems/thrift/lib/erl/src/thrift_framed_transport.erl +0 -208
- data/vendor/gems/thrift/lib/erl/src/thrift_http_transport.erl +0 -199
- data/vendor/gems/thrift/lib/erl/src/thrift_memory_buffer.erl +0 -164
- data/vendor/gems/thrift/lib/erl/src/thrift_processor.erl +0 -188
- data/vendor/gems/thrift/lib/erl/src/thrift_protocol.erl +0 -356
- data/vendor/gems/thrift/lib/erl/src/thrift_server.erl +0 -183
- data/vendor/gems/thrift/lib/erl/src/thrift_service.erl +0 -25
- data/vendor/gems/thrift/lib/erl/src/thrift_socket_server.erl +0 -249
- data/vendor/gems/thrift/lib/erl/src/thrift_socket_transport.erl +0 -119
- data/vendor/gems/thrift/lib/erl/src/thrift_transport.erl +0 -57
- data/vendor/gems/thrift/lib/erl/vsn.mk +0 -1
- data/vendor/gems/thrift/lib/hs/README +0 -82
- data/vendor/gems/thrift/lib/hs/TODO +0 -2
- data/vendor/gems/thrift/lib/hs/Thrift.cabal +0 -20
- data/vendor/gems/thrift/lib/hs/src/Thrift/Protocol/Binary.hs +0 -147
- data/vendor/gems/thrift/lib/hs/src/Thrift/Protocol.hs +0 -191
- data/vendor/gems/thrift/lib/hs/src/Thrift/Server.hs +0 -65
- data/vendor/gems/thrift/lib/hs/src/Thrift/Transport/Handle.hs +0 -58
- data/vendor/gems/thrift/lib/hs/src/Thrift/Transport.hs +0 -60
- data/vendor/gems/thrift/lib/hs/src/Thrift.hs +0 -111
- data/vendor/gems/thrift/lib/java/README +0 -43
- data/vendor/gems/thrift/lib/java/build.xml +0 -195
- data/vendor/gems/thrift/lib/java/ivy.xml +0 -8
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/IntRangeSet.java +0 -171
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TApplicationException.java +0 -123
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TBase.java +0 -66
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TBaseHelper.java +0 -102
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TByteArrayOutputStream.java +0 -46
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TDeserializer.java +0 -94
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TException.java +0 -45
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TFieldRequirementType.java +0 -30
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TProcessor.java +0 -32
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TProcessorFactory.java +0 -39
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TSerializer.java +0 -110
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/FieldMetaData.java +0 -69
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/FieldValueMetaData.java +0 -42
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/ListMetaData.java +0 -29
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/MapMetaData.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/SetMetaData.java +0 -29
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/StructMetaData.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TBase64Utils.java +0 -128
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java +0 -331
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TCompactProtocol.java +0 -741
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TField.java +0 -48
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java +0 -927
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TList.java +0 -38
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMap.java +0 -40
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMessage.java +0 -48
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMessageType.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocol.java +0 -146
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolException.java +0 -81
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolFactory.java +0 -30
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolUtil.java +0 -158
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TSet.java +0 -42
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java +0 -384
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TStruct.java +0 -36
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TType.java +0 -40
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/THsHaServer.java +0 -304
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TNonblockingServer.java +0 -772
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TServer.java +0 -126
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TSimpleServer.java +0 -145
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TThreadPoolServer.java +0 -271
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TFramedTransport.java +0 -126
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/THttpClient.java +0 -157
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TIOStreamTransport.java +0 -159
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TMemoryBuffer.java +0 -98
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingServerSocket.java +0 -160
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingServerTransport.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingSocket.java +0 -213
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingTransport.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TServerSocket.java +0 -145
@@ -0,0 +1,739 @@
|
|
1
|
+
## lib/trollop.rb -- trollop command-line processing library
|
2
|
+
## Author:: William Morgan (mailto: wmorgan-trollop@masanjin.net)
|
3
|
+
## Copyright:: Copyright 2007 William Morgan
|
4
|
+
## License:: GNU GPL version 2
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
module Trollop
|
9
|
+
|
10
|
+
VERSION = "1.14"
|
11
|
+
|
12
|
+
## Thrown by Parser in the event of a commandline error. Not needed if
|
13
|
+
## you're using the Trollop::options entry.
|
14
|
+
class CommandlineError < StandardError; end
|
15
|
+
|
16
|
+
## Thrown by Parser if the user passes in '-h' or '--help'. Handled
|
17
|
+
## automatically by Trollop#options.
|
18
|
+
class HelpNeeded < StandardError; end
|
19
|
+
|
20
|
+
## Thrown by Parser if the user passes in '-h' or '--version'. Handled
|
21
|
+
## automatically by Trollop#options.
|
22
|
+
class VersionNeeded < StandardError; end
|
23
|
+
|
24
|
+
## Regex for floating point numbers
|
25
|
+
FLOAT_RE = /^-?((\d+(\.\d+)?)|(\.\d+))$/
|
26
|
+
|
27
|
+
## Regex for parameters
|
28
|
+
PARAM_RE = /^-(-|\.$|[^\d\.])/
|
29
|
+
|
30
|
+
## The commandline parser. In typical usage, the methods in this class
|
31
|
+
## will be handled internally by Trollop::options. In this case, only the
|
32
|
+
## #opt, #banner and #version, #depends, and #conflicts methods will
|
33
|
+
## typically be called.
|
34
|
+
##
|
35
|
+
## If it's necessary to instantiate this class (for more complicated
|
36
|
+
## argument-parsing situations), be sure to call #parse to actually
|
37
|
+
## produce the output hash.
|
38
|
+
class Parser
|
39
|
+
|
40
|
+
## The set of values that indicate a flag option when passed as the
|
41
|
+
## +:type+ parameter of #opt.
|
42
|
+
FLAG_TYPES = [:flag, :bool, :boolean]
|
43
|
+
|
44
|
+
## The set of values that indicate a single-parameter (normal) option when
|
45
|
+
## passed as the +:type+ parameter of #opt.
|
46
|
+
##
|
47
|
+
## A value of +io+ corresponds to a readable IO resource, including
|
48
|
+
## a filename, URI, or the strings 'stdin' or '-'.
|
49
|
+
SINGLE_ARG_TYPES = [:int, :integer, :string, :double, :float, :io, :date]
|
50
|
+
|
51
|
+
## The set of values that indicate a multiple-parameter option (i.e., that
|
52
|
+
## takes multiple space-separated values on the commandline) when passed as
|
53
|
+
## the +:type+ parameter of #opt.
|
54
|
+
MULTI_ARG_TYPES = [:ints, :integers, :strings, :doubles, :floats, :ios, :dates]
|
55
|
+
|
56
|
+
## The complete set of legal values for the +:type+ parameter of #opt.
|
57
|
+
TYPES = FLAG_TYPES + SINGLE_ARG_TYPES + MULTI_ARG_TYPES
|
58
|
+
|
59
|
+
INVALID_SHORT_ARG_REGEX = /[\d-]/ #:nodoc:
|
60
|
+
|
61
|
+
## The values from the commandline that were not interpreted by #parse.
|
62
|
+
attr_reader :leftovers
|
63
|
+
|
64
|
+
## The complete configuration hashes for each option. (Mainly useful
|
65
|
+
## for testing.)
|
66
|
+
attr_reader :specs
|
67
|
+
|
68
|
+
## Initializes the parser, and instance-evaluates any block given.
|
69
|
+
def initialize *a, &b
|
70
|
+
@version = nil
|
71
|
+
@leftovers = []
|
72
|
+
@specs = {}
|
73
|
+
@long = {}
|
74
|
+
@short = {}
|
75
|
+
@order = []
|
76
|
+
@constraints = []
|
77
|
+
@stop_words = []
|
78
|
+
@stop_on_unknown = false
|
79
|
+
|
80
|
+
#instance_eval(&b) if b # can't take arguments
|
81
|
+
cloaker(&b).bind(self).call(*a) if b
|
82
|
+
end
|
83
|
+
|
84
|
+
## Define an option. +name+ is the option name, a unique identifier
|
85
|
+
## for the option that you will use internally, which should be a
|
86
|
+
## symbol or a string. +desc+ is a string description which will be
|
87
|
+
## displayed in help messages.
|
88
|
+
##
|
89
|
+
## Takes the following optional arguments:
|
90
|
+
##
|
91
|
+
## [+:long+] Specify the long form of the argument, i.e. the form with two dashes. If unspecified, will be automatically derived based on the argument name by turning the +name+ option into a string, and replacing any _'s by -'s.
|
92
|
+
## [+:short+] Specify the short form of the argument, i.e. the form with one dash. If unspecified, will be automatically derived from +name+.
|
93
|
+
## [+:type+] Require that the argument take a parameter or parameters of type +type+. For a single parameter, the value can be a member of +SINGLE_ARG_TYPES+, or a corresponding Ruby class (e.g. +Integer+ for +:int+). For multiple-argument parameters, the value can be any member of +MULTI_ARG_TYPES+ constant. If unset, the default argument type is +:flag+, meaning that the argument does not take a parameter. The specification of +:type+ is not necessary if a +:default+ is given.
|
94
|
+
## [+:default+] Set the default value for an argument. Without a default value, the hash returned by #parse (and thus Trollop::options) will have a +nil+ value for this key unless the argument is given on the commandline. The argument type is derived automatically from the class of the default value given, so specifying a +:type+ is not necessary if a +:default+ is given. (But see below for an important caveat when +:multi+: is specified too.) If the argument is a flag, and the default is set to +true+, then if it is specified on the the commandline the value will be +false+.
|
95
|
+
## [+:required+] If set to +true+, the argument must be provided on the commandline.
|
96
|
+
## [+:multi+] If set to +true+, allows multiple occurrences of the option on the commandline. Otherwise, only a single instance of the option is allowed. (Note that this is different from taking multiple parameters. See below.)
|
97
|
+
##
|
98
|
+
## Note that there are two types of argument multiplicity: an argument
|
99
|
+
## can take multiple values, e.g. "--arg 1 2 3". An argument can also
|
100
|
+
## be allowed to occur multiple times, e.g. "--arg 1 --arg 2".
|
101
|
+
##
|
102
|
+
## Arguments that take multiple values should have a +:type+ parameter
|
103
|
+
## drawn from +MULTI_ARG_TYPES+ (e.g. +:strings+), or a +:default:+
|
104
|
+
## value of an array of the correct type (e.g. [String]). The
|
105
|
+
## value of this argument will be an array of the parameters on the
|
106
|
+
## commandline.
|
107
|
+
##
|
108
|
+
## Arguments that can occur multiple times should be marked with
|
109
|
+
## +:multi+ => +true+. The value of this argument will also be an array.
|
110
|
+
## In contrast with regular non-multi options, if not specified on
|
111
|
+
## the commandline, the default value will be [], not nil.
|
112
|
+
##
|
113
|
+
## These two attributes can be combined (e.g. +:type+ => +:strings+,
|
114
|
+
## +:multi+ => +true+), in which case the value of the argument will be
|
115
|
+
## an array of arrays.
|
116
|
+
##
|
117
|
+
## There's one ambiguous case to be aware of: when +:multi+: is true and a
|
118
|
+
## +:default+ is set to an array (of something), it's ambiguous whether this
|
119
|
+
## is a multi-value argument as well as a multi-occurrence argument.
|
120
|
+
## In thise case, Trollop assumes that it's not a multi-value argument.
|
121
|
+
## If you want a multi-value, multi-occurrence argument with a default
|
122
|
+
## value, you must specify +:type+ as well.
|
123
|
+
|
124
|
+
def opt name, desc="", opts={}
|
125
|
+
raise ArgumentError, "you already have an argument named '#{name}'" if @specs.member? name
|
126
|
+
|
127
|
+
## fill in :type
|
128
|
+
opts[:type] = # normalize
|
129
|
+
case opts[:type]
|
130
|
+
when :boolean, :bool; :flag
|
131
|
+
when :integer; :int
|
132
|
+
when :integers; :ints
|
133
|
+
when :double; :float
|
134
|
+
when :doubles; :floats
|
135
|
+
when Class
|
136
|
+
case opts[:type].name
|
137
|
+
when 'TrueClass', 'FalseClass'; :flag
|
138
|
+
when 'String'; :string
|
139
|
+
when 'Integer'; :int
|
140
|
+
when 'Float'; :float
|
141
|
+
when 'IO'; :io
|
142
|
+
when 'Date'; :date
|
143
|
+
else
|
144
|
+
raise ArgumentError, "unsupported argument type '#{opts[:type].class.name}'"
|
145
|
+
end
|
146
|
+
when nil; nil
|
147
|
+
else
|
148
|
+
raise ArgumentError, "unsupported argument type '#{opts[:type]}'" unless TYPES.include?(opts[:type])
|
149
|
+
opts[:type]
|
150
|
+
end
|
151
|
+
|
152
|
+
## for options with :multi => true, an array default doesn't imply
|
153
|
+
## a multi-valued argument. for that you have to specify a :type
|
154
|
+
## as well. (this is how we disambiguate an ambiguous situation;
|
155
|
+
## see the docs for Parser#opt for details.)
|
156
|
+
disambiguated_default =
|
157
|
+
if opts[:multi] && opts[:default].is_a?(Array) && !opts[:type]
|
158
|
+
opts[:default].first
|
159
|
+
else
|
160
|
+
opts[:default]
|
161
|
+
end
|
162
|
+
|
163
|
+
type_from_default =
|
164
|
+
case disambiguated_default
|
165
|
+
when Integer; :int
|
166
|
+
when Numeric; :float
|
167
|
+
when TrueClass, FalseClass; :flag
|
168
|
+
when String; :string
|
169
|
+
when IO; :io
|
170
|
+
when Date; :date
|
171
|
+
when Array
|
172
|
+
if opts[:default].empty?
|
173
|
+
raise ArgumentError, "multiple argument type cannot be deduced from an empty array for '#{opts[:default][0].class.name}'"
|
174
|
+
end
|
175
|
+
case opts[:default][0] # the first element determines the types
|
176
|
+
when Integer; :ints
|
177
|
+
when Numeric; :floats
|
178
|
+
when String; :strings
|
179
|
+
when IO; :ios
|
180
|
+
when Date; :dates
|
181
|
+
else
|
182
|
+
raise ArgumentError, "unsupported multiple argument type '#{opts[:default][0].class.name}'"
|
183
|
+
end
|
184
|
+
when nil; nil
|
185
|
+
else
|
186
|
+
raise ArgumentError, "unsupported argument type '#{opts[:default].class.name}'"
|
187
|
+
end
|
188
|
+
|
189
|
+
raise ArgumentError, ":type specification and default type don't match (default type is #{type_from_default})" if opts[:type] && type_from_default && opts[:type] != type_from_default
|
190
|
+
|
191
|
+
opts[:type] = opts[:type] || type_from_default || :flag
|
192
|
+
|
193
|
+
## fill in :long
|
194
|
+
opts[:long] = opts[:long] ? opts[:long].to_s : name.to_s.gsub("_", "-")
|
195
|
+
opts[:long] =
|
196
|
+
case opts[:long]
|
197
|
+
when /^--([^-].*)$/
|
198
|
+
$1
|
199
|
+
when /^[^-]/
|
200
|
+
opts[:long]
|
201
|
+
else
|
202
|
+
raise ArgumentError, "invalid long option name #{opts[:long].inspect}"
|
203
|
+
end
|
204
|
+
raise ArgumentError, "long option name #{opts[:long].inspect} is already taken; please specify a (different) :long" if @long[opts[:long]]
|
205
|
+
|
206
|
+
## fill in :short
|
207
|
+
opts[:short] = opts[:short].to_s if opts[:short] unless opts[:short] == :none
|
208
|
+
opts[:short] = case opts[:short]
|
209
|
+
when /^-(.)$/; $1
|
210
|
+
when nil, :none, /^.$/; opts[:short]
|
211
|
+
else raise ArgumentError, "invalid short option name '#{opts[:short].inspect}'"
|
212
|
+
end
|
213
|
+
|
214
|
+
if opts[:short]
|
215
|
+
raise ArgumentError, "short option name #{opts[:short].inspect} is already taken; please specify a (different) :short" if @short[opts[:short]]
|
216
|
+
raise ArgumentError, "a short option name can't be a number or a dash" if opts[:short] =~ INVALID_SHORT_ARG_REGEX
|
217
|
+
end
|
218
|
+
|
219
|
+
## fill in :default for flags
|
220
|
+
opts[:default] = false if opts[:type] == :flag && opts[:default].nil?
|
221
|
+
|
222
|
+
## autobox :default for :multi (multi-occurrence) arguments
|
223
|
+
opts[:default] = [opts[:default]] if opts[:default] && opts[:multi] && !opts[:default].is_a?(Array)
|
224
|
+
|
225
|
+
## fill in :multi
|
226
|
+
opts[:multi] ||= false
|
227
|
+
|
228
|
+
opts[:desc] ||= desc
|
229
|
+
@long[opts[:long]] = name
|
230
|
+
@short[opts[:short]] = name if opts[:short] && opts[:short] != :none
|
231
|
+
@specs[name] = opts
|
232
|
+
@order << [:opt, name]
|
233
|
+
end
|
234
|
+
|
235
|
+
## Sets the version string. If set, the user can request the version
|
236
|
+
## on the commandline. Should probably be of the form "<program name>
|
237
|
+
## <version number>".
|
238
|
+
def version s=nil; @version = s if s; @version end
|
239
|
+
|
240
|
+
## Adds text to the help display. Can be interspersed with calls to
|
241
|
+
## #opt to build a multi-section help page.
|
242
|
+
def banner s; @order << [:text, s] end
|
243
|
+
alias :text :banner
|
244
|
+
|
245
|
+
## Marks two (or more!) options as requiring each other. Only handles
|
246
|
+
## undirected (i.e., mutual) dependencies. Directed dependencies are
|
247
|
+
## better modeled with Trollop::die.
|
248
|
+
def depends *syms
|
249
|
+
syms.each { |sym| raise ArgumentError, "unknown option '#{sym}'" unless @specs[sym] }
|
250
|
+
@constraints << [:depends, syms]
|
251
|
+
end
|
252
|
+
|
253
|
+
## Marks two (or more!) options as conflicting.
|
254
|
+
def conflicts *syms
|
255
|
+
syms.each { |sym| raise ArgumentError, "unknown option '#{sym}'" unless @specs[sym] }
|
256
|
+
@constraints << [:conflicts, syms]
|
257
|
+
end
|
258
|
+
|
259
|
+
## Defines a set of words which cause parsing to terminate when
|
260
|
+
## encountered, such that any options to the left of the word are
|
261
|
+
## parsed as usual, and options to the right of the word are left
|
262
|
+
## intact.
|
263
|
+
##
|
264
|
+
## A typical use case would be for subcommand support, where these
|
265
|
+
## would be set to the list of subcommands. A subsequent Trollop
|
266
|
+
## invocation would then be used to parse subcommand options, after
|
267
|
+
## shifting the subcommand off of ARGV.
|
268
|
+
def stop_on *words
|
269
|
+
@stop_words = [*words].flatten
|
270
|
+
end
|
271
|
+
|
272
|
+
## Similar to #stop_on, but stops on any unknown word when encountered
|
273
|
+
## (unless it is a parameter for an argument). This is useful for
|
274
|
+
## cases where you don't know the set of subcommands ahead of time,
|
275
|
+
## i.e., without first parsing the global options.
|
276
|
+
def stop_on_unknown
|
277
|
+
@stop_on_unknown = true
|
278
|
+
end
|
279
|
+
|
280
|
+
## Parses the commandline. Typically called by Trollop::options.
|
281
|
+
def parse cmdline=ARGV
|
282
|
+
vals = {}
|
283
|
+
required = {}
|
284
|
+
|
285
|
+
opt :version, "Print version and exit" if @version unless @specs[:version] || @long["version"]
|
286
|
+
opt :help, "Show this message" unless @specs[:help] || @long["help"]
|
287
|
+
|
288
|
+
@specs.each do |sym, opts|
|
289
|
+
required[sym] = true if opts[:required]
|
290
|
+
vals[sym] = opts[:default]
|
291
|
+
vals[sym] = [] if opts[:multi] && !opts[:default] # multi arguments default to [], not nil
|
292
|
+
end
|
293
|
+
|
294
|
+
resolve_default_short_options
|
295
|
+
|
296
|
+
## resolve symbols
|
297
|
+
given_args = {}
|
298
|
+
@leftovers = each_arg cmdline do |arg, params|
|
299
|
+
sym = case arg
|
300
|
+
when /^-([^-])$/
|
301
|
+
@short[$1]
|
302
|
+
when /^--([^-]\S*)$/
|
303
|
+
@long[$1]
|
304
|
+
else
|
305
|
+
raise CommandlineError, "invalid argument syntax: '#{arg}'"
|
306
|
+
end
|
307
|
+
raise CommandlineError, "unknown argument '#{arg}'" unless sym
|
308
|
+
|
309
|
+
if given_args.include?(sym) && !@specs[sym][:multi]
|
310
|
+
raise CommandlineError, "option '#{arg}' specified multiple times"
|
311
|
+
end
|
312
|
+
|
313
|
+
given_args[sym] ||= {}
|
314
|
+
|
315
|
+
given_args[sym][:arg] = arg
|
316
|
+
given_args[sym][:params] ||= []
|
317
|
+
|
318
|
+
# The block returns the number of parameters taken.
|
319
|
+
num_params_taken = 0
|
320
|
+
|
321
|
+
unless params.nil?
|
322
|
+
if SINGLE_ARG_TYPES.include?(@specs[sym][:type])
|
323
|
+
given_args[sym][:params] << params[0, 1] # take the first parameter
|
324
|
+
num_params_taken = 1
|
325
|
+
elsif MULTI_ARG_TYPES.include?(@specs[sym][:type])
|
326
|
+
given_args[sym][:params] << params # take all the parameters
|
327
|
+
num_params_taken = params.size
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
num_params_taken
|
332
|
+
end
|
333
|
+
|
334
|
+
## check for version and help args
|
335
|
+
raise VersionNeeded if given_args.include? :version
|
336
|
+
raise HelpNeeded if given_args.include? :help
|
337
|
+
|
338
|
+
## check constraint satisfaction
|
339
|
+
@constraints.each do |type, syms|
|
340
|
+
constraint_sym = syms.find { |sym| given_args[sym] }
|
341
|
+
next unless constraint_sym
|
342
|
+
|
343
|
+
case type
|
344
|
+
when :depends
|
345
|
+
syms.each { |sym| raise CommandlineError, "--#{@specs[constraint_sym][:long]} requires --#{@specs[sym][:long]}" unless given_args.include? sym }
|
346
|
+
when :conflicts
|
347
|
+
syms.each { |sym| raise CommandlineError, "--#{@specs[constraint_sym][:long]} conflicts with --#{@specs[sym][:long]}" if given_args.include?(sym) && (sym != constraint_sym) }
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
required.each do |sym, val|
|
352
|
+
raise CommandlineError, "option '#{sym}' must be specified" unless given_args.include? sym
|
353
|
+
end
|
354
|
+
|
355
|
+
## parse parameters
|
356
|
+
given_args.each do |sym, given_data|
|
357
|
+
arg = given_data[:arg]
|
358
|
+
params = given_data[:params]
|
359
|
+
|
360
|
+
opts = @specs[sym]
|
361
|
+
raise CommandlineError, "option '#{arg}' needs a parameter" if params.empty? && opts[:type] != :flag
|
362
|
+
|
363
|
+
vals["#{sym}_given".intern] = true # mark argument as specified on the commandline
|
364
|
+
|
365
|
+
case opts[:type]
|
366
|
+
when :flag
|
367
|
+
vals[sym] = !opts[:default]
|
368
|
+
when :int, :ints
|
369
|
+
vals[sym] = params.map { |pg| pg.map { |p| parse_integer_parameter p, arg } }
|
370
|
+
when :float, :floats
|
371
|
+
vals[sym] = params.map { |pg| pg.map { |p| parse_float_parameter p, arg } }
|
372
|
+
when :string, :strings
|
373
|
+
vals[sym] = params.map { |pg| pg.map { |p| p.to_s } }
|
374
|
+
when :io, :ios
|
375
|
+
vals[sym] = params.map { |pg| pg.map { |p| parse_io_parameter p, arg } }
|
376
|
+
when :date, :dates
|
377
|
+
vals[sym] = params.map { |pg| pg.map { |p| parse_date_parameter p, arg } }
|
378
|
+
end
|
379
|
+
|
380
|
+
if SINGLE_ARG_TYPES.include?(opts[:type])
|
381
|
+
unless opts[:multi] # single parameter
|
382
|
+
vals[sym] = vals[sym][0][0]
|
383
|
+
else # multiple options, each with a single parameter
|
384
|
+
vals[sym] = vals[sym].map { |p| p[0] }
|
385
|
+
end
|
386
|
+
elsif MULTI_ARG_TYPES.include?(opts[:type]) && !opts[:multi]
|
387
|
+
vals[sym] = vals[sym][0] # single option, with multiple parameters
|
388
|
+
end
|
389
|
+
# else: multiple options, with multiple parameters
|
390
|
+
end
|
391
|
+
|
392
|
+
## allow openstruct-style accessors
|
393
|
+
class << vals
|
394
|
+
def method_missing(m, *args)
|
395
|
+
self[m] || self[m.to_s]
|
396
|
+
end
|
397
|
+
end
|
398
|
+
vals
|
399
|
+
end
|
400
|
+
|
401
|
+
def parse_date_parameter param, arg #:nodoc:
|
402
|
+
begin
|
403
|
+
begin
|
404
|
+
time = Chronic.parse(param)
|
405
|
+
rescue NameError
|
406
|
+
# chronic is not available
|
407
|
+
end
|
408
|
+
time ? Date.new(time.year, time.month, time.day) : Date.parse(param)
|
409
|
+
rescue ArgumentError => e
|
410
|
+
raise CommandlineError, "option '#{arg}' needs a date"
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
## Print the help message to +stream+.
|
415
|
+
def educate stream=$stdout
|
416
|
+
width # just calculate it now; otherwise we have to be careful not to
|
417
|
+
# call this unless the cursor's at the beginning of a line.
|
418
|
+
|
419
|
+
left = {}
|
420
|
+
@specs.each do |name, spec|
|
421
|
+
left[name] = "--#{spec[:long]}" +
|
422
|
+
(spec[:short] && spec[:short] != :none ? ", -#{spec[:short]}" : "") +
|
423
|
+
case spec[:type]
|
424
|
+
when :flag; ""
|
425
|
+
when :int; " <i>"
|
426
|
+
when :ints; " <i+>"
|
427
|
+
when :string; " <s>"
|
428
|
+
when :strings; " <s+>"
|
429
|
+
when :float; " <f>"
|
430
|
+
when :floats; " <f+>"
|
431
|
+
when :io; " <filename/uri>"
|
432
|
+
when :ios; " <filename/uri+>"
|
433
|
+
when :date; " <date>"
|
434
|
+
when :dates; " <date+>"
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
leftcol_width = left.values.map { |s| s.length }.max || 0
|
439
|
+
rightcol_start = leftcol_width + 6 # spaces
|
440
|
+
|
441
|
+
unless @order.size > 0 && @order.first.first == :text
|
442
|
+
stream.puts "#@version\n" if @version
|
443
|
+
stream.puts "Options:"
|
444
|
+
end
|
445
|
+
|
446
|
+
@order.each do |what, opt|
|
447
|
+
if what == :text
|
448
|
+
stream.puts wrap(opt)
|
449
|
+
next
|
450
|
+
end
|
451
|
+
|
452
|
+
spec = @specs[opt]
|
453
|
+
stream.printf " %#{leftcol_width}s: ", left[opt]
|
454
|
+
desc = spec[:desc] + begin
|
455
|
+
default_s = case spec[:default]
|
456
|
+
when $stdout; "<stdout>"
|
457
|
+
when $stdin; "<stdin>"
|
458
|
+
when $stderr; "<stderr>"
|
459
|
+
when Array
|
460
|
+
spec[:default].join(", ")
|
461
|
+
else
|
462
|
+
spec[:default].to_s
|
463
|
+
end
|
464
|
+
|
465
|
+
if spec[:default]
|
466
|
+
if spec[:desc] =~ /\.$/
|
467
|
+
" (Default: #{default_s})"
|
468
|
+
else
|
469
|
+
" (default: #{default_s})"
|
470
|
+
end
|
471
|
+
else
|
472
|
+
""
|
473
|
+
end
|
474
|
+
end
|
475
|
+
stream.puts wrap(desc, :width => width - rightcol_start - 1, :prefix => rightcol_start)
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
def width #:nodoc:
|
480
|
+
@width ||= if $stdout.tty?
|
481
|
+
begin
|
482
|
+
require 'curses'
|
483
|
+
Curses::init_screen
|
484
|
+
x = Curses::cols
|
485
|
+
Curses::close_screen
|
486
|
+
x
|
487
|
+
rescue Exception
|
488
|
+
80
|
489
|
+
end
|
490
|
+
else
|
491
|
+
80
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
def wrap str, opts={} # :nodoc:
|
496
|
+
if str == ""
|
497
|
+
[""]
|
498
|
+
else
|
499
|
+
str.split("\n").map { |s| wrap_line s, opts }.flatten
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
private
|
504
|
+
|
505
|
+
## yield successive arg, parameter pairs
|
506
|
+
def each_arg args
|
507
|
+
remains = []
|
508
|
+
i = 0
|
509
|
+
|
510
|
+
until i >= args.length
|
511
|
+
if @stop_words.member? args[i]
|
512
|
+
remains += args[i .. -1]
|
513
|
+
return remains
|
514
|
+
end
|
515
|
+
case args[i]
|
516
|
+
when /^--$/ # arg terminator
|
517
|
+
remains += args[(i + 1) .. -1]
|
518
|
+
return remains
|
519
|
+
when /^--(\S+?)=(.*)$/ # long argument with equals
|
520
|
+
yield "--#{$1}", [$2]
|
521
|
+
i += 1
|
522
|
+
when /^--(\S+)$/ # long argument
|
523
|
+
params = collect_argument_parameters(args, i + 1)
|
524
|
+
unless params.empty?
|
525
|
+
num_params_taken = yield args[i], params
|
526
|
+
unless num_params_taken
|
527
|
+
if @stop_on_unknown
|
528
|
+
remains += args[i + 1 .. -1]
|
529
|
+
return remains
|
530
|
+
else
|
531
|
+
remains += params
|
532
|
+
end
|
533
|
+
end
|
534
|
+
i += 1 + num_params_taken
|
535
|
+
else # long argument no parameter
|
536
|
+
yield args[i], nil
|
537
|
+
i += 1
|
538
|
+
end
|
539
|
+
when /^-(\S+)$/ # one or more short arguments
|
540
|
+
shortargs = $1.split(//)
|
541
|
+
shortargs.each_with_index do |a, j|
|
542
|
+
if j == (shortargs.length - 1)
|
543
|
+
params = collect_argument_parameters(args, i + 1)
|
544
|
+
unless params.empty?
|
545
|
+
num_params_taken = yield "-#{a}", params
|
546
|
+
unless num_params_taken
|
547
|
+
if @stop_on_unknown
|
548
|
+
remains += args[i + 1 .. -1]
|
549
|
+
return remains
|
550
|
+
else
|
551
|
+
remains += params
|
552
|
+
end
|
553
|
+
end
|
554
|
+
i += 1 + num_params_taken
|
555
|
+
else # argument no parameter
|
556
|
+
yield "-#{a}", nil
|
557
|
+
i += 1
|
558
|
+
end
|
559
|
+
else
|
560
|
+
yield "-#{a}", nil
|
561
|
+
end
|
562
|
+
end
|
563
|
+
else
|
564
|
+
if @stop_on_unknown
|
565
|
+
remains += args[i .. -1]
|
566
|
+
return remains
|
567
|
+
else
|
568
|
+
remains << args[i]
|
569
|
+
i += 1
|
570
|
+
end
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
remains
|
575
|
+
end
|
576
|
+
|
577
|
+
def parse_integer_parameter param, arg
|
578
|
+
raise CommandlineError, "option '#{arg}' needs an integer" unless param =~ /^\d+$/
|
579
|
+
param.to_i
|
580
|
+
end
|
581
|
+
|
582
|
+
def parse_float_parameter param, arg
|
583
|
+
raise CommandlineError, "option '#{arg}' needs a floating-point number" unless param =~ FLOAT_RE
|
584
|
+
param.to_f
|
585
|
+
end
|
586
|
+
|
587
|
+
def parse_io_parameter param, arg
|
588
|
+
case param
|
589
|
+
when /^(stdin|-)$/i; $stdin
|
590
|
+
else
|
591
|
+
require 'open-uri'
|
592
|
+
begin
|
593
|
+
open param
|
594
|
+
rescue SystemCallError => e
|
595
|
+
raise CommandlineError, "file or url for option '#{arg}' cannot be opened: #{e.message}"
|
596
|
+
end
|
597
|
+
end
|
598
|
+
end
|
599
|
+
|
600
|
+
def collect_argument_parameters args, start_at
|
601
|
+
params = []
|
602
|
+
pos = start_at
|
603
|
+
while args[pos] && args[pos] !~ PARAM_RE && !@stop_words.member?(args[pos]) do
|
604
|
+
params << args[pos]
|
605
|
+
pos += 1
|
606
|
+
end
|
607
|
+
params
|
608
|
+
end
|
609
|
+
|
610
|
+
def resolve_default_short_options
|
611
|
+
@order.each do |type, name|
|
612
|
+
next unless type == :opt
|
613
|
+
opts = @specs[name]
|
614
|
+
next if opts[:short]
|
615
|
+
|
616
|
+
c = opts[:long].split(//).find { |d| d !~ INVALID_SHORT_ARG_REGEX && !@short.member?(d) }
|
617
|
+
raise ArgumentError, "can't generate a default short option name for #{opts[:long].inspect}: out of unique characters" unless c
|
618
|
+
|
619
|
+
opts[:short] = c
|
620
|
+
@short[c] = name
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
def wrap_line str, opts={}
|
625
|
+
prefix = opts[:prefix] || 0
|
626
|
+
width = opts[:width] || (self.width - 1)
|
627
|
+
start = 0
|
628
|
+
ret = []
|
629
|
+
until start > str.length
|
630
|
+
nextt =
|
631
|
+
if start + width >= str.length
|
632
|
+
str.length
|
633
|
+
else
|
634
|
+
x = str.rindex(/\s/, start + width)
|
635
|
+
x = str.index(/\s/, start) if x && x < start
|
636
|
+
x || str.length
|
637
|
+
end
|
638
|
+
ret << (ret.empty? ? "" : " " * prefix) + str[start ... nextt]
|
639
|
+
start = nextt + 1
|
640
|
+
end
|
641
|
+
ret
|
642
|
+
end
|
643
|
+
|
644
|
+
## instance_eval but with ability to handle block arguments
|
645
|
+
## thanks to why: http://redhanded.hobix.com/inspect/aBlockCostume.html
|
646
|
+
def cloaker &b
|
647
|
+
(class << self; self; end).class_eval do
|
648
|
+
define_method :cloaker_, &b
|
649
|
+
meth = instance_method :cloaker_
|
650
|
+
remove_method :cloaker_
|
651
|
+
meth
|
652
|
+
end
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
## The top-level entry method into Trollop. Creates a Parser object,
|
657
|
+
## passes the block to it, then parses +args+ with it, handling any
|
658
|
+
## errors or requests for help or version information appropriately (and
|
659
|
+
## then exiting). Modifies +args+ in place. Returns a hash of option
|
660
|
+
## values.
|
661
|
+
##
|
662
|
+
## The block passed in should contain zero or more calls to +opt+
|
663
|
+
## (Parser#opt), zero or more calls to +text+ (Parser#text), and
|
664
|
+
## probably a call to +version+ (Parser#version).
|
665
|
+
##
|
666
|
+
## The returned block contains a value for every option specified with
|
667
|
+
## +opt+. The value will be the value given on the commandline, or the
|
668
|
+
## default value if the option was not specified on the commandline. For
|
669
|
+
## every option specified on the commandline, a key "<option
|
670
|
+
## name>_given" will also be set in the hash.
|
671
|
+
##
|
672
|
+
## Example:
|
673
|
+
##
|
674
|
+
## require 'trollop'
|
675
|
+
## opts = Trollop::options do
|
676
|
+
## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
|
677
|
+
## opt :goat, "Use goat mode", :default => true # a flag --goat, defaulting to true
|
678
|
+
## opt :num_limbs, "Number of limbs", :default => 4 # an integer --num-limbs <i>, defaulting to 4
|
679
|
+
## opt :num_thumbs, "Number of thumbs", :type => :int # an integer --num-thumbs <i>, defaulting to nil
|
680
|
+
## end
|
681
|
+
##
|
682
|
+
## ## if called with no arguments
|
683
|
+
## p opts # => { :monkey => false, :goat => true, :num_limbs => 4, :num_thumbs => nil }
|
684
|
+
##
|
685
|
+
## ## if called with --monkey
|
686
|
+
## p opts # => {:monkey_given=>true, :monkey=>true, :goat=>true, :num_limbs=>4, :help=>false, :num_thumbs=>nil}
|
687
|
+
##
|
688
|
+
## See more examples at http://trollop.rubyforge.org.
|
689
|
+
def options args = ARGV, *a, &b
|
690
|
+
@p = Parser.new(*a, &b)
|
691
|
+
begin
|
692
|
+
vals = @p.parse args
|
693
|
+
args.clear
|
694
|
+
@p.leftovers.each { |l| args << l }
|
695
|
+
vals
|
696
|
+
rescue CommandlineError => e
|
697
|
+
$stderr.puts "Error: #{e.message}."
|
698
|
+
$stderr.puts "Try --help for help."
|
699
|
+
exit(-1)
|
700
|
+
rescue HelpNeeded
|
701
|
+
@p.educate
|
702
|
+
exit
|
703
|
+
rescue VersionNeeded
|
704
|
+
puts @p.version
|
705
|
+
exit
|
706
|
+
end
|
707
|
+
end
|
708
|
+
|
709
|
+
## Informs the user that their usage of 'arg' was wrong, as detailed by
|
710
|
+
## 'msg', and dies. Example:
|
711
|
+
##
|
712
|
+
## options do
|
713
|
+
## opt :volume, :default => 0.0
|
714
|
+
## end
|
715
|
+
##
|
716
|
+
## die :volume, "too loud" if opts[:volume] > 10.0
|
717
|
+
## die :volume, "too soft" if opts[:volume] < 0.1
|
718
|
+
##
|
719
|
+
## In the one-argument case, simply print that message, a notice
|
720
|
+
## about -h, and die. Example:
|
721
|
+
##
|
722
|
+
## options do
|
723
|
+
## opt :whatever # ...
|
724
|
+
## end
|
725
|
+
##
|
726
|
+
## Trollop::die "need at least one filename" if ARGV.empty?
|
727
|
+
def die arg, msg=nil
|
728
|
+
if msg
|
729
|
+
$stderr.puts "Error: argument --#{@p.specs[arg][:long]} #{msg}."
|
730
|
+
else
|
731
|
+
$stderr.puts "Error: #{arg}."
|
732
|
+
end
|
733
|
+
$stderr.puts "Try --help for help."
|
734
|
+
exit(-1)
|
735
|
+
end
|
736
|
+
|
737
|
+
module_function :options, :die
|
738
|
+
|
739
|
+
end # module
|