baf 0.0.3 → 0.1.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: 7b5885bd5c54f82a2332b2af104090112ba279bb
4
- data.tar.gz: fc785f6261b8aa42c23ccd04ed822d314cd82ae7
3
+ metadata.gz: eb7e742e40fa882d844b78c036a6bca5f131c171
4
+ data.tar.gz: 37d3817b1e22de1bfc64893e160348def169cc21
5
5
  SHA512:
6
- metadata.gz: c6f56b483aa1c0173b1993634b4b066324c1d30586a8c129bc943a91bc9b4011d4887de4c8cbdd892aeb6f99d0007b9cf261192759e6c56e8b02273bcb930ad2
7
- data.tar.gz: f8f09d9a661222facdd6a0768fc6d814396c4fceda131ed4c40db4ec39fdca2ee0869b37d8769586cd97d0bb41660249e57397f26f139df177a940fa90a82455
6
+ metadata.gz: df951baa4362f0ab932d930cb01f90e903008cb3bfb2274ecb8af91d42e6234d621fe25c946ac60b8f8d692d711e440c398491d83722cb7347dc1bb9f6b068d9
7
+ data.tar.gz: 808326c6382a87fd570dabd173c50958929702cf32ffc22363acda37ab933af0ce94f33e82fa611c0284fc916bbb590e907d6ab09017e42f1f6592e9a4b1507f
data/lib/baf.rb CHANGED
@@ -1,10 +1,3 @@
1
- require 'forwardable'
2
- require 'optparse'
3
-
4
- require 'baf/cli'
5
- require 'baf/env'
6
- require 'baf/options_registrant'
7
-
8
1
  module Baf
9
2
  Error = Class.new(::StandardError)
10
3
  ArgumentError = Class.new(Error)
@@ -1,42 +1,20 @@
1
+ require 'optparse'
2
+
3
+ require 'baf'
4
+ require 'baf/env'
5
+ require 'baf/option'
1
6
  require 'baf/options_registrant'
2
7
 
3
8
  module Baf
4
9
  class CLI
5
- ArgumentError = Class.new(ArgumentError)
10
+ ArgumentError = Class.new(::Baf::ArgumentError)
6
11
 
7
12
  EX_USAGE = 64
8
13
  EX_SOFTWARE = 70
9
14
 
10
- CONFIG_DEFAULTS = {
11
- flags: [],
12
- options: [],
13
- parser: OptionParser.new,
14
- registrant: OptionsRegistrant
15
- }.freeze
16
-
17
15
  class << self
18
- def config
19
- @config ||= CONFIG_DEFAULTS.dup
20
- end
21
-
22
- def flag *args
23
- config[:flags] << Option.new(*args)
24
- end
25
-
26
- def flag_verbose
27
- config[:flags] << Option.new(:v, 'verbose')
28
- end
29
-
30
- def flag_debug
31
- config[:flags] << Option.new(:d, 'debug')
32
- end
33
-
34
- def option *args
35
- config[:options] << Option.new(*args)
36
- end
37
-
38
16
  def run arguments, stdout: $stdout, stderr: $stderr
39
- cli = new Env.new(stdout), arguments, config
17
+ cli = new Env.new(stdout), arguments
40
18
  cli.parse_arguments!
41
19
  cli.run
42
20
  rescue ArgumentError => e
@@ -47,29 +25,50 @@ module Baf
47
25
  stderr.puts e.backtrace.map { |l| ' %s' % l }
48
26
  exit EX_SOFTWARE
49
27
  end
28
+ end
29
+
30
+ attr_reader :arguments, :env, :parser
50
31
 
51
- protected
32
+ def initialize env, arguments, **opts
33
+ @env = env
34
+ @arguments = arguments
35
+ @parser = opts[:parser] || OptionParser.new
36
+ @registrant = opts[:registrant] || OptionsRegistrant.new(env, parser)
52
37
 
53
- Option = Struct.new('Option', :short, :long, :arg, :desc)
38
+ registrant.register_default_options
39
+ setup
54
40
  end
55
41
 
56
- attr_reader :arguments, :env, :option_parser
42
+ def setup
43
+ end
57
44
 
58
- def initialize env, arguments, config
59
- @env = env
60
- @option_parser = config[:parser]
61
- @arguments = arguments
45
+ def flag *args
46
+ registrant.flag *args
47
+ end
62
48
 
63
- config[:registrant].register env, config[:parser], config
49
+ def flag_debug
50
+ flag :d, 'debug'
51
+ end
52
+
53
+ def flag_verbose
54
+ flag :v, 'verbose'
55
+ end
56
+
57
+ def option *args
58
+ registrant.option *args
64
59
  end
65
60
 
66
61
  def parse_arguments!
67
- option_parser.parse! arguments
62
+ parser.parse! arguments
68
63
  rescue OptionParser::InvalidOption
69
- raise ArgumentError, option_parser
64
+ raise ArgumentError, parser
70
65
  end
71
66
 
72
67
  def run
73
68
  end
69
+
70
+ private
71
+
72
+ attr_reader :registrant
74
73
  end
75
74
  end
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module Baf
2
4
  class Env
3
5
  extend Forwardable
@@ -0,0 +1,16 @@
1
+ module Baf
2
+ Option = Struct.new('Option', :short, :long, :arg, :desc) do
3
+ def to_parser_arguments
4
+ ["-#{short}", parser_argument_long, desc]
5
+ end
6
+
7
+ protected
8
+
9
+ def parser_argument_long
10
+ [
11
+ '--' + long.to_s.tr(?_, ?-),
12
+ arg
13
+ ].join ' '
14
+ end
15
+ end
16
+ end
@@ -1,21 +1,16 @@
1
1
  module Baf
2
2
  class OptionsRegistrant
3
- class << self
4
- def register *args
5
- new(*args).register
6
- end
7
- end
8
-
9
- def initialize env, parser, config
3
+ def initialize env, parser
10
4
  @env = env
11
5
  @parser = parser
12
- @config = config
13
6
  end
14
7
 
15
- def register
16
- declare_default_options
17
- config[:flags].each { |o| flag o.short, o.long }
18
- config[:options].each { |o| option o }
8
+ def register_default_options
9
+ parser.separator ''
10
+ parser.separator 'options:'
11
+ parser.on_tail '-h', '--help', 'print this message' do
12
+ env.print parser
13
+ end
19
14
  end
20
15
 
21
16
  def flag short, long
@@ -25,9 +20,10 @@ module Baf
25
20
  end
26
21
  end
27
22
 
28
- def option opt
23
+ def option *args
24
+ opt = Option.new(*args)
29
25
  define_env_accessor env, opt.long
30
- parser.on "-#{opt.short}", "--#{opt.long} #{opt.arg}", opt.desc do |v|
26
+ parser.on *opt.to_parser_arguments do |v|
31
27
  env.send :"#{opt.long}=", v
32
28
  end
33
29
  end
@@ -36,14 +32,6 @@ module Baf
36
32
 
37
33
  attr_reader :env, :parser, :config
38
34
 
39
- def declare_default_options
40
- parser.separator ''
41
- parser.separator 'options:'
42
- parser.on_tail '-h', '--help', 'print this message' do
43
- env.print parser
44
- end
45
- end
46
-
47
35
  def define_env_accessor env, name
48
36
  (class << env; self end).send :attr_accessor, name
49
37
  end
@@ -1,3 +1,3 @@
1
1
  module Baf
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,49 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-05 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aruba
14
+ name: baf-testing
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.11'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '0.12'
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '0.11'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '0.12'
33
- - !ruby/object:Gem::Dependency
34
- name: cucumber
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '2.0'
19
+ version: '0.0'
40
20
  type: :development
41
21
  prerelease: false
42
22
  version_requirements: !ruby/object:Gem::Requirement
43
23
  requirements:
44
24
  - - "~>"
45
25
  - !ruby/object:Gem::Version
46
- version: '2.0'
26
+ version: '0.0'
47
27
  - !ruby/object:Gem::Dependency
48
28
  name: rake
49
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,20 +38,6 @@ dependencies:
58
38
  - - "~>"
59
39
  - !ruby/object:Gem::Version
60
40
  version: '10.4'
61
- - !ruby/object:Gem::Dependency
62
- name: rspec
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '3.4'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '3.4'
75
41
  description: Basic Application Framework
76
42
  email: tj@a13.fr
77
43
  executables: []
@@ -81,6 +47,7 @@ files:
81
47
  - lib/baf.rb
82
48
  - lib/baf/cli.rb
83
49
  - lib/baf/env.rb
50
+ - lib/baf/option.rb
84
51
  - lib/baf/options_registrant.rb
85
52
  - lib/baf/testing/cucumber.rb
86
53
  - lib/baf/testing/cucumber/steps/execution.rb