kronk 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,13 +1,41 @@
1
+ === 1.3.0 / 2011-06
2
+
3
+ * Major Enhancements:
4
+
5
+ * Added auto-querying functionality with param randomizing.
6
+
7
+ * Added test helper methods, assertions, and core extensions.
8
+
9
+ * Enhancements:
10
+
11
+ * Updated dependencies json ~>1.5, nokogiri ~>1.4, i18n >=0.5
12
+
13
+ * Reimplemented the diff logic to a LCS algorithm.
14
+
15
+ * Added support for ranges and 'index,length' pairs to DataSet path parsing.
16
+
17
+ * Moved kronk config files to the ~/.kronk folder.
18
+
19
+ * Made path matching case-insensitive.
20
+
21
+ * Deprecated and moved cmd functionality into Kronk::Cmd class.
22
+
23
+ * Bugfixes:
24
+
25
+ * Fix for path lookup of parents when parent is the root data object.
26
+
27
+ * Handling of reset connection errors.
28
+
1
29
  === 1.2.5 / 2011-03-09
2
30
 
3
31
  * Bugfixes:
4
32
 
5
33
  * Small fix to the diff functionality.
6
- Swapping left and right would not always yeild the same behavior.
34
+ Swapping left and right would not always yield the same behavior.
7
35
 
8
36
  === 1.2.4 / 2011-03-04
9
37
 
10
- * Enhancements:
38
+ * Bugfixes:
11
39
 
12
40
  * Cleaner exit on sigint.
13
41
 
@@ -4,13 +4,24 @@ Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  bin/kronk
7
+ bin/yzma
7
8
  lib/kronk.rb
9
+ lib/kronk/cmd.rb
8
10
  lib/kronk/data_set.rb
9
11
  lib/kronk/diff.rb
12
+ lib/kronk/diff/ascii_format.rb
13
+ lib/kronk/diff/color_format.rb
10
14
  lib/kronk/plist_parser.rb
11
15
  lib/kronk/request.rb
12
16
  lib/kronk/response.rb
17
+ lib/kronk/test.rb
18
+ lib/kronk/test/assertions.rb
19
+ lib/kronk/test/core_ext.rb
20
+ lib/kronk/test/helper_methods.rb
13
21
  lib/kronk/xml_parser.rb
22
+ lib/yzma.rb
23
+ lib/yzma/randomizer.rb
24
+ lib/yzma/report.rb
14
25
  script/kronk_completion
15
26
  test/mocks/200_response.json
16
27
  test/mocks/200_response.plist
@@ -18,6 +29,9 @@ test/mocks/200_response.txt
18
29
  test/mocks/200_response.xml
19
30
  test/mocks/301_response.txt
20
31
  test/mocks/302_response.txt
32
+ test/test_assertions.rb
33
+ test/test_core_ext.rb
34
+ test/test_helper_methods.rb
21
35
  test/test_data_set.rb
22
36
  test/test_diff.rb
23
37
  test/test_helper.rb
@@ -11,8 +11,6 @@ Kronk was made possible by the sponsoring of AT&T Interactive.
11
11
 
12
12
  * Parse and display or diff data from http response body and/or headers.
13
13
 
14
- * Follow redirects automatically.
15
-
16
14
  * Include or exclude specific data points with file-glob-like paths.
17
15
 
18
16
  * Supports json, rails-ish xml, and plist.
@@ -27,13 +25,13 @@ Kronk was made possible by the sponsoring of AT&T Interactive.
27
25
 
28
26
  * Easy-to-read output (color or ascii, line numbers, etc).
29
27
 
30
- * Yes, it works on Windows.
28
+ * URI-specific configuration.
31
29
 
32
- == FUTURE:
30
+ * Helper methods for test suites.
33
31
 
34
- * Auto-queryer with optional param randomizing.
32
+ * Auto-query reports with request randomization support.
35
33
 
36
- * Support for test suites.
34
+ * Yes, it works on Windows.
37
35
 
38
36
  == SYNOPSIS:
39
37
 
@@ -246,7 +244,7 @@ single quotes around some of your paths.
246
244
 
247
245
  == INSTALL:
248
246
 
249
- $ sudo gem install kronk
247
+ $ gem install kronk
250
248
 
251
249
  == DEVELOPERS:
252
250
 
data/Rakefile CHANGED
@@ -3,7 +3,18 @@
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
- Hoe.plugin :isolate
6
+
7
+ if ENV['version']
8
+ gem 'kronk', ENV['version']
9
+ else
10
+ $: << "lib"
11
+ Hoe.plugin :isolate
12
+ end
13
+
14
+ require 'kronk'
15
+
16
+ puts "kronk-#{Kronk::VERSION}"
17
+
7
18
 
8
19
  Hoe.spec 'kronk' do
9
20
  developer('Jeremie Castagna', 'yaksnrainbows@gmail.com')
@@ -12,9 +23,9 @@ Hoe.spec 'kronk' do
12
23
  self.extra_rdoc_files = FileList['*.rdoc']
13
24
 
14
25
  self.extra_deps << ['plist', '~>3.1.0']
15
- self.extra_deps << ['json', '~>1.2']
16
- self.extra_deps << ['nokogiri', '~>1.3']
17
- self.extra_deps << ['i18n', '~>0.5']
26
+ self.extra_deps << ['json', '~>1.5']
27
+ self.extra_deps << ['nokogiri', '~>1.4']
28
+ self.extra_deps << ['i18n', '>=0.5']
18
29
  self.extra_deps << ['activesupport', '>=2.0.0']
19
30
  self.extra_deps << ['cookiejar', '~>0.3.0']
20
31
  self.extra_deps << ['rack', '~>1.0']
@@ -22,4 +33,77 @@ Hoe.spec 'kronk' do
22
33
  self.extra_dev_deps << ['mocha', '~>0.9.10']
23
34
  end
24
35
 
36
+
37
+ class Object
38
+
39
+ BENCHMARKS = {}
40
+
41
+ def bm name=nil
42
+ start = Time.now
43
+ yield
44
+ span = Time.now - start
45
+
46
+ if BENCHMARKS[name]
47
+ t = BENCHMARKS[name][:time]
48
+ w = BENCHMARKS[name][:weight]
49
+
50
+ t = t + span
51
+ w += 1
52
+
53
+ BENCHMARKS[name] = {:time => t, :weight => w}
54
+ else
55
+ BENCHMARKS[name] = {:time => span, :weight => 1}
56
+ end
57
+ end
58
+ end
59
+
60
+
61
+ def benchmark num=1000
62
+ start = Time.now
63
+
64
+ num.times do
65
+ yield
66
+ end
67
+
68
+ puts "Ran #{num} times: #{(Time.now - start).to_f / num}"
69
+ end
70
+
71
+
72
+ namespace :bm do
73
+
74
+ desc "Run performance benchmarks on diff and parsing"
75
+ task :full do
76
+
77
+ benchmark(100) do
78
+ Kronk.compare("prod.txt", "beta.txt").count
79
+ end
80
+ end
81
+
82
+
83
+ desc "Run performance benchmarks on diffs"
84
+ task :diff do
85
+ left = Kronk::Request.retrieve("prod.txt").parsed_body
86
+ right = Kronk::Request.retrieve("beta.txt").parsed_body
87
+
88
+ diff = Kronk::Diff.new_from_data left, right
89
+
90
+ arr1 = diff.str1.split "\n"
91
+ arr2 = diff.str2.split "\n"
92
+
93
+ benchmark(100) do
94
+ #arr1.each{|i| 0.upto(5){|j| foo = j+123}}
95
+ #arr2.each{|i| foo = 'foobar'}
96
+ #arr2.each{|i| i == 'foobar'}
97
+ diff.create_diff
98
+ #diff.common_sequences arr1, arr2
99
+ #diff.find_common arr1, arr2
100
+ #`diff prod.txt beta.txt`
101
+ end
102
+
103
+ Object::BENCHMARKS.each do |name, bm|
104
+ puts "#{name} (#{bm[:weight]/100}): #{bm[:time] / 100}"
105
+ end rescue nil
106
+ end
107
+ end
108
+
25
109
  # vim: syntax=ruby
data/bin/kronk CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $: << File.join(File.dirname(__FILE__), "../lib")
3
4
  begin
4
5
  require 'kronk'
5
6
 
@@ -10,4 +11,4 @@ rescue LoadError => e
10
11
  require 'kronk'
11
12
  end
12
13
 
13
- Kronk.run
14
+ Kronk::Cmd.run
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'yzma'
5
+
6
+ rescue LoadError => e
7
+ raise unless e.message =~ %r{no such file to load -- yzma}
8
+
9
+ $: << File.join(File.dirname(__FILE__), "../lib")
10
+ require 'yzma'
11
+ end
12
+
13
+ Yzma.run
@@ -11,18 +11,13 @@ require 'yaml'
11
11
  class Kronk
12
12
 
13
13
  # This gem's version.
14
- VERSION = '1.2.5'
15
-
16
-
17
- ##
18
- # Returns true if kronk is running on ruby for windows.
19
-
20
- def self.windows?
21
- !!(RUBY_PLATFORM.downcase =~ /mswin|mingw|cygwin/)
22
- end
14
+ VERSION = '1.3.0'
23
15
 
24
16
 
17
+ require 'kronk/cmd'
25
18
  require 'kronk/data_set'
19
+ require 'kronk/diff/ascii_format'
20
+ require 'kronk/diff/color_format'
26
21
  require 'kronk/diff'
27
22
  require 'kronk/response'
28
23
  require 'kronk/request'
@@ -30,20 +25,20 @@ class Kronk
30
25
  require 'kronk/xml_parser'
31
26
 
32
27
 
33
- # Default config file to load. Defaults to ~/.kronk.
34
- DEFAULT_CONFIG_FILE = File.expand_path "~/.kronk"
28
+ # Config directory.
29
+ CONFIG_DIR = File.expand_path "~/.kronk"
35
30
 
31
+ # Default config file to load. Defaults to ~/.kronk.
32
+ DEFAULT_CONFIG_FILE = File.join CONFIG_DIR, "rc"
36
33
 
37
34
  # Default cache file.
38
- DEFAULT_CACHE_FILE = File.expand_path "~/.kronk_cache"
39
-
35
+ DEFAULT_CACHE_FILE = File.join CONFIG_DIR, "cache"
40
36
 
41
37
  # Default cookies file.
42
- DEFAULT_COOKIES_FILE = File.expand_path "~/.kronk_cookies"
43
-
38
+ DEFAULT_COOKIES_FILE = File.join CONFIG_DIR, "cookies"
44
39
 
45
40
  # Default file with history of unique URIs. (Used for autocomplete)
46
- DEFAULT_HISTORY_FILE = File.expand_path "~/.kronk_history"
41
+ DEFAULT_HISTORY_FILE = File.join CONFIG_DIR, "history"
47
42
 
48
43
 
49
44
  # Default Content-Type header to parser mapping.
@@ -141,42 +136,12 @@ class Kronk
141
136
  ##
142
137
  # Creates the default config file at the given path.
143
138
 
144
- def self.make_config_file filepath=DEFAULT_CONFIG_FILE
145
- File.open filepath, "w+" do |file|
146
- file << DEFAULT_CONFIG.to_yaml
147
- end
148
- end
149
-
150
-
151
- ##
152
- # Find a fully qualified ruby namespace/constant.
139
+ def self.make_config_file
140
+ Dir.mkdir CONFIG_DIR unless File.directory? CONFIG_DIR
153
141
 
154
- def self.find_const namespace
155
- consts = namespace.to_s.split "::"
156
- curr = self
157
-
158
- until consts.empty? do
159
- curr = curr.const_get consts.shift
142
+ File.open DEFAULT_CONFIG_FILE, "w+" do |file|
143
+ file << DEFAULT_CONFIG.to_yaml
160
144
  end
161
-
162
- curr
163
- end
164
-
165
-
166
- ##
167
- # Returns the config-defined parser class for a given content type.
168
-
169
- def self.parser_for content_type
170
- parser_pair =
171
- config[:content_types].select do |key, value|
172
- (content_type =~ %r{#{key}([^\w]|$)}) && value
173
- end.to_a
174
-
175
- return if parser_pair.empty?
176
-
177
- parser = parser_pair[0][1]
178
- parser = find_const parser if String === parser || Symbol === parser
179
- parser
180
145
  end
181
146
 
182
147
 
@@ -186,14 +151,14 @@ class Kronk
186
151
  # Returns cmd_opts Hash if none found.
187
152
 
188
153
  def self.merge_options_for_uri uri, cmd_opts={}
189
- return cmd_opts if config[:no_uri_options]
154
+ return cmd_opts if Kronk.config[:no_uri_options]
190
155
 
191
156
  out_opts = Hash.new.merge cmd_opts
192
157
 
193
- config[:uri_options].each do |matcher, options|
194
- next unless (uri == matcher || uri =~ %r{#{matcher}}) && Hash === options
158
+ Kronk.config[:uri_options].each do |matcher, opts|
159
+ next unless (uri == matcher || uri =~ %r{#{matcher}}) && Hash === opts
195
160
 
196
- options.each do |key, val|
161
+ opts.each do |key, val|
197
162
  if !out_opts[key]
198
163
  out_opts[key] = val
199
164
  next
@@ -245,39 +210,34 @@ class Kronk
245
210
 
246
211
 
247
212
  ##
248
- # Ask the user for a password from stdinthe command line.
249
-
250
- def self.query_password str=nil
251
- $stderr << "#{(str || "Password:")} "
252
- system "stty -echo"
253
- password = $stdin.gets.chomp
254
- ensure
255
- system "stty echo"
256
- $stderr << "\n"
257
- password
258
- end
213
+ # Find a fully qualified ruby namespace/constant.
259
214
 
215
+ def self.find_const namespace
216
+ consts = namespace.to_s.split "::"
217
+ curr = self
260
218
 
261
- ##
262
- # Load the saved cookies file.
219
+ until consts.empty? do
220
+ curr = curr.const_get consts.shift
221
+ end
263
222
 
264
- def self.load_cookie_jar file=nil
265
- file ||= config[:cookies_file]
266
- @cookie_jar = YAML.load_file file if File.file? file
267
- @cookie_jar ||= CookieJar::Jar.new
268
- @cookie_jar.expire_cookies
269
- @cookie_jar
223
+ curr
270
224
  end
271
225
 
272
226
 
273
227
  ##
274
- # Save the cookie jar to file.
228
+ # Returns the config-defined parser class for a given content type.
275
229
 
276
- def self.save_cookie_jar file=nil
277
- file ||= config[:cookies_file]
278
- File.open(file, "w") do |f|
279
- f.write @cookie_jar.to_yaml
280
- end
230
+ def self.parser_for content_type
231
+ parser_pair =
232
+ config[:content_types].select do |key, value|
233
+ (content_type =~ %r{#{key}([^\w]|$)}) && value
234
+ end.to_a
235
+
236
+ return if parser_pair.empty?
237
+
238
+ parser = parser_pair[0][1]
239
+ parser = find_const parser if String === parser || Symbol === parser
240
+ parser
281
241
  end
282
242
 
283
243
 
@@ -298,6 +258,29 @@ class Kronk
298
258
  end
299
259
 
300
260
 
261
+ ##
262
+ # Load the saved cookies file.
263
+
264
+ def self.load_cookie_jar file=nil
265
+ file ||= config[:cookies_file]
266
+ @cookie_jar = YAML.load_file file if File.file? file
267
+ @cookie_jar ||= CookieJar::Jar.new
268
+ @cookie_jar.expire_cookies
269
+ @cookie_jar
270
+ end
271
+
272
+
273
+ ##
274
+ # Save the cookie jar to file.
275
+
276
+ def self.save_cookie_jar file=nil
277
+ file ||= config[:cookies_file]
278
+ File.open(file, "w") do |f|
279
+ f.write @cookie_jar.to_yaml
280
+ end
281
+ end
282
+
283
+
301
284
  ##
302
285
  # Returns the Kronk history array of accessed URLs.
303
286
 
@@ -313,8 +296,10 @@ class Kronk
313
296
  # Writes the URL history to the history file.
314
297
 
315
298
  def self.save_history
299
+ history_str = self.history.uniq.join($/)
300
+
316
301
  File.open self.config[:history_file], "w" do |file|
317
- file.write self.history.uniq.join($/)
302
+ file.write history_str
318
303
  end
319
304
  end
320
305
 
@@ -372,397 +357,94 @@ class Kronk
372
357
  Diff.ordered_data_string data, options[:struct]
373
358
 
374
359
  rescue Response::MissingParser
375
- verbose "Warning: No parser for #{resp['Content-Type']} [#{uri}]"
360
+ Cmd.warn "No parser for #{resp['Content-Type']} [#{uri}]"
376
361
  resp.selective_string options
377
362
  end
378
363
  end
379
364
  end
380
365
 
381
366
 
367
+ ###
368
+ # Deprecated methods...
369
+ ###
382
370
 
383
- ##
384
- # Start an IRB console with the given http response object.
385
-
386
- def self.irb resp
387
- require 'irb'
388
-
389
- $http_response = resp
390
- $response = begin
391
- resp.parsed_body
392
- rescue Response::MissingParser
393
- resp.body
394
- end
395
371
 
396
- puts "\nHTTP Response is in $http_response"
397
- puts "Response data is in $response\n\n"
372
+ def self.deprecated method_name, replacement=nil
373
+ replacement &&= ", use #{replacement}"
374
+ replacement ||= " with no replacement"
398
375
 
399
- IRB.start
400
- exit 1
376
+ Cmd.warn "#{method_name} deprecated#{replacement}"
401
377
  end
402
378
 
403
379
 
404
380
  ##
405
- # Runs the kronk command with the given terminal args.
406
-
407
- def self.run argv=ARGV
408
- begin
409
- load_config
410
-
411
- rescue Errno::ENOENT
412
- make_config_file
413
-
414
- $stderr << "\nNo config file was found.\n\n"
415
- $stderr << "Created default config in #{DEFAULT_CONFIG_FILE}\n"
416
- $stderr << "Edit file if necessary and try again.\n"
417
- exit 2
418
- end
419
-
420
- load_cookie_jar
381
+ # Deprecated! Use Kronk::Cmd::irb
421
382
 
422
- options = parse_args argv
423
-
424
- load_requires options[:requires]
425
-
426
- at_exit do
427
- save_cookie_jar
428
- save_history
429
- end
430
-
431
- trap 'INT' do
432
- exit 2
433
- end
434
-
435
-
436
- options[:cache_response] = config[:cache_file] if config[:cache_file]
437
-
438
- uri1, uri2 = options.delete :uris
439
-
440
- if uri1 && uri2
441
- diff = compare uri1, uri2, options
442
- puts "#{diff.formatted}\n" unless config[:brief]
443
-
444
- if config[:verbose] || config[:brief]
445
- $stdout << "Found #{diff.count} diff(s).\n"
446
- end
383
+ def self.irb resp
384
+ deprecated "Kronk::irb", "Kronk::Cmd::irb"
385
+ Cmd.irb resp
386
+ end
447
387
 
448
- exit 1 if diff.count > 0
449
388
 
450
- else
451
- out = retrieve_data_string uri1, options
452
- out = Diff.insert_line_nums out if config[:show_lines]
453
- puts out
454
- end
389
+ ##
390
+ # Deprecated! Use Kronk::Cmd::move_config_file
455
391
 
456
- rescue Request::Exception, Response::MissingParser => e
457
- $stderr << "\nError: #{e.message}\n"
458
- exit 2
392
+ def self.move_config_file
393
+ deprecated "Kronk::move_config_file", "Kronk::Cmd::move_config_file"
394
+ Cmd.move_config_file
459
395
  end
460
396
 
461
397
 
462
398
  ##
463
- # Print string only if verbose
399
+ # Deprecated! Use Kronk::Cmd::query_password
464
400
 
465
- def self.verbose str
466
- $stdout << "#{str}\n" if config[:verbose]
401
+ def self.query_password str=nil
402
+ deprecated "Kronk::query_password", "Kronk::Cmd::query_password"
403
+ Cmd.query_password str
467
404
  end
468
405
 
469
406
 
470
407
  ##
471
- # Parse ARGV
408
+ # Deprecated! Use Kronk::Cmd::parse_args
472
409
 
473
410
  def self.parse_args argv
474
- options = {
475
- :auth => {},
476
- :no_body => false,
477
- :proxy => {},
478
- :uris => [],
479
- :with_headers => false
480
- }
481
-
482
- options = parse_data_path_args options, argv
483
-
484
- opts = OptionParser.new do |opt|
485
- opt.program_name = File.basename $0
486
- opt.version = VERSION
487
- opt.release = nil
488
-
489
- opt.banner = <<-STR
490
-
491
- #{opt.program_name} #{opt.version}
492
-
493
- Parse and run diffs against data from live and cached http responses.
494
-
495
- Usage:
496
- #{opt.program_name} --help
497
- #{opt.program_name} --version
498
- #{opt.program_name} uri1 [uri2] [options...] [-- data-paths]
499
-
500
- Examples:
501
- #{opt.program_name} http://example.com/A
502
- #{opt.program_name} http://example.com/B --prev --raw
503
- #{opt.program_name} http://example.com/B.xml local/file/B.json
504
- #{opt.program_name} file1.json file2.json -- **/key1=val1 -root/key?
505
-
506
- Arguments after -- will be used to focus the diff on specific data points.
507
- If the data paths start with a '-' the matched data points will be removed.
508
- If the data paths start with a ":" the parent of the matched data is used.
509
- The ':' and '-' modifiers may be used together in that order (':-').
510
-
511
- Options:
512
- STR
513
-
514
- opt.on('--ascii', 'Return ascii formatted diff') do
515
- config[:diff_format] = :ascii_diff
516
- end
517
-
518
-
519
- opt.on('--color', 'Return color formatted diff') do
520
- config[:diff_format] = :color_diff
521
- end
522
-
523
-
524
- opt.on('--completion', 'Print bash completion file path and exit') do
525
- file = File.join(File.dirname(__FILE__), "../script/kronk_completion")
526
- puts File.expand_path(file)
527
- exit 2
528
- end
529
-
530
-
531
- opt.on('--config STR', String,
532
- 'Load the given Kronk config file') do |value|
533
- load_config value
534
- end
535
-
536
-
537
- opt.on('-q', '--brief', 'Output only whether URI responses differ') do
538
- config[:brief] = true
539
- end
540
-
541
-
542
- opt.on('--format STR', String,
543
- 'Use a custom diff formatter') do |value|
544
- config[:diff_format] = value
545
- end
546
-
547
-
548
- opt.on('-i', '--include [header1,header2]', Array,
549
- 'Include all or given headers in response') do |value|
550
- options[:with_headers] ||= []
551
-
552
- if value
553
- options[:with_headers].concat value if
554
- Array === options[:with_headers]
555
- else
556
- options[:with_headers] = true
557
- end
558
- end
559
-
560
-
561
- opt.on('-I', '--head [header1,header2]', Array,
562
- 'Use all or given headers only in the response') do |value|
563
- options[:with_headers] ||= []
564
-
565
- if value
566
- options[:with_headers].concat value if
567
- Array === options[:with_headers]
568
- else
569
- options[:with_headers] = true
570
- end
571
-
572
- options[:no_body] = true
573
- end
574
-
575
-
576
- opt.on('--irb', 'Start an IRB console') do
577
- options[:irb] = true
578
- end
579
-
580
-
581
- opt.on('--lines', 'Show line numbers') do
582
- config[:show_lines] = true
583
- end
584
-
585
-
586
- opt.on('--no-opts', 'Turn off config URI options') do
587
- config[:no_uri_options] = true
588
- end
589
-
590
-
591
- opt.on('--parser STR', String,
592
- 'Override default parser') do |value|
593
- options[:parser] = value
594
- end
595
-
596
-
597
- opt.on('--prev', 'Use last response to diff against') do
598
- options[:uris].unshift :cache
599
- end
600
-
601
-
602
- opt.on('--raw', 'Run diff on the raw data returned') do
603
- options[:raw] = true
604
- end
605
-
606
-
607
- opt.on('-r', '--require lib1,lib2', Array,
608
- 'Require a library or gem') do |value|
609
- options[:requires] ||= []
610
- options[:requires].concat value
611
- end
612
-
613
-
614
- opt.on('--struct', 'Run diff on the data structure') do
615
- options[:struct] = true
616
- end
617
-
618
-
619
- opt.on('-V', '--verbose', 'Make the operation more talkative') do
620
- config[:verbose] = true
621
- end
622
-
623
-
624
- opt.separator <<-STR
625
-
626
- HTTP Options:
627
- STR
628
-
629
- opt.on('--clear-cookies', 'Delete all saved cookies') do
630
- clear_cookies!
631
- end
632
-
633
-
634
- opt.on('-d', '--data STR', String,
635
- 'Post data with the request') do |value|
636
- options[:data] = value
637
- options[:http_method] ||= 'POST'
638
- end
639
-
640
-
641
- opt.on('-H', '--header STR', String,
642
- 'Header to pass to the server request') do |value|
643
- options[:headers] ||= {}
644
-
645
- key, value = value.split ": ", 2
646
- options[:headers][key] = value.strip
647
- end
648
-
649
-
650
- opt.on('-A', '--user-agent STR', String,
651
- 'User-Agent to send to server or a valid alias') do |value|
652
- options[:user_agent] = value
653
- end
654
-
655
-
656
- opt.on('-L', '--location [NUM]', Integer,
657
- 'Follow the location header always or num times') do |value|
658
- options[:follow_redirects] = value || true
659
- end
660
-
661
-
662
- opt.on('--no-cookies', 'Don\'t use cookies for this session') do
663
- options[:no_cookies] = true
664
- end
665
-
666
-
667
- opt.on('-?', '--query STR', String,
668
- 'Append query to URLs') do |value|
669
- options[:query] = value
670
- end
671
-
672
-
673
- opt.on('--suff STR', String,
674
- 'Add common path items to the end of each URL') do |value|
675
- options[:uri_suffix] = value
676
- end
677
-
678
-
679
- opt.on('--timeout INT', Integer,
680
- 'Timeout for http connection in seconds') do |value|
681
- config[:timeout] = value
682
- end
683
-
684
-
685
- opt.on('-U', '--proxy-user STR', String,
686
- 'Set proxy user and/or password: usr[:pass]') do |value|
687
- options[:proxy][:username], options[:proxy][:password] =
688
- value.split ":", 2
689
-
690
- options[:proxy][:password] ||= query_password "Proxy password:"
691
- end
692
-
693
-
694
- opt.on('-u', '--user STR', String,
695
- 'Set server auth user and/or password: usr[:pass]') do |value|
696
- options[:auth][:username], options[:auth][:password] =
697
- value.split ":", 2
698
-
699
- options[:auth][:password] ||= query_password "Server password:"
700
- end
701
-
702
-
703
- opt.on('-X', '--request STR', String,
704
- 'The request method to use') do |value|
705
- options[:http_method] = value
706
- end
707
-
708
-
709
- opt.on('-x', '--proxy STR', String,
710
- 'Use HTTP proxy on given port: host[:port]') do |value|
711
- options[:proxy][:address], options[:proxy][:port] = value.split ":", 2
712
- end
713
-
714
- opt.separator nil
715
- end
716
-
717
- opts.parse! argv
718
-
719
- unless $stdin.tty?
720
- io = StringIO.new $stdin.read
721
- options[:uris] << io
722
- end
723
-
724
- options[:uris].concat argv
725
- options[:uris].slice!(2..-1)
726
-
727
- argv.clear
411
+ deprecated "Kronk::parse_args", "Kronk::Cmd::parse_args"
412
+ Cmd.parse_args argv
413
+ end
728
414
 
729
- raise OptionParser::MissingArgument, "You must enter at least one URI" if
730
- options[:uris].empty?
731
415
 
732
- options
416
+ ##
417
+ # Deprecated! Use Kronk::Cmd::parse_data_path_args
733
418
 
734
- rescue => e
735
- $stderr << "\nError: #{e.message}\n"
736
- $stderr << "See 'kronk --help' for usage\n\n"
737
- exit 1
419
+ def self.parse_data_path_args options, argv
420
+ deprecated "Kronk::parse_data_path_args", "Kronk::Cmd::parse_data_path_args"
421
+ Cmd.parse_data_path_args options, argv
738
422
  end
739
423
 
740
424
 
741
425
  ##
742
- # Searches ARGV and returns data paths to add or exclude in the diff.
743
- # Returns the array [only_paths, except_paths]
426
+ # Deprecated! Use Kronk::Cmd::run
744
427
 
745
- def self.parse_data_path_args options, argv
746
- return options unless argv.include? "--"
428
+ def self.run argv=ARGV
429
+ deprecated "Kronk::run", "Kronk::Cmd::run"
430
+ Cmd.run argv
431
+ end
747
432
 
748
- data_paths = argv.slice! argv.index("--")..-1
749
- data_paths.shift
750
433
 
751
- data_paths.each do |path|
752
- if path[0,1] == "-"
753
- (options[:ignore_data] ||= []) << path[1..-1]
434
+ ##
435
+ # Deprecated! Use Kronk::Cmd::verbose
754
436
 
755
- elsif path[0,2] == ":-"
756
- (options[:ignore_data_with] ||= []) << path[2..-1]
437
+ def self.verbose str
438
+ deprecated "Kronk::verbose", "Kronk::Cmd::verbose"
439
+ Cmd.verbose str
440
+ end
757
441
 
758
- elsif path[0,1] == ":"
759
- (options[:only_data_with] ||= []) << path[1..-1]
760
442
 
761
- else
762
- (options[:only_data] ||= []) << path
763
- end
764
- end
443
+ ##
444
+ # Deprecated! Use Kronk::Cmd::windows?
765
445
 
766
- options
446
+ def self.windows?
447
+ deprecated "Kronk::windows?", "Kronk::Cmd::windows?"
448
+ Cmd.windows?
767
449
  end
768
450
  end