fluent-format 0.2.6 → 0.3.0

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: a42c489ee8e91e24fb8b3b29be8c9ca70299686a
4
- data.tar.gz: 81f2f02994f5b81cc889c8407b455fd84c998d88
3
+ metadata.gz: f7af2e17ee19cfeb863500c8449b08c961fb4f7d
4
+ data.tar.gz: c1c85c00356df958e831957c843a526e22086db5
5
5
  SHA512:
6
- metadata.gz: 981ceaa4700db2e66380c7ad31cb7f9942d1aa456eff1ae55c2d4a3cca52ebb817eed28b66659d3f958edad5a4dec19d4f12804607cbc917575d13b3f3dde7d2
7
- data.tar.gz: e32491a42548be2950038742a41ac89e8ed98eb30ac7777bbc23b3d619ea22201891d6bb16234867c49f802418cdff15f5d2415a48fef7f4abc3f1b04d3bdda4
6
+ metadata.gz: a72136527cd6c7bf6e9dfc05a5ae47964ba6c08ce868d54d69a234d029473c464c31802643d099c9aaacb048cf8e0cdeadc1c6630bf101c949349bc2ad623c26
7
+ data.tar.gz: 04881f4268b511155bd2bcbe9cae962c959edd4059f0f44439d13cb9a1e8bd53dd7b1d947de158b092411e67ccaf60535d75db7ce46ae6c444ea268c74cd09f3
@@ -1,6 +1,6 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
4
+ - 2.1
5
5
  gemfile:
6
6
  - Gemfile
@@ -1,3 +1,9 @@
1
+ ## 0.3.0 (2014/11/27)
2
+
3
+ Enhancements:
4
+
5
+ * Add --use-v1-config option
6
+
1
7
  ## 0.2.6 (2014/09/22)
2
8
 
3
9
  Fixes:
data/README.md CHANGED
@@ -47,6 +47,10 @@ Output Example:
47
47
  </match>
48
48
  ```
49
49
 
50
+ See help for more options
51
+
52
+ $ fluent-format help format
53
+
50
54
  ### Check
51
55
 
52
56
  $ fluent-format check -c fluent.conf -p plugin_dir
@@ -55,6 +59,10 @@ Output Example:
55
59
  This returns the status code 0 if check passed,
56
60
  and status code 1 with error messages if check failed.
57
61
 
62
+ See help for more options
63
+
64
+ $ fluent-format help check
65
+
58
66
  ## As a library
59
67
 
60
68
  ### Format
@@ -5,9 +5,10 @@ module Fluent
5
5
  # Format config file
6
6
  #
7
7
  # @param [IO|String] config_dev
8
+ # @param [Hash] opts
8
9
  # @return [String] the formatted config
9
- def self.format(config_dev)
10
- Fluent::Format::Format.new(config_dev).run
10
+ def self.format(config_dev, opts = {})
11
+ Fluent::Format::Format.new(config_dev, opts).run
11
12
  end
12
13
 
13
14
  # Check config file
@@ -19,6 +19,7 @@ module Fluent
19
19
  :chgroup => nil,
20
20
  :suppress_interval => 0,
21
21
  :suppress_repeated_stacktrace => false,
22
+ :use_v1_config => true,
22
23
  }
23
24
  @opts[:plugin_dirs] += opts[:plugin_dirs] if opts[:plugin_dirs] and !opts[:plugin_dirs].empty?
24
25
  @opts[:libs] += opts[:libs] if opts[:libs] and !opts[:libs].empty?
@@ -28,6 +29,7 @@ module Fluent
28
29
  if config_dev.respond_to?(:read) # IO object
29
30
  @opts[:config_path] = Tempfile.open('fluent-format') {|f| f.puts(config_dev.read); f.path }
30
31
  end
32
+ @opts[:use_v1_config] = opts[:use_v1_config]
31
33
  end
32
34
 
33
35
  # Check config file
@@ -7,9 +7,10 @@ module Fluent
7
7
  default_command :format
8
8
  desc "format", "Format fluent.conf"
9
9
  option :config, :aliases => ["-c"], :type => :string, :default => 'fluent.conf', :desc => 'Fluentd configuration file'
10
+ option :use_v1_config, :type => :boolean, :default => false, :desc => 'use v1 config format'
10
11
  def format
11
12
  config = @options[:config]
12
- taputs Fluent::Format.format(config)
13
+ taputs Fluent::Format.format(config, @options)
13
14
  rescue => e
14
15
  $stderr.puts "#{e.class} #{e.message} #{e.backtrace.first}"
15
16
  exit 1
@@ -22,6 +23,7 @@ module Fluent
22
23
  option :inline_config, :aliases => ["-i"], :type => :string, :desc => 'inline config which is appended to the config file on-fly'
23
24
  option :gemfile, :aliases => ["-g"], :type => :string, :desc => 'Gemfile path'
24
25
  option :gem_install_path, :aliases => ["-G"], :type => :string, :desc => 'Gem install path (default: $(dirname $gemfile)/vendor/bundle)'
26
+ option :use_v1_config, :type => :boolean, :default => false, :desc => 'use v1 config format'
25
27
  def check
26
28
  config = @options[:config]
27
29
  Fluent::Format.check(config, @options)
@@ -3,18 +3,39 @@ module Fluent
3
3
  class Format
4
4
  # Initialize
5
5
  #
6
- # @param [IO|String] config_dev
7
- def initialize(config_dev)
6
+ # @param [IO|String] config filename or IO Object
7
+ def initialize(config_dev, opts = {})
8
8
  @config_dev = config_dev
9
+ @use_v1_config = opts[:use_v1_config]
9
10
  end
10
11
 
11
12
  # Format config
12
13
  #
13
14
  # @raise Fluent::ConfigParseError if conf has syntax errors
15
+ # @raise Fluent::ConfigError if plugin raises config error
14
16
  # @return [String] the formatted config
15
17
  def run
16
- config = Fluent::ExtConfig.read(@config_dev)
17
- indent(config)
18
+ formatted = read(@config_dev, @use_v1_config)
19
+ indent(formatted)
20
+ end
21
+
22
+ # Read config (this does formatting)
23
+ #
24
+ # @param [IO|String] config_dev config filename or IO Object
25
+ # @raise Fluent::ConfigParseError if conf has syntax errors
26
+ # @raise Fluent::ConfigError if plugin raises config error
27
+ # @return [String] the formatted config
28
+ def read(config_dev, use_v1_config)
29
+ if config_dev.respond_to?(:read) # IO object
30
+ str = config_dev.read
31
+ fname = '-'
32
+ basename = '-'
33
+ else
34
+ str = File.read(config_dev)
35
+ fname = File.basename(config_dev)
36
+ basename = File.dirname(config_dev)
37
+ end
38
+ Fluent::Config.parse(str, fname, basename, use_v1_config)
18
39
  end
19
40
 
20
41
  private
@@ -28,34 +49,3 @@ module Fluent
28
49
  end
29
50
  end
30
51
  end
31
-
32
- # lib/fluent/config.rb
33
- module Fluent
34
- module ExtConfig
35
- # Extended to accept IO object
36
- #
37
- # @raise Fluent::ConfigParseError if conf has syntax errors
38
- # @raise Fluent::ConfigError if plugin raises config error
39
- # @return [String] parsed config string
40
- def self.read(dev)
41
- if dev.respond_to?(:read) # IO object
42
- parse(dev, '-', '-')
43
- else
44
- File.open(dev) {|io| parse(io, File.basename(dev), File.dirname(dev)) }
45
- end
46
- end
47
-
48
- # Extended to accept config dsl
49
- #
50
- # @raise Fluent::ConfigParseError if conf has syntax errors
51
- # @raise Fluent::ConfigError if plugin raises config error
52
- # @return [String] parsed config string
53
- def self.parse(io, fname, basepath=Dir.pwd)
54
- if fname =~ /\.rb$/
55
- Fluent::Config::DSL::Parser.parse(io, File.join(basepath, fname))
56
- else
57
- Fluent::Config.parse(io, fname, basepath)
58
- end
59
- end
60
- end
61
- end
@@ -1,5 +1,5 @@
1
1
  module Fluent
2
2
  class Format
3
- VERSION = "0.2.6"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -20,13 +20,13 @@ describe Fluent::Format::CLI do
20
20
 
21
21
  context "success" do
22
22
  let(:opts) { {config: "fluent.conf"} }
23
- it { capture_stderr { subject }.should == "" }
23
+ it { expect(capture_stderr { subject }).to eq "" }
24
24
  it { expect { subject }.not_to raise_error }
25
25
  end
26
26
 
27
27
  context "failure" do
28
28
  let(:opts) { {config: "unknown.conf"} }
29
- it { capture_stderr { subject }.should include "No such file or directory" }
29
+ it { expect(capture_stderr { subject }).to include "No such file or directory" }
30
30
  it { expect { subject }.to raise_error(SystemExit) }
31
31
  end
32
32
  end
@@ -36,38 +36,38 @@ describe Fluent::Format::CLI do
36
36
 
37
37
  context "success" do
38
38
  let(:opts) { {config: "fluent.conf"} }
39
- it { capture_stderr { subject }.should == "" }
39
+ it { expect(capture_stderr { subject }).to eq "" }
40
40
  it { expect { subject }.not_to raise_error }
41
41
  end
42
42
 
43
43
  context "-p option" do
44
44
  let(:opts) { {config: "fluent.conf", plugin_dirs: ["example"]} }
45
- it { capture_stderr { subject }.should == "" }
45
+ it { expect(capture_stderr { subject }).to eq "" }
46
46
  it { expect { subject }.not_to raise_error }
47
47
  end
48
48
 
49
49
  context "-r option" do
50
50
  let(:libs) { [File.expand_path('../../../example/out_example', File.dirname(__FILE__))] }
51
51
  let(:opts) { {config: "fluent.conf", libs: libs } }
52
- it { capture_stderr { subject }.should == "" }
52
+ it { expect(capture_stderr { subject }).to eq "" }
53
53
  it { expect { subject }.not_to raise_error }
54
54
  end
55
55
 
56
56
  context "syntax error" do
57
57
  let(:opts) { {config: "example/syntax_error.conf"} }
58
- it { capture_stderr { subject }.should include("parse error") }
58
+ it { expect(capture_stderr { subject }).to include("parse error") }
59
59
  it { expect { subject }.to raise_error(SystemExit) }
60
60
  end
61
61
 
62
62
  context "plugin error" do
63
63
  let(:opts) { {config: "example/plugin_error.conf"} }
64
- it { capture_stderr { subject }.should include("Unknown input plugin") }
64
+ it { expect(capture_stderr { subject }).to include("Unknown input plugin") }
65
65
  it { expect { subject }.to raise_error(SystemExit) }
66
66
  end
67
67
 
68
68
  context "param error" do
69
69
  let(:opts) { {config: "example/param_error.conf", plugin_dirs: ["example"]} }
70
- it { capture_stderr { subject }.should include("out_example.rb") }
70
+ it { expect(capture_stderr { subject }).to include("out_example.rb") }
71
71
  it { expect { subject }.to raise_error(SystemExit) }
72
72
  end
73
73
  end
@@ -5,8 +5,3 @@ require 'fluent-format'
5
5
 
6
6
  ROOT = File.dirname(__FILE__)
7
7
  Dir[File.expand_path("support/**/*.rb", ROOT)].each {|f| require f }
8
-
9
- RSpec.configure do |config|
10
- config.treat_symbols_as_metadata_keys_with_true_values = true
11
- config.run_all_when_everything_filtered = true
12
- end
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.6
4
+ version: 0.3.0
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-09-21 00:00:00.000000000 Z
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor