lugg 0.0.1 → 0.0.2
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 +4 -4
- data/.rubocop.yml +4 -8
- data/lib/lugg/request.rb +5 -2
- data/lib/lugg/runner.rb +16 -94
- data/lib/lugg/switch.rb +58 -0
- data/lib/lugg/switches.rb +127 -0
- data/lib/lugg/version.rb +1 -1
- data/spec/lugg/runner_spec.rb +6 -6
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abcad075a8a7f632dbf9fd6d144291d3ae4273c9
|
4
|
+
data.tar.gz: 2a24b47421c0b4c40615f1a8ccff3158b64b8897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 685c248a1c3da1cc2798164108a18538062aece46f8edf00d7104e3c07354895ba73249e330aee99547ce87d3b95f0c26ff50aaa6bf85f9e1de08660307e2594
|
7
|
+
data.tar.gz: 83940e320771cb6d5b5c37a430dd5c001f728db52f0d332bef0bbec51cd213ff448065dc47dd6a4599a58c2a16b104f19d38471dff2fcd2a15fecc5f9f1e8abb
|
data/.rubocop.yml
CHANGED
@@ -24,13 +24,9 @@ LineLength:
|
|
24
24
|
AndOr:
|
25
25
|
Enabled: false
|
26
26
|
|
27
|
-
ClassLength:
|
28
|
-
Exclude:
|
29
|
-
- lib/lugg/runner.rb
|
30
|
-
|
31
|
-
MethodLength:
|
32
|
-
Exclude:
|
33
|
-
- lib/lugg/runner.rb
|
34
|
-
|
35
27
|
DoubleNegation:
|
36
28
|
Enabled: false
|
29
|
+
|
30
|
+
TrivialAccessors:
|
31
|
+
Exclude:
|
32
|
+
- lib/lugg/switch.rb
|
data/lib/lugg/request.rb
CHANGED
@@ -74,8 +74,11 @@ module Lugg
|
|
74
74
|
|
75
75
|
def params
|
76
76
|
params_string = source[/^ Parameters: (.+)$/, 1]
|
77
|
-
|
78
|
-
|
77
|
+
String(params_string)
|
78
|
+
.scan(/(?<!\\)"(.+?)(?<!\\)"=>(?<!\\)"(.+?)(?<!\\)"/)
|
79
|
+
.each_with_object({}) do |match, output|
|
80
|
+
output[match[0]] = match[1]
|
81
|
+
end
|
79
82
|
end
|
80
83
|
end
|
81
84
|
end
|
data/lib/lugg/runner.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'lugg/version'
|
2
2
|
require 'lugg/filter'
|
3
3
|
require 'lugg/streamer'
|
4
|
+
require 'lugg/switches'
|
4
5
|
require 'optparse'
|
5
6
|
require 'optparse/time'
|
6
7
|
|
@@ -29,17 +30,6 @@ module Lugg
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
private
|
33
|
-
|
34
|
-
def reset
|
35
|
-
@combine = false
|
36
|
-
@last_block = nil
|
37
|
-
end
|
38
|
-
|
39
|
-
def combine_clauses?
|
40
|
-
@combine && @last_block
|
41
|
-
end
|
42
|
-
|
43
33
|
def add_clause(&block)
|
44
34
|
if combine_clauses?
|
45
35
|
prev_block = @last_block
|
@@ -51,6 +41,12 @@ module Lugg
|
|
51
41
|
end
|
52
42
|
end
|
53
43
|
|
44
|
+
def combine_next
|
45
|
+
@combine = true
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
54
50
|
def options
|
55
51
|
@options ||= OptionParser.new do |o|
|
56
52
|
o.banner = <<-EOS
|
@@ -60,91 +56,17 @@ Parses log entries from FILE or STDIN and uses [options] to control what is
|
|
60
56
|
sent STDOUT.
|
61
57
|
EOS
|
62
58
|
o.separator ''
|
59
|
+
Switch.apply_all(o, self)
|
60
|
+
end
|
61
|
+
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
%w(get post put delete head patch).each do |verb|
|
70
|
-
o.on "--#{verb}", "Limit to #{verb.upcase} requests" do
|
71
|
-
add_clause { |r| r.method == verb.upcase }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
o.on '-c',
|
76
|
-
'--controller CONTROLLER',
|
77
|
-
'Limit to requests handled by CONTROLLER' do |controller|
|
78
|
-
add_clause { |r| r.controller == controller }
|
79
|
-
end
|
80
|
-
|
81
|
-
o.on '-a',
|
82
|
-
'--action CONTROLLER_ACTION',
|
83
|
-
'Limit to requests handled by CONTROLLER_ACTION' do |ca|
|
84
|
-
add_clause { |r| r.action == ca }
|
85
|
-
end
|
86
|
-
|
87
|
-
%w(json html xml csv pdf js).each do |format|
|
88
|
-
o.on "--#{format}", "Limit to #{format} requests" do
|
89
|
-
add_clause { |r| r.format.downcase == format }
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
o.on '-f', '--format FORMAT', 'Limit to FORMAT requests' do |format|
|
94
|
-
add_clause { |r| r.format.downcase == format.downcase }
|
95
|
-
end
|
96
|
-
|
97
|
-
o.on '-s',
|
98
|
-
'--status CODE',
|
99
|
-
'Limit requests with status code CODE' do |code|
|
100
|
-
add_clause { |r| r.code == code }
|
101
|
-
end
|
102
|
-
|
103
|
-
o.on '--since TIME',
|
104
|
-
Time,
|
105
|
-
'Limit to requests made after TIME' do |time|
|
106
|
-
add_clause { |r| r.timestamp > time }
|
107
|
-
end
|
108
|
-
|
109
|
-
o.on '--until TIME',
|
110
|
-
Time,
|
111
|
-
'Limit to requests made before TIME' do |time|
|
112
|
-
add_clause { |r| r.timestamp < time }
|
113
|
-
end
|
114
|
-
|
115
|
-
o.on '-d',
|
116
|
-
'--duration N',
|
117
|
-
Integer,
|
118
|
-
'Limit to requests longer than N ms' do |n|
|
119
|
-
add_clause { |r| r.duration > n }
|
120
|
-
end
|
121
|
-
|
122
|
-
o.on '-u',
|
123
|
-
'--uri URI',
|
124
|
-
Regexp,
|
125
|
-
'Limit to requests matching URI' do |uri|
|
126
|
-
add_clause { |r| r.uri =~ uri }
|
127
|
-
end
|
128
|
-
|
129
|
-
o.on '-p',
|
130
|
-
'--param KEY=VAL',
|
131
|
-
'Limit to requests with param KEY => VAL' do |param|
|
132
|
-
key, value = param.split('=', 2)
|
133
|
-
add_clause { |r| r.params[key] == value }
|
134
|
-
end
|
135
|
-
|
136
|
-
o.separator ''
|
137
|
-
|
138
|
-
o.on_tail '-v', '--version', 'Display version number' do
|
139
|
-
puts Lugg::VERSION
|
140
|
-
exit
|
141
|
-
end
|
63
|
+
def reset
|
64
|
+
@combine = false
|
65
|
+
@last_block = nil
|
66
|
+
end
|
142
67
|
|
143
|
-
|
144
|
-
|
145
|
-
exit
|
146
|
-
end
|
147
|
-
end
|
68
|
+
def combine_clauses?
|
69
|
+
@combine && @last_block
|
148
70
|
end
|
149
71
|
end
|
150
72
|
end
|
data/lib/lugg/switch.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
module Lugg
|
2
|
+
# An object representing a command line swith with certain behaviour. The
|
3
|
+
# Runner applies switches to its own internal `OptionParser` object to build
|
4
|
+
# the CLI and provide querying functionality.
|
5
|
+
#
|
6
|
+
# @see Runner
|
7
|
+
class Switch
|
8
|
+
@queries = []
|
9
|
+
|
10
|
+
# Define a new Switch object and add it to the global collection of
|
11
|
+
# switches.
|
12
|
+
def self.define(*args, &block)
|
13
|
+
@queries << new(*args).tap { |obj| obj.instance_eval(&block) }
|
14
|
+
end
|
15
|
+
|
16
|
+
# Call {#apply} on each {Switch} in the global collection to register the
|
17
|
+
# callback on a given object.
|
18
|
+
def self.apply_all(*args)
|
19
|
+
@queries.each do |query|
|
20
|
+
query.apply_to(*args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(method = :on)
|
25
|
+
@method = method
|
26
|
+
@flags = nil
|
27
|
+
@cast = nil
|
28
|
+
@desc = nil
|
29
|
+
@action = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def apply_to(options, obj)
|
33
|
+
@options = options
|
34
|
+
@obj = obj
|
35
|
+
@options.send(@method, *[@flags, @cast, @desc].flatten.compact, &@action)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def flags(*flags)
|
41
|
+
@flags = flags
|
42
|
+
end
|
43
|
+
|
44
|
+
def cast(obj)
|
45
|
+
@cast = obj
|
46
|
+
end
|
47
|
+
|
48
|
+
def desc(msg)
|
49
|
+
@desc = msg
|
50
|
+
end
|
51
|
+
|
52
|
+
def action(&block)
|
53
|
+
@action = block
|
54
|
+
end
|
55
|
+
|
56
|
+
attr_reader :options, :obj
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'lugg/switch'
|
2
|
+
|
3
|
+
# Collection of available command line argument switches and their behaviour.
|
4
|
+
module Lugg
|
5
|
+
Switch.define do
|
6
|
+
flags '--and'
|
7
|
+
desc 'Combine previous and next clause with AND instead of OR'
|
8
|
+
action do
|
9
|
+
obj.combine_next
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
%w(get post put delete head patch).each do |verb|
|
14
|
+
Switch.define do
|
15
|
+
flags "--#{verb}"
|
16
|
+
desc "Limit to #{verb.upcase} requests"
|
17
|
+
action do
|
18
|
+
obj.add_clause { |r| r.method == verb.upcase }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Switch.define do
|
24
|
+
flags '-c', '--controller CONTROLLER'
|
25
|
+
desc 'Limit to requests handled by CONTROLLER'
|
26
|
+
action do |controller|
|
27
|
+
obj.add_clause { |r| r.controller == controller }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Switch.define do
|
32
|
+
flags '-a', '--action CONTROLLER_ACTION'
|
33
|
+
desc 'Limit to requests handled by CONTROLLER_ACTION'
|
34
|
+
action do |ca|
|
35
|
+
obj.add_clause { |r| r.action == ca }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
%w(json html xml csv pdf js).each do |format|
|
40
|
+
Switch.define do
|
41
|
+
flags "--#{format}"
|
42
|
+
desc "Limit to #{format} requests"
|
43
|
+
action do
|
44
|
+
obj.add_clause { |r| r.format.downcase == format }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Switch.define do
|
50
|
+
flags '-f', '--format FORMAT'
|
51
|
+
desc 'Limit to FORMAT requests'
|
52
|
+
action do |format|
|
53
|
+
obj.add_clause { |r| r.format.downcase == format.downcase }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Switch.define do
|
58
|
+
flags '-s', '--status CODE'
|
59
|
+
desc 'Limit requests with status code CODE'
|
60
|
+
action do |code|
|
61
|
+
obj.add_clause { |r| r.code == code }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
Switch.define do
|
66
|
+
flags '--since TIME'
|
67
|
+
cast Time
|
68
|
+
desc 'Limit to requests made after TIME'
|
69
|
+
action do |time|
|
70
|
+
obj.add_clause { |r| r.timestamp > time }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
Switch.define do
|
75
|
+
flags '--until TIME'
|
76
|
+
cast Time
|
77
|
+
desc 'Limit to requests made before TIME'
|
78
|
+
action do |time|
|
79
|
+
obj.add_clause { |r| r.timestamp < time }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
Switch.define do
|
84
|
+
flags '-d', '--duration N'
|
85
|
+
cast Integer
|
86
|
+
desc 'Limit to requests longer than N ms'
|
87
|
+
action do |n|
|
88
|
+
obj.add_clause { |r| r.duration > n }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
Switch.define do
|
93
|
+
flags '-u', '--uri URI'
|
94
|
+
cast Regexp
|
95
|
+
desc 'Limit to requests matching URI'
|
96
|
+
action do |uri|
|
97
|
+
obj.add_clause { |r| r.uri =~ uri }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
Switch.define do
|
102
|
+
flags '-p', '--param PAIR'
|
103
|
+
desc 'Limit to requests with param KEY => VAL'
|
104
|
+
action do |param|
|
105
|
+
key, value = param.split('=', 2)
|
106
|
+
obj.add_clause { |r| r.params[key] == value }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
Switch.define :on_tail do
|
111
|
+
flags '-v', '--version'
|
112
|
+
desc 'Display version number'
|
113
|
+
action do
|
114
|
+
puts Lugg::VERSION
|
115
|
+
exit
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
Switch.define :on_tail do
|
120
|
+
flags '-h', '--help'
|
121
|
+
desc 'Display this message'
|
122
|
+
action do
|
123
|
+
puts options
|
124
|
+
exit
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/lugg/version.rb
CHANGED
data/spec/lugg/runner_spec.rb
CHANGED
@@ -32,7 +32,7 @@ module Lugg
|
|
32
32
|
let(:options) { %w(--post --and --controller PostsController) }
|
33
33
|
let(:input) { "Started GET\nProcessing by PostsController#index as HTML\nCompleted 1\nStarted POST\nProcessing by BlogController#create as HTML\nCompleted 2\n" }
|
34
34
|
|
35
|
-
it 'limits
|
35
|
+
it 'limits to post requests in PostsController' do
|
36
36
|
subject.run(StringIO.new(input))
|
37
37
|
expect(stdout.string).to eql("Started POST\nProcessing by BlogController#create as HTML\nCompleted 2\n")
|
38
38
|
end
|
@@ -42,7 +42,7 @@ module Lugg
|
|
42
42
|
let(:options) { %w(--controller PostsController) }
|
43
43
|
let(:input) { "Started GET\nProcessing by PostsController#index as HTML\nCompleted 1\nStarted POST\nProcessing by BlogController#create as HTML\nCompleted 2\n" }
|
44
44
|
|
45
|
-
it 'limits
|
45
|
+
it 'limits to just PostController' do
|
46
46
|
subject.run(StringIO.new(input))
|
47
47
|
expect(stdout.string).to eql("Started GET\nProcessing by PostsController#index as HTML\nCompleted 1\n")
|
48
48
|
end
|
@@ -52,17 +52,17 @@ module Lugg
|
|
52
52
|
let(:options) { %w(--since 2012-03-20) }
|
53
53
|
let(:input) { "Started GET at 2012-03-21 12:00 +0100\nCompleted 1\nStarted GET at 2012-03-19\nProcessing by BlogController#create as HTML\nCompleted 2\n" }
|
54
54
|
|
55
|
-
it 'limits
|
55
|
+
it 'limits to after the date' do
|
56
56
|
subject.run(StringIO.new(input))
|
57
57
|
expect(stdout.string).to eql("Started GET at 2012-03-21 12:00 +0100\nCompleted 1\n")
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context 'with --param foo=
|
62
|
-
let(:options) {
|
61
|
+
context 'with --param foo=val' do
|
62
|
+
let(:options) { %w(--param foo=val) }
|
63
63
|
let(:input) { "Started GET\n Parameters: {\"foo\"=>\"val\"}\nCompleted 1\nStarted POST\nProcessing by BlogController#create as HTML\nCompleted 2\n" }
|
64
64
|
|
65
|
-
it 'limits requests
|
65
|
+
it 'limits to requests with given param' do
|
66
66
|
subject.run(StringIO.new(input))
|
67
67
|
expect(stdout.string).to eql("Started GET\n Parameters: {\"foo\"=>\"val\"}\nCompleted 1\n")
|
68
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lugg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arjan van der Gaag
|
@@ -107,6 +107,8 @@ files:
|
|
107
107
|
- lib/lugg/request_matcher.rb
|
108
108
|
- lib/lugg/runner.rb
|
109
109
|
- lib/lugg/streamer.rb
|
110
|
+
- lib/lugg/switch.rb
|
111
|
+
- lib/lugg/switches.rb
|
110
112
|
- lib/lugg/version.rb
|
111
113
|
- lugg.gemspec
|
112
114
|
- spec/fixtures/example.log
|