strelka 0.11.0 → 0.12.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23f3a2bf90987379d646fd64f813d403057ba894
4
- data.tar.gz: 7df48c8764cf88fc8e357fd6d4e70ab84bc7af9d
3
+ metadata.gz: 4def250c1b369dbb9c80a1ed8a928e2e83d6dd70
4
+ data.tar.gz: 12db351245be50c0d822072c7b1b28fc6f4b152b
5
5
  SHA512:
6
- metadata.gz: f0d5356fbb5c03eccdb77d055796a6b120aabfd8702a590725b16b8b9446a42ad157fdd05841e96ab761ce91e74bdb8ade89893c4365d4cb5b7f34bc698f2ac1
7
- data.tar.gz: 6993272bb47fd7874689853b7439b70581b27788ab3b1195125180eedca958bdc9a4e25bef06bf7d3587ea331dd70fd09d2d5a565fca256e2ec92b546679160b
6
+ metadata.gz: ee7ccc09f871ef0d019d61b6ed090ea2f296316d0000d803bca487345ce16293852141db9c21a743596ac0208f16ac82128f73c241ae9542308c4cade34eb699
7
+ data.tar.gz: 761861faeb03a911d6efba3a88d674948bd954ec47bc173fe5ed5d371d2535669292ab8d5d7f9b8d4e8351c4c8f32af105d2788a5ce060cd61edc9b7b7acfb7d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ == v0.12.0 [2016-11-03] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ Enhancements:
4
+
5
+ - Rewritten command line interface
6
+ - Rewritten app-discovery system
7
+
8
+
1
9
  == v0.11.0 [2016-01-20] Mahlon E. Smith <mahlon@martini.nu>
2
10
 
3
11
  Enhancements:
data/Manifest.txt CHANGED
@@ -54,6 +54,10 @@ lib/strelka/authprovider.rb
54
54
  lib/strelka/authprovider/basic.rb
55
55
  lib/strelka/authprovider/hostaccess.rb
56
56
  lib/strelka/behavior/plugin.rb
57
+ lib/strelka/cli.rb
58
+ lib/strelka/command/config.rb
59
+ lib/strelka/command/discover.rb
60
+ lib/strelka/command/start.rb
57
61
  lib/strelka/constants.rb
58
62
  lib/strelka/cookie.rb
59
63
  lib/strelka/cookieset.rb
@@ -107,6 +111,7 @@ spec/strelka/app_spec.rb
107
111
  spec/strelka/authprovider/basic_spec.rb
108
112
  spec/strelka/authprovider/hostaccess_spec.rb
109
113
  spec/strelka/authprovider_spec.rb
114
+ spec/strelka/cli_spec.rb
110
115
  spec/strelka/cookie_spec.rb
111
116
  spec/strelka/cookieset_spec.rb
112
117
  spec/strelka/discovery_spec.rb
data/README.rdoc CHANGED
@@ -20,7 +20,7 @@ Her name means "little arrow".
20
20
  == Prerequisites
21
21
 
22
22
  * Mongrel2[http://mongrel2.org/] 1.8.0 or better
23
- * Ruby 1.9.3 or better
23
+ * Ruby 2.2 or better
24
24
 
25
25
 
26
26
  == Installation
@@ -142,6 +142,29 @@ you see the text "Hello, World!", congrats! We'll build off of this in the
142
142
  next section, the {Strelka Tutorial}[rdoc-ref:Tutorial.rdoc].
143
143
 
144
144
 
145
+ === Packaging
146
+
147
+ If you want your app to be launchable via the <tt>strelka</tt> command, you can
148
+ do so by registering it with the Strelka::Discovery module. For instance, if
149
+ your app is defined in a file called <tt>lib/acme/store.rb</tt> and you want to
150
+ start it with the command
151
+
152
+ strelka start acme-store
153
+
154
+ then you'd do something like:
155
+
156
+ require 'strelka/discovery'
157
+ Strelka::Discovery.register_app( 'acme-store', 'acme/store.rb' )
158
+
159
+ If you want the app to be launchable directory from the gem, you can put the
160
+ above discovery code in a file named <code>lib/strelka/apps.rb</code> to your
161
+ gem. The `strelka` command will load all of those files from any installed gems
162
+ before running <tt>start</tt>. You can test to see which apps are discoverable
163
+ this way using the <tt>strelka discover</tt> command.
164
+
165
+ See Strelka::Discovery for more info.
166
+
167
+
145
168
  == Further Reading
146
169
 
147
170
  You'll likely want to start with {the Tutorial}[rdoc-ref:Tutorial.rdoc].
@@ -161,14 +184,6 @@ Here's a tentative list of what kinds of stuff we have planned:
161
184
  headers, especially for service applications
162
185
  * caching -- utilities for easy HTTP caching
163
186
 
164
- === Deployment/Packaging
165
-
166
- You'll be able to package up your applications as Rubygems for easy deployment.
167
- The Strelka::App class already supports application discovery, but we
168
- want to hook that up to the 'strelka' command line tool so you can install
169
- and run them with a minimum of manual monkeying around with directories,
170
- migrations, etc.
171
-
172
187
  === New Application Styles
173
188
 
174
189
  Create some new handler classes for different application styles, similar to
@@ -195,7 +210,7 @@ and generate the API documentation.
195
210
 
196
211
  == License
197
212
 
198
- Copyright (c) 2011-2013, Michael Granger and Mahlon E. Smith
213
+ Copyright (c) 2011-2016, Michael Granger and Mahlon E. Smith
199
214
  All rights reserved.
200
215
 
201
216
  Redistribution and use in source and binary forms, with or without
data/Rakefile CHANGED
@@ -30,7 +30,7 @@ hoespec = Hoe.spec 'strelka' do
30
30
  self.dependency 'highline', '~> 1.6'
31
31
  self.dependency 'inversion', '~> 0.12'
32
32
  self.dependency 'loggability', '~> 0.9'
33
- self.dependency 'mongrel2', ['~> 0.43', '>= 0.43.1']
33
+ self.dependency 'mongrel2', '~> 0.44'
34
34
  self.dependency 'pluggability', '~> 0.4'
35
35
  self.dependency 'sysexits', '~> 1.1'
36
36
  self.dependency 'trollop', '~> 2.0'
@@ -42,7 +42,7 @@ hoespec = Hoe.spec 'strelka' do
42
42
  self.dependency 'simplecov', '~> 0.7', :developer
43
43
  self.dependency 'rdoc-generator-fivefish', '~> 0.1', :developer
44
44
 
45
- self.require_ruby_version( '>=2.0.0' )
45
+ self.require_ruby_version( '>=2.2.0' )
46
46
  self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
47
47
  self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
48
48
  self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
data/bin/strelka CHANGED
@@ -2,416 +2,7 @@
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
 
4
4
  require 'strelka'
5
- require 'strelka/discovery'
5
+ require 'strelka/cli'
6
6
 
7
- require 'trollop'
8
- require 'highline'
9
- require 'loggability'
10
-
11
- # Have to do it this way to avoid the vendored 'sysexits' under OSX.
12
- gem 'sysexits'
13
- require 'sysexits'
14
-
15
-
16
- # A tool for setting up and running Strelka apps
17
- class Strelka::CLICommand
18
- extend ::Sysexits,
19
- Loggability
20
- include Sysexits,
21
- Strelka::Constants
22
-
23
-
24
- # Write logs to Strelka's logger
25
- log_to :strelka
26
-
27
-
28
- # Make a HighLine color scheme
29
- COLOR_SCHEME = HighLine::ColorScheme.new do |scheme|
30
- scheme[:header] = [ :bold, :yellow ]
31
- scheme[:subheader] = [ :bold, :white ]
32
- scheme[:key] = [ :white ]
33
- scheme[:value] = [ :bold, :white ]
34
- scheme[:error] = [ :red ]
35
- scheme[:warning] = [ :yellow ]
36
- scheme[:message] = [ :reset ]
37
- end
38
-
39
-
40
- # Class instance variables
41
- @command_help = Hash.new {|h,k| h[k] = { :desc => nil, :usage => ''} }
42
- @prompt = @option_parser = nil
43
-
44
-
45
- ### Run the utility with the given +args+.
46
- def self::run( args )
47
- HighLine.color_scheme = COLOR_SCHEME
48
-
49
- oparser = self.make_option_parser
50
- opts = Trollop.with_standard_exception_handling( oparser ) do
51
- oparser.parse( args )
52
- end
53
-
54
- command = oparser.leftovers.shift
55
- self.new( opts ).run( command, *oparser.leftovers )
56
- exit :ok
57
-
58
- rescue => err
59
- self.log.fatal "Oops: %s: %s" % [ err.class.name, err.message ]
60
- self.log.debug { ' ' + err.backtrace.join("\n ") }
61
-
62
- exit :software_error
63
- end
64
-
65
-
66
- ### Return a String that describes the available commands, e.g., for the 'help'
67
- ### command.
68
- def self::make_command_table
69
- commands = self.available_commands
70
-
71
- # Build the command table
72
- col1len = commands.map( &:length ).max
73
- return commands.collect do |cmd|
74
- helptext = self.help( cmd.to_sym ) or next # no help == invisible command
75
- "%s %s" % [
76
- self.prompt.color(cmd.rjust(col1len), :key),
77
- self.prompt.color(helptext, :value)
78
- ]
79
- end.compact
80
- end
81
-
82
-
83
- ### Return an Array of the available commands.
84
- def self::available_commands
85
- return self.public_instance_methods( false ).
86
- map( &:to_s ).
87
- grep( /_command$/ ).
88
- map {|methodname| methodname.sub(/_command$/, '') }.
89
- sort
90
- end
91
-
92
-
93
- ### Create and configure a command-line option parser for the command.
94
- ### Returns a Trollop::Parser.
95
- def self::make_option_parser
96
- unless @option_parser
97
- progname = File.basename( $0 )
98
-
99
- # Make a list of the log level names and the available commands
100
- loglevels = Loggability::LOG_LEVELS.
101
- sort_by {|name,lvl| lvl }.
102
- collect {|name,lvl| name.to_s }.
103
- join( ', ' )
104
- command_table = self.make_command_table
105
- commands = self.available_commands
106
-
107
- @option_parser = Trollop::Parser.new do
108
- banner "Manage Strelka apps"
109
- version( Strelka.version_string(true) )
110
-
111
- stop_on( commands )
112
-
113
- text ''
114
- command_table.each {|line| text(line) }
115
- text ''
116
-
117
- text 'Global Options'
118
- opt :config, "Specify the config file to load.", :type => :string
119
- opt :datadir, "Override the Strelka data directory.", :type => :string,
120
- :short => :D
121
- opt :requires, "Specify additional libraries to require.", :type => :strings,
122
- :short => :r
123
- text ''
124
-
125
- text 'Other Options:'
126
- opt :debug, "Turn debugging on. Also sets the --loglevel to 'debug'."
127
- opt :loglevel, "Set the logging level. Must be one of: #{loglevels}",
128
- :default => Strelka.logger.level.to_s
129
- end
130
- end
131
-
132
- return @option_parser
133
- end
134
-
135
-
136
- ### Add a help string for the given +command+.
137
- def self::help( command, helpstring=nil )
138
- if helpstring
139
- @command_help[ command.to_sym ][:desc] = helpstring
140
- end
141
-
142
- return @command_help[ command.to_sym ][:desc]
143
- end
144
-
145
-
146
- ### Add/fetch the +usagestring+ for +command+.
147
- def self::usage( command, usagestring=nil )
148
- if usagestring
149
- prefix = usagestring[ /\A(\s+)/, 1 ]
150
- usagestring.gsub!( /^#{prefix}/m, '' ) if prefix
151
-
152
- @command_help[ command.to_sym ][:usage] = usagestring
153
- end
154
-
155
- return @command_help[ command.to_sym ][:usage]
156
- end
157
-
158
-
159
- ### Return the global Highline prompt object, creating it if necessary.
160
- def self::prompt
161
- unless @prompt
162
- @prompt = HighLine.new
163
-
164
- columns = @prompt.output_cols.nonzero? || 80
165
- rows = @prompt.output_rows.nonzero? || 1000
166
-
167
- @prompt.page_at = rows - 5
168
- @prompt.wrap_at = columns - 2
169
- end
170
-
171
- return @prompt
172
- end
173
-
174
-
175
- #################################################################
176
- ### I N S T A N C E M E T H O D S
177
- #################################################################
178
-
179
- ### Create a new instance of the command and set it up with the given
180
- ### +options+.
181
- def initialize( options )
182
- Loggability.format_with( :color ) if $stderr.tty?
183
- @options = options
184
-
185
- if @options.debug
186
- $DEBUG = true
187
- $VERBOSE = true
188
- Loggability.level = :debug
189
- elsif @options.loglevel
190
- Loggability.level = @options.loglevel
191
- end
192
-
193
- end
194
-
195
-
196
- ######
197
- public
198
- ######
199
-
200
- # The Trollop options hash the command will read its configuration from
201
- attr_reader :options
202
-
203
-
204
- # Delegate the instance #prompt method to the class method instead
205
- define_method( :prompt, &self.method(:prompt) )
206
-
207
-
208
- ### Run the command with the specified +command+ and +args+.
209
- def run( command, *args )
210
- command ||= 'help'
211
- cmd_method = nil
212
-
213
- # Set the datadir override if it's given
214
- if self.options.datadir
215
- self.log.debug "Using data dir option: %s" % [ self.options.datadir ]
216
- Strelka::Discovery.local_data_dirs = Pathname( self.options.datadir )
217
- end
218
-
219
- # Include a 'lib' directory if there is one
220
- $LOAD_PATH.unshift( 'lib' ) if File.directory?( 'lib' )
221
-
222
- # Run the command
223
- begin
224
- cmd_method = self.method( "#{command}_command" )
225
- rescue NameError => err
226
- error "No such command %p" % [ command ]
227
- exit :usage
228
- end
229
-
230
- cmd_method.call( *args )
231
- end
232
-
233
-
234
- #
235
- # Commands
236
- #
237
-
238
- ### The 'help' command
239
- def help_command( *args )
240
-
241
- # Subcommand help
242
- if !args.empty?
243
- command = args.shift
244
-
245
- if self.class.available_commands.include?( command )
246
- header( self.class.help(command) )
247
- desc = "\n" + 'Usage: ' + command + ' ' + self.class.usage(command) + "\n"
248
- message( desc )
249
- else
250
- error "No such command %p" % [ command ]
251
- end
252
-
253
- # Help by itself show the table of available commands
254
- else
255
- command_table = self.class.make_command_table
256
- header "Available Commands"
257
- message( *command_table )
258
- end
259
-
260
- end
261
- help :help, "Show help for a single COMMAND if given, or list available commands if not"
262
- usage :help, "[COMMAND]"
263
-
264
-
265
- ### The 'discover' command
266
- def discover_command( *args )
267
- header "Searching for Strelka applications..."
268
-
269
- self.load_additional_requires
270
-
271
- paths = Strelka::Discovery.discover_paths
272
- if paths.empty?
273
- message "None found."
274
- else
275
- paths.each do |gemname, paths|
276
- message "\n"
277
-
278
- if gemname == ''
279
- subheader "Local: "
280
- else
281
- subheader "Gem: #{gemname}"
282
- end
283
-
284
- filenames = paths.map {|path| path.basename.to_s }
285
- list( filenames )
286
- end
287
- end
288
- end
289
- help :discover, "Show available Strelka applications installed as gems."
290
-
291
-
292
- ### The 'setup' command
293
- def setup_command( *args )
294
- end
295
- help :setup, "Set up a new Strelka environment and start the admin server."
296
-
297
-
298
- ### The 'start' command
299
- def start_command( *args )
300
- appname = args.pop
301
- gemname = args.pop
302
- path = nil
303
-
304
- if File.exist?( appname )
305
- header "Starting %s." % [ appname ]
306
- path = appname
307
- else
308
- path, gemname = Strelka::Discovery.find( appname, gemname )
309
-
310
- header "Starting the %s app%s" % [
311
- appname,
312
- gemname == '' ? '' : " from the #{gemname} gem"
313
- ]
314
- end
315
-
316
- apps = Strelka::Discovery.load( path )
317
- Strelka.load_config( self.options.config ) if self.options.config
318
- self.log.debug " loaded: %p" % [ apps ]
319
-
320
- self.load_additional_requires
321
-
322
- apps.first.run
323
- end
324
- help :start, "Start a Strelka app"
325
-
326
-
327
- ### The 'version' command
328
- def version_command( *args )
329
- message( "<%= color 'Version:', :header %> " + Mongrel2.version_string(true) )
330
- end
331
- help :version, "Prints the Ruby-Mongrel2 version."
332
-
333
-
334
- ### The 'config' command
335
- def config_command( *args )
336
- gemname = args.shift
337
- discovery_name = gemname || ''
338
-
339
- header "Dumping config for %s" % [ gemname || 'local apps' ]
340
- discovered_apps = Strelka::Discovery.discover_paths
341
-
342
- raise ArgumentError, "No apps discovered" unless discovered_apps.key?( discovery_name )
343
-
344
- discovered_apps[ discovery_name ].each do |apppath|
345
- message " loading %s (%s)" % [ apppath, apppath.basename('.rb') ]
346
- Strelka::Discovery.load( apppath )
347
- end
348
-
349
- self.load_additional_requires
350
-
351
- message " dumping config:"
352
- $stdout.puts Configurability.default_config.dump
353
- end
354
- help :config, "Dump the configuration for GEMNAME (or the local directory if no gem is specified)"
355
- usage :config, "[GEMNAME]"
356
-
357
-
358
- ### The 'version' command
359
- def version_command( *args )
360
- message( "<%= color 'Version:', :header %> " + Mongrel2.version_string(true) )
361
- end
362
- help :version, "Prints the Ruby-Mongrel2 version."
363
-
364
-
365
- #
366
- # Helper methods
367
- #
368
-
369
- ### Load any requires added to the command via the '-r' option.
370
- def load_additional_requires
371
- return unless self.options.requires
372
-
373
- self.log.debug " loading additional requires: %p" % [ self.options.requires ]
374
- self.options.requires.each do |lib|
375
- require( lib )
376
- end
377
- end
378
-
379
-
380
- #
381
- # Utility methods
382
- #
383
-
384
- ### Output normal output
385
- def message( *parts )
386
- self.prompt.say( parts.map(&:to_s).join($/) )
387
- end
388
-
389
-
390
- ### Output the given +text+ highlighted as a header.
391
- def header( text )
392
- message( self.prompt.color(text, :header) )
393
- end
394
-
395
-
396
- ### Output the given +text+ highlighted as a subheader.
397
- def subheader( text )
398
- message( self.prompt.color(text, :subheader) )
399
- end
400
-
401
-
402
- ### Output the given +text+ highlighted as an error.
403
- def error( text )
404
- message( self.prompt.color(text, :error) )
405
- end
406
-
407
-
408
- ### Output the given +items+ as a columnar list.
409
- def list( *items )
410
- message( self.prompt.list(items.flatten.compact.map(&:to_s), :columns_down) )
411
- end
412
-
413
- end # class Strelka::CLICommand
414
-
415
-
416
- Strelka::CLICommand.run( ARGV.dup )
7
+ Strelka::CLI.run( ARGV.dup )
417
8