baf 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/baf.rb +1 -1
- data/lib/baf/cli.rb +30 -26
- data/lib/baf/options_registrant.rb +60 -0
- data/lib/baf/testing/cucumber/steps/execution.rb +5 -1
- data/lib/baf/testing/cucumber/steps/output.rb +6 -2
- data/lib/baf/version.rb +1 -1
- metadata +3 -3
- data/lib/baf/option_registrant.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b5885bd5c54f82a2332b2af104090112ba279bb
|
4
|
+
data.tar.gz: fc785f6261b8aa42c23ccd04ed822d314cd82ae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6f56b483aa1c0173b1993634b4b066324c1d30586a8c129bc943a91bc9b4011d4887de4c8cbdd892aeb6f99d0007b9cf261192759e6c56e8b02273bcb930ad2
|
7
|
+
data.tar.gz: f8f09d9a661222facdd6a0768fc6d814396c4fceda131ed4c40db4ec39fdca2ee0869b37d8769586cd97d0bb41660249e57397f26f139df177a940fa90a82455
|
data/lib/baf.rb
CHANGED
data/lib/baf/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'baf/options_registrant'
|
2
|
+
|
1
3
|
module Baf
|
2
4
|
class CLI
|
3
5
|
ArgumentError = Class.new(ArgumentError)
|
@@ -5,17 +7,36 @@ module Baf
|
|
5
7
|
EX_USAGE = 64
|
6
8
|
EX_SOFTWARE = 70
|
7
9
|
|
10
|
+
CONFIG_DEFAULTS = {
|
11
|
+
flags: [],
|
12
|
+
options: [],
|
13
|
+
parser: OptionParser.new,
|
14
|
+
registrant: OptionsRegistrant
|
15
|
+
}.freeze
|
16
|
+
|
8
17
|
class << self
|
9
|
-
def
|
10
|
-
|
18
|
+
def config
|
19
|
+
@config ||= CONFIG_DEFAULTS.dup
|
11
20
|
end
|
12
21
|
|
13
|
-
def
|
14
|
-
|
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)
|
15
36
|
end
|
16
37
|
|
17
38
|
def run arguments, stdout: $stdout, stderr: $stderr
|
18
|
-
cli = new
|
39
|
+
cli = new Env.new(stdout), arguments, config
|
19
40
|
cli.parse_arguments!
|
20
41
|
cli.run
|
21
42
|
rescue ArgumentError => e
|
@@ -30,23 +51,16 @@ module Baf
|
|
30
51
|
protected
|
31
52
|
|
32
53
|
Option = Struct.new('Option', :short, :long, :arg, :desc)
|
33
|
-
|
34
|
-
def env output = nil
|
35
|
-
@env ||= Env.new(output)
|
36
|
-
end
|
37
|
-
|
38
|
-
def option_parser
|
39
|
-
@option_parser ||= OptionParser.new
|
40
|
-
end
|
41
54
|
end
|
42
55
|
|
43
56
|
attr_reader :arguments, :env, :option_parser
|
44
57
|
|
45
|
-
def initialize env,
|
58
|
+
def initialize env, arguments, config
|
46
59
|
@env = env
|
47
|
-
@option_parser =
|
60
|
+
@option_parser = config[:parser]
|
48
61
|
@arguments = arguments
|
49
|
-
|
62
|
+
|
63
|
+
config[:registrant].register env, config[:parser], config
|
50
64
|
end
|
51
65
|
|
52
66
|
def parse_arguments!
|
@@ -57,15 +71,5 @@ module Baf
|
|
57
71
|
|
58
72
|
def run
|
59
73
|
end
|
60
|
-
|
61
|
-
protected
|
62
|
-
|
63
|
-
def setup_default_options option_parser
|
64
|
-
option_parser.separator ''
|
65
|
-
option_parser.separator 'options:'
|
66
|
-
option_parser.on_tail '-h', '--help', 'print this message' do
|
67
|
-
env.print option_parser
|
68
|
-
end
|
69
|
-
end
|
70
74
|
end
|
71
75
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Baf
|
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
|
10
|
+
@env = env
|
11
|
+
@parser = parser
|
12
|
+
@config = config
|
13
|
+
end
|
14
|
+
|
15
|
+
def register
|
16
|
+
declare_default_options
|
17
|
+
config[:flags].each { |o| flag o.short, o.long }
|
18
|
+
config[:options].each { |o| option o }
|
19
|
+
end
|
20
|
+
|
21
|
+
def flag short, long
|
22
|
+
define_env_flag env, long
|
23
|
+
parser.on "-#{short}", "--#{long}", "enable #{long} mode" do
|
24
|
+
env.send :"#{long}=", true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def option opt
|
29
|
+
define_env_accessor env, opt.long
|
30
|
+
parser.on "-#{opt.short}", "--#{opt.long} #{opt.arg}", opt.desc do |v|
|
31
|
+
env.send :"#{opt.long}=", v
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
attr_reader :env, :parser, :config
|
38
|
+
|
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
|
+
def define_env_accessor env, name
|
48
|
+
(class << env; self end).send :attr_accessor, name
|
49
|
+
end
|
50
|
+
|
51
|
+
def define_env_flag env, name
|
52
|
+
define_env_accessor env, name
|
53
|
+
env.send :"#{name}=", false
|
54
|
+
env.define_singleton_method :"#{name}?" do
|
55
|
+
instance_variable_get :"@#{name}"
|
56
|
+
end
|
57
|
+
env.instance_variable_set :"@#{name}", false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
def program_run check: false, opts: nil, args: nil
|
2
|
-
cmd = %w[ruby baf]
|
2
|
+
cmd = [*@_baf_program ||= %w[ruby baf]]
|
3
3
|
cmd << opts if opts
|
4
4
|
cmd << args.split(' ') if args
|
5
5
|
run_simple cmd.join(' '), fail_on_error: false
|
@@ -36,3 +36,7 @@ end
|
|
36
36
|
Then /^the exit status must be (\d+)$/ do |exit_status|
|
37
37
|
program_run_check status: exit_status.to_i
|
38
38
|
end
|
39
|
+
|
40
|
+
Then /^the program must terminate successfully$/ do
|
41
|
+
program_run_check status: 0
|
42
|
+
end
|
@@ -8,13 +8,17 @@ def build_regexp pattern, options
|
|
8
8
|
end)
|
9
9
|
end
|
10
10
|
|
11
|
+
def expect_output content
|
12
|
+
expect(last_command_started.output).to eq unescape_text content
|
13
|
+
end
|
14
|
+
|
11
15
|
|
12
16
|
Then /^the output must contain exactly:$/ do |content|
|
13
|
-
|
17
|
+
expect_output content + $/
|
14
18
|
end
|
15
19
|
|
16
20
|
Then /^the output must contain exactly "([^"]+)"$/ do |content|
|
17
|
-
|
21
|
+
expect_output content
|
18
22
|
end
|
19
23
|
|
20
24
|
Then /^the output must match \/([^\/]+)\/([a-z]*)$/ do |pattern, options|
|
data/lib/baf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|
@@ -81,7 +81,7 @@ files:
|
|
81
81
|
- lib/baf.rb
|
82
82
|
- lib/baf/cli.rb
|
83
83
|
- lib/baf/env.rb
|
84
|
-
- lib/baf/
|
84
|
+
- lib/baf/options_registrant.rb
|
85
85
|
- lib/baf/testing/cucumber.rb
|
86
86
|
- lib/baf/testing/cucumber/steps/execution.rb
|
87
87
|
- lib/baf/testing/cucumber/steps/output.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Baf
|
2
|
-
class OptionRegistrant
|
3
|
-
class << self
|
4
|
-
def register_flag env, parser, short, long
|
5
|
-
define_env_flag env, long
|
6
|
-
parser.on "-#{short}", "--#{long}", "enable #{long} mode" do
|
7
|
-
env.send :"#{long}=", true
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def register_option env, parser, opt
|
12
|
-
define_env_accessor env, opt.long
|
13
|
-
parser.on "-#{opt.short}", "--#{opt.long} #{opt.arg}", opt.desc do |v|
|
14
|
-
env.send :"#{opt.long}=", v
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
def define_env_accessor env, name
|
21
|
-
(class << env; self end).send :attr_accessor, name
|
22
|
-
end
|
23
|
-
|
24
|
-
def define_env_flag env, name
|
25
|
-
define_env_accessor env, name
|
26
|
-
env.send :"#{name}=", false
|
27
|
-
env.define_singleton_method :"#{name}?" do
|
28
|
-
instance_variable_get :"@#{name}"
|
29
|
-
end
|
30
|
-
env.instance_variable_set :"@#{name}", false
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|