lino 1.2.0.pre.1 → 1.2.0.pre.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/Gemfile.lock +1 -1
- data/lib/lino/command_line_builder.rb +24 -8
- data/lib/lino/subcommand_builder.rb +9 -4
- data/lib/lino/utilities.rb +20 -2
- data/lib/lino/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 638e1715f758c7cf7021e6fc6e6222fd87313073b1041bd0f685405a7eb37d54
|
4
|
+
data.tar.gz: c2e681493e5d8d0470013c90f9df879b6dec19bb97ac81ba4ade7b3c4d2f5c23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3defa65d401ed798c06399ef7a68ea1dad267b0982db7d177e4d3a527202fcccbea1a7f322358ecec9ee7de849d65840d5acb77faa7a4e8b91e943ea50026a0b
|
7
|
+
data.tar.gz: 61dea9a9cafc9ba91df99690192e0e165e55cefeaaffade628ec7e48418cad393681d1b505533b38552246bb524f94e1ec134917c219261e1a049f8bba341fc2
|
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ module Lino
|
|
8
8
|
include Lino::Utilities
|
9
9
|
|
10
10
|
class <<self
|
11
|
-
def for_command
|
11
|
+
def for_command(command)
|
12
12
|
CommandLineBuilder.new(command: command)
|
13
13
|
end
|
14
14
|
end
|
@@ -19,13 +19,15 @@ module Lino
|
|
19
19
|
switches: [],
|
20
20
|
arguments: [],
|
21
21
|
environment_variables: [],
|
22
|
-
option_separator: ' '
|
22
|
+
option_separator: ' ',
|
23
|
+
option_quoting: nil)
|
23
24
|
@command = command
|
24
25
|
@subcommands = Hamster::Vector.new(subcommands)
|
25
26
|
@switches = Hamster::Vector.new(switches)
|
26
27
|
@arguments = Hamster::Vector.new(arguments)
|
27
28
|
@environment_variables = Hamster::Vector.new(environment_variables)
|
28
29
|
@option_separator = option_separator
|
30
|
+
@option_quoting = option_quoting
|
29
31
|
end
|
30
32
|
|
31
33
|
def with_subcommand(subcommand, &block)
|
@@ -33,14 +35,22 @@ module Lino
|
|
33
35
|
SubcommandBuilder.for_subcommand(subcommand))))
|
34
36
|
end
|
35
37
|
|
36
|
-
def with_option(switch, value, separator: nil)
|
37
|
-
with(switches: @switches.add({
|
38
|
+
def with_option(switch, value, separator: nil, quoting: nil)
|
39
|
+
with(switches: @switches.add({
|
40
|
+
components: [switch, value],
|
41
|
+
separator: separator,
|
42
|
+
quoting: quoting
|
43
|
+
}))
|
38
44
|
end
|
39
45
|
|
40
46
|
def with_option_separator(option_separator)
|
41
47
|
with(option_separator: option_separator)
|
42
48
|
end
|
43
49
|
|
50
|
+
def with_option_quoting(character)
|
51
|
+
with(option_quoting: character)
|
52
|
+
end
|
53
|
+
|
44
54
|
def with_flag(flag)
|
45
55
|
with(switches: @switches.add({components: [flag]}))
|
46
56
|
end
|
@@ -55,10 +65,15 @@ module Lino
|
|
55
65
|
|
56
66
|
def build
|
57
67
|
components = [
|
58
|
-
map_and_join(@environment_variables) { |var|
|
68
|
+
map_and_join(@environment_variables) { |var|
|
69
|
+
"#{var[0]}=\"#{var[1]}\""
|
70
|
+
},
|
59
71
|
@command,
|
60
|
-
map_and_join(@switches,
|
61
|
-
|
72
|
+
map_and_join(@switches,
|
73
|
+
&(quote_with(@option_quoting) >> join_with(@option_separator))),
|
74
|
+
map_and_join(@subcommands) { |sub|
|
75
|
+
sub.build(@option_separator, @option_quoting)
|
76
|
+
},
|
62
77
|
map_and_join(@arguments, &join_with(' '))
|
63
78
|
]
|
64
79
|
|
@@ -82,7 +97,8 @@ module Lino
|
|
82
97
|
switches: @switches,
|
83
98
|
arguments: @arguments,
|
84
99
|
environment_variables: @environment_variables,
|
85
|
-
option_separator: @option_separator
|
100
|
+
option_separator: @option_separator,
|
101
|
+
option_quoting: @option_quoting
|
86
102
|
}
|
87
103
|
end
|
88
104
|
end
|
@@ -18,18 +18,23 @@ module Lino
|
|
18
18
|
@switches = Hamster::Vector.new(switches)
|
19
19
|
end
|
20
20
|
|
21
|
-
def with_option(switch, value, separator: nil)
|
22
|
-
with(switches: @switches.add({
|
21
|
+
def with_option(switch, value, separator: nil, quoting: nil)
|
22
|
+
with(switches: @switches.add({
|
23
|
+
components: [switch, value],
|
24
|
+
separator: separator,
|
25
|
+
quoting: quoting
|
26
|
+
}))
|
23
27
|
end
|
24
28
|
|
25
29
|
def with_flag(flag)
|
26
30
|
with(switches: @switches.add({components: [flag]}))
|
27
31
|
end
|
28
32
|
|
29
|
-
def build(option_separator)
|
33
|
+
def build(option_separator, option_quoting)
|
30
34
|
components = [
|
31
35
|
@subcommand,
|
32
|
-
map_and_join(@switches,
|
36
|
+
map_and_join(@switches,
|
37
|
+
&(quote_with(option_quoting) >> join_with(option_separator)))
|
33
38
|
]
|
34
39
|
|
35
40
|
components
|
data/lib/lino/utilities.rb
CHANGED
@@ -1,11 +1,29 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
1
3
|
module Lino
|
2
4
|
module Utilities
|
3
5
|
def map_and_join(collection, &block)
|
4
6
|
collection.map { |item| block.call(item) }.join(' ')
|
5
7
|
end
|
6
8
|
|
7
|
-
def join_with(
|
8
|
-
lambda
|
9
|
+
def join_with(global_separator)
|
10
|
+
lambda do |item|
|
11
|
+
item[:components].join(item[:separator] || global_separator)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def quote_with(global_character)
|
16
|
+
lambda do |item|
|
17
|
+
character = item[:quoting] || global_character
|
18
|
+
components = item[:components]
|
19
|
+
switch = components[0]
|
20
|
+
value = components[1]
|
21
|
+
|
22
|
+
item.merge(
|
23
|
+
components: (components.count > 1) ?
|
24
|
+
[switch, "#{character}#{value}#{character}"] :
|
25
|
+
components)
|
26
|
+
end
|
9
27
|
end
|
10
28
|
end
|
11
29
|
end
|
data/lib/lino/version.rb
CHANGED