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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f400d67549dca909bceb3ca4596ae999a1c9f29cee17ef113e445f4a481163f2
4
- data.tar.gz: 10252b5eadc145a150fcffcc121988c98567da08dc1c51f8d261c58d9387e026
3
+ metadata.gz: 638e1715f758c7cf7021e6fc6e6222fd87313073b1041bd0f685405a7eb37d54
4
+ data.tar.gz: c2e681493e5d8d0470013c90f9df879b6dec19bb97ac81ba4ade7b3c4d2f5c23
5
5
  SHA512:
6
- metadata.gz: e6dc5a7ee780de4de6f3576751dca285816bfe21ded3329804e0983466ea4db4d406793672f63d7b45e46f3445e310b396e081283038d2a655275f61bbe65568
7
- data.tar.gz: 19c1769b9fce8be5e49be853d6974ac704853b205a6979ffb836a5acd189191640b00428a625e3b5ae62f3dadde8131567405ca5564a1b6da42706a0a14c8d11
6
+ metadata.gz: 3defa65d401ed798c06399ef7a68ea1dad267b0982db7d177e4d3a527202fcccbea1a7f322358ecec9ee7de849d65840d5acb77faa7a4e8b91e943ea50026a0b
7
+ data.tar.gz: 61dea9a9cafc9ba91df99690192e0e165e55cefeaaffade628ec7e48418cad393681d1b505533b38552246bb524f94e1ec134917c219261e1a049f8bba341fc2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lino (1.2.0.pre.1)
4
+ lino (1.2.0.pre.2)
5
5
  hamster (~> 3.0)
6
6
  open4 (~> 1.3)
7
7
 
@@ -8,7 +8,7 @@ module Lino
8
8
  include Lino::Utilities
9
9
 
10
10
  class <<self
11
- def for_command 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({components: [switch, value], separator: separator}))
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| "#{var[0]}=\"#{var[1]}\"" },
68
+ map_and_join(@environment_variables) { |var|
69
+ "#{var[0]}=\"#{var[1]}\""
70
+ },
59
71
  @command,
60
- map_and_join(@switches, &join_with(@option_separator)),
61
- map_and_join(@subcommands) { |sub| sub.build(@option_separator)},
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({components: [switch, value], separator: separator}))
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, &join_with(option_separator))
36
+ map_and_join(@switches,
37
+ &(quote_with(option_quoting) >> join_with(option_separator)))
33
38
  ]
34
39
 
35
40
  components
@@ -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(separator)
8
- lambda { |item| item[:components].join(item[:separator] || separator) }
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
@@ -1,3 +1,3 @@
1
1
  module Lino
2
- VERSION = '1.2.0.pre.1'
2
+ VERSION = '1.2.0.pre.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lino
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.pre.1
4
+ version: 1.2.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Clemson