fluent-format 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 495a2bd0d34f9a30ff0ac8be3700d5e361cf6150
4
- data.tar.gz: 01554a964c734cedf4f7c2cfb0e915e3c608a158
3
+ metadata.gz: 3c146d76922041322724ecc30226d50f82a10233
4
+ data.tar.gz: b9f8974f98d0c56705ae57a0d936d6f470a49f28
5
5
  SHA512:
6
- metadata.gz: 2e5e950a92c5fb60dd20e86cebe99946c0b6410f1e7c20a55100a54fa0ac6923237b67bccd155d6859e48e59d0a5f9e5f2ef350da16325f2fa28bb3d467e27e1
7
- data.tar.gz: 36673c63cfd92f6e12c3aebc294b64132e37bed1c59780266066ea529ff29f827e75e7c2e122a7e5be3e828c997a9f8a6fef16cc6119d51ad1e7e58d1f35488a
6
+ metadata.gz: b969c2059241258ce3c03a5c043805d3696726c0c1a2ff2b0cfa6409dda770649f65760bc07ae468943831609060c57f97fed9cae2d25c10550832df5b0c6fba
7
+ data.tar.gz: 1f09c86414d97aac4186616cf677c4d05b68652eca921ea2da12ea99e735040ea02b51c5459fd3d568ddfc150a543de134d5f3fe2f42d0c9cab13da21903bf96
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.3 (2014/04/10)
2
+
3
+ Enhancement:
4
+
5
+ * Add `require` option to fluent-format check
6
+
1
7
  ## 0.2.2 (2014/02/08)
2
8
 
3
9
  Enhancement:
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # fluent-format [![Build Status](https://secure.travis-ci.org/sonots/fluent-format.png?branch=master)](http://travis-ci.org/sonots/fluent-format)
1
+ # fluent-format [![Build Status](https://travis-ci.org/sonots/fluent-format.png?branch=master)](https://travis-ci.org/sonots/fluent-format)
2
2
 
3
- A command line utility to format fluentd configuration beautifully
3
+ An utility to format or check fluentd configuration
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,26 +18,87 @@ Or install it yourself as:
18
18
 
19
19
  ## Command Line Interface
20
20
 
21
- Format fluent.conf
21
+ ### Format
22
22
 
23
+ $ fluent-format format -c fluent.conf
24
+ or
23
25
  $ fluent-format -c fluent.conf
24
26
 
25
- Check fluent.conf
27
+ Input Example:
28
+
29
+ ```
30
+ <source>
31
+ type forward
32
+ </source>
33
+
34
+ <match test>
35
+ type stdout
36
+ </match>
37
+ ```
38
+
39
+ Output Example:
40
+
41
+ ```
42
+ <source>
43
+ type forward
44
+ </source>
45
+ <match test>
46
+ type stdout
47
+ </match>
48
+ ```
49
+
50
+ ### Check
26
51
 
27
52
  $ fluent-format check -c fluent.conf -p plugin_dir
28
- $ echo $? # 0: success 1: failure
53
+ $ echo $? # 0 or 1
54
+
55
+ This returns the status code 0 if check passed,
56
+ and status code 1 with error messages if check failed.
29
57
 
30
58
  ## As a library
31
59
 
60
+ ### Format
61
+
62
+ ```ruby
63
+ require 'fluent-format'
64
+
65
+ File.open(path) {|config|
66
+ puts Fluent::Format.format(config)
67
+ }
68
+ ```
69
+
70
+ or
71
+
72
+ ```ruby
73
+ require 'fluent-format'
74
+
75
+ puts Fluent::Format.format(path)
76
+ ```
77
+
78
+ Use the 2nd way when you want to exapnd `include` directive.
79
+
80
+ ### Check
81
+
32
82
  ```ruby
33
83
  require 'fluent-format'
34
84
 
35
85
  File.open(path) {|config|
36
- puts Fluent::Format.format(config) # formatted string
37
- Fluent::Format.check(config, plugin_dir) #=> Fluent::ConfigParseError or Fluent::ConfigError if failed
86
+ Fluent::Format.check(config, plugin_dir)
87
+ #=> Fluent::ConfigParseError or Fluent::ConfigError if failed
38
88
  }
39
89
  ```
40
90
 
91
+ or
92
+
93
+ ```ruby
94
+ require 'fluent-format'
95
+
96
+ Fluent::Format.check(path, plugin_dir)
97
+ #=> Fluent::ConfigParseError or Fluent::ConfigError if failed
98
+ ```
99
+
100
+ Use the 2nd way when you want to exapnd `include` directive.
101
+
41
102
  ## Contributing
42
103
 
43
104
  1. Fork it
@@ -49,4 +110,3 @@ File.open(path) {|config|
49
110
  ## Licenses
50
111
 
51
112
  See [LICENSE](LICENSE)
52
-
@@ -0,0 +1,5 @@
1
+ include included.conf
2
+
3
+ <source>
4
+ type forward
5
+ </source>
@@ -0,0 +1 @@
1
+ include included_error.conf
@@ -0,0 +1,3 @@
1
+ <match include>
2
+ type stdout
3
+ </match>
@@ -0,0 +1,3 @@
1
+ <match included>
2
+ type unknown
3
+ </match>
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Naotoshi Seo"]
10
10
  s.email = ["sonots@gmail.com"]
11
11
  s.homepage = "https://github.com/sonots/fluent-format"
12
- s.summary = "A command line utility to format fluentd configuration beautifully"
12
+ s.summary = "A utility to format or check fluentd configuration"
13
13
  s.description = s.summary
14
14
  s.licenses = ["MIT"]
15
15
 
@@ -7,7 +7,8 @@ module Fluent
7
7
  #
8
8
  # @param [IO|String] config_dev
9
9
  # @param [String] plugin_dir the plugin directory
10
- def initialize(config_dev, plugin_dir = nil)
10
+ # @param [Array] libs load libraries (to require)
11
+ def initialize(config_dev, plugin_dir = nil, libs = nil)
11
12
  @opts = {
12
13
  :config_path => config_dev, # Fluent::DEFAULT_CONFIG_PATH,
13
14
  :plugin_dirs => [Fluent::DEFAULT_PLUGIN_DIR],
@@ -22,6 +23,7 @@ module Fluent
22
23
  :suppress_repeated_stacktrace => false,
23
24
  }
24
25
  @opts[:plugin_dirs] << plugin_dir if plugin_dir
26
+ @opts[:libs] += libs if libs and !libs.empty?
25
27
  end
26
28
 
27
29
  # Check config file
@@ -17,11 +17,15 @@ module Fluent
17
17
 
18
18
  desc "check", "Check fluent.conf"
19
19
  option :config, :aliases => ["-c"], :type => :string, :default => 'fluent.conf', :desc => 'Fluentd configuration file'
20
- option :plugin, :aliases => ["-p"], :type => :string, :desc => 'Fluentd plugin directory'
20
+ option :plugin, :aliases => ["-p"], :type => :string, :desc => 'Additional Fluentd plugin directory'
21
+ option :require, :aliases => ["-r"], :type => :array, :desc => 'Additional Fluentd lib path'
21
22
  def check
22
23
  config = @options[:config]
23
24
  plugin = @options[:plugin]
24
- Fluent::Format.check(config, plugin)
25
+ require 'pry'
26
+ binding.pry
27
+ libs = @options[:require]
28
+ Fluent::Format.check(config, plugin, libs)
25
29
  rescue => e
26
30
  $stderr.puts "#{e.class} #{e.message} #{e.backtrace.first}"
27
31
  exit 1
@@ -1,5 +1,5 @@
1
1
  module Fluent
2
2
  class Format
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
data/lib/fluent/format.rb CHANGED
@@ -14,9 +14,10 @@ module Fluent
14
14
  #
15
15
  # @param [IO|String] config_dev
16
16
  # @param [String] plugin_dir the plugin directory
17
+ # @param [Array] libs load libraries (to require)
17
18
  # @return [Boolean]
18
- def self.check(config_dev, plugin_dir = nil)
19
- Fluent::Format::Check.new(config_dev, plugin_dir).run
19
+ def self.check(config_dev, plugin_dir = nil, libs = nil)
20
+ Fluent::Format::Check.new(config_dev, plugin_dir, libs).run
20
21
  end
21
22
  end
22
23
  end
@@ -2,13 +2,19 @@ require 'spec_helper'
2
2
 
3
3
  describe Fluent::Format::Check do
4
4
  let(:plugin_dir) { File.expand_path('../../../example', File.dirname(__FILE__)) }
5
- let(:subject) { Fluent::Format.check(config, plugin_dir) }
5
+ let(:libs) { [File.expand_path('../../../example/out_example', File.dirname(__FILE__))] }
6
+ let(:subject) { Fluent::Format.check(config, plugin_dir, libs) }
6
7
 
7
8
  context "valid" do
8
9
  let(:config) { StringIO.new(%[<match>\ntype stdout\n</match>]) }
9
10
  it { should be_true }
10
11
  end
11
12
 
13
+ context "plugin option" do
14
+ let(:config) { StringIO.new(%[<match>\ntype example\n</match>]) }
15
+ it { should be_true }
16
+ end
17
+
12
18
  context "syntax error" do
13
19
  let(:config) { StringIO.new(%[<source>\ntype stdout\n</match>]) }
14
20
  it { expect { subject }.to raise_error(Fluent::ConfigParseError) }
@@ -23,5 +29,10 @@ describe Fluent::Format::Check do
23
29
  let(:config) { StringIO.new(%[<match>\ntype example\nparam bad\n</match>]) }
24
30
  it { expect { subject }.to raise_error(Fluent::ConfigError) }
25
31
  end
32
+
33
+ context "file_path should `include`" do
34
+ let(:config) { File.expand_path('../../../example/include_error.conf', File.dirname(__FILE__)) }
35
+ it { expect { subject }.to raise_error(Fluent::ConfigError) }
36
+ end
26
37
  end
27
38
 
@@ -40,6 +40,18 @@ describe Fluent::Format::CLI do
40
40
  it { expect { subject }.not_to raise_error }
41
41
  end
42
42
 
43
+ context "plugin option" do
44
+ let(:opts) { {config: "fluent.conf", plugin: "example"} }
45
+ it { capture_stderr { subject }.should == "" }
46
+ it { expect { subject }.not_to raise_error }
47
+ end
48
+
49
+ context "require option" do
50
+ let(:opts) { {config: "fluent.conf", require: ["example/out_example"]} }
51
+ it { capture_stderr { subject }.should == "" }
52
+ it { expect { subject }.not_to raise_error }
53
+ end
54
+
43
55
  context "syntax error" do
44
56
  let(:opts) { {config: "example/syntax_error.conf"} }
45
57
  it { capture_stderr { subject }.should include("parse error") }
@@ -17,6 +17,12 @@ describe Fluent::Format::Format do
17
17
  let(:config) { StringIO.new(%[<match>\ntype foobar\n</match>]) }
18
18
  it { should == %[<match>\n type foobar\n</match>] }
19
19
  end
20
+
21
+ context "file_path should `include`" do
22
+ let(:config) { File.expand_path('../../../example/include.conf', File.dirname(__FILE__)) }
23
+ let(:included) { File.expand_path('../../../example/included.conf', File.dirname(__FILE__)) }
24
+ it { should include(File.read(included)) }
25
+ end
20
26
  end
21
27
 
22
28
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-07 00:00:00.000000000 Z
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: A command line utility to format fluentd configuration beautifully
97
+ description: A utility to format or check fluentd configuration
98
98
  email:
99
99
  - sonots@gmail.com
100
100
  executables:
@@ -111,6 +111,10 @@ files:
111
111
  - README.md
112
112
  - Rakefile
113
113
  - bin/fluent-format
114
+ - example/include.conf
115
+ - example/include_error.conf
116
+ - example/included.conf
117
+ - example/included_error.conf
114
118
  - example/out_example.rb
115
119
  - example/param_error.conf
116
120
  - example/plugin_error.conf
@@ -150,7 +154,7 @@ rubyforge_project:
150
154
  rubygems_version: 2.0.3
151
155
  signing_key:
152
156
  specification_version: 4
153
- summary: A command line utility to format fluentd configuration beautifully
157
+ summary: A utility to format or check fluentd configuration
154
158
  test_files:
155
159
  - spec/fluent/format/check_spec.rb
156
160
  - spec/fluent/format/cli_spec.rb