usps-imis-api 0.13.4 → 0.13.5

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: f34a885284d3ccfeced54ef7b76cda38b69922d80c61ba22d4950945ee4bc1ea
4
- data.tar.gz: fe1a7952665d65adabddf3f13eed3720b267b20ee2d5029715df096bbc82d52f
3
+ metadata.gz: 6f533f6f1c46a836c57ed615db3e4ed3a960e1cf6e280d258cc59ee72bbe735d
4
+ data.tar.gz: b2877c785c60738326dc96e7aa50da21eff214e21b961a30773dc2f0f843e195
5
5
  SHA512:
6
- metadata.gz: f99eb59125c90b6e1c7dc11b2e32c6b3eea327825785614629919b9548aa429ed30458d68f59943557e07e37c3faef6c22deddc9b5e5da127c05d26f674912d3
7
- data.tar.gz: 0dd03c7791e6d1e68a0365aa87c741a44fb5b145aec6002c264e2931c6fa14f35554321ec1cb6d59dfcd36c012ccfcd2f4e0adae514886f48a31ba87a484930a
6
+ metadata.gz: 1c032d83d0b9c87de3d0e705e330e840cf159dc252837b54b138b5ee7a791d587b21630050b05427a59d81a5c2c605331b514dbed339634a199c2fc67f61b35c
7
+ data.tar.gz: 6f6a335d752b0aacef359d5fb79a499e7f6224a9c884acc42730beb44ab595d4a88659545fb7ec8ae612d84c3ba16159cc568a8993a1101bbf7bca74bd399e48
@@ -8,9 +8,24 @@ module Usps
8
8
  # @private
9
9
  #
10
10
  module Help
11
- TERMINAL_WIDTH = 120
11
+ # Width of the terminal window
12
+ #
13
+ # :nocov:
14
+ TERMINAL_WIDTH = IO.console&.winsize&.at(1) || 80
15
+ # :nocov:
16
+
17
+ # Extra padding between columns
18
+ #
12
19
  GAP = 4
13
20
 
21
+ # Adjust the underlying command padding to account for non-printing characters
22
+ #
23
+ # Bold and gray each add 14:
24
+ # '-'.bold.length == 15
25
+ # '-'.gray.length == 15
26
+ #
27
+ ESCAPE_PADDING = 14
28
+
14
29
  def banner_header(version)
15
30
  <<~BANNER
16
31
  #{version.bold.blue}
@@ -19,6 +34,12 @@ module Usps
19
34
  end
20
35
 
21
36
  def banner_contents
37
+ wiki = word_wrap(
38
+ 'For an explanation of how to provide API configuration, ' \
39
+ 'more details on the options, and usage examples, please refer to the wiki:',
40
+ TERMINAL_WIDTH - indent(1).length
41
+ ).join("\n#{indent(1)}")
42
+
22
43
  <<~BANNER
23
44
  #{'Usage'.underline}
24
45
 
@@ -27,8 +48,7 @@ module Usps
27
48
 
28
49
  #{'Further Help'.underline}
29
50
 
30
- For an explanation of how to provide API configuration, more details on the options,
31
- and usage examples, please refer to the wiki:
51
+ #{wiki}
32
52
 
33
53
  https://github.com/unitedstatespowersquadrons/imis-api-ruby/wiki/Command-Line
34
54
 
@@ -64,29 +84,21 @@ module Usps
64
84
  private
65
85
 
66
86
  def help_commands(lines)
67
- # Adjust the underlying command padding to account for non-printing characters
68
- #
69
- # Bold and gray each add 14:
70
- # '-'.bold.length == 15
71
- # '-'.gray.length == 15
72
- #
73
- escape_padding = 14
74
-
75
- command_lengths = subcommands.map { |name, details| name.length + details[:value].to_s.length }
76
- command_width = command_lengths.max + GAP + escape_padding
77
-
78
87
  lines << "#{'Commands'.underline}\n"
79
88
  subcommands.each do |name, details|
80
89
  combined_name = details[:value] ? "#{name.bold} #{"<#{details[:value]}>".gray}" : name.bold
81
- lines << [
82
- indent(1),
83
- combined_name.ljust(command_width + (details[:value] ? escape_padding : 0)),
84
- details[:description]
85
- ].join
90
+ command = combined_name.ljust(command_width + (details[:value] ? ESCAPE_PADDING : 0))
91
+ left_width = indent(1).length + command_width
92
+ lines << "#{indent(1)}#{command}#{wrap_description(details[:description], left_width)}"
86
93
  end
87
94
  lines << "\n"
88
95
  end
89
96
 
97
+ def command_width
98
+ command_lengths = subcommands.map { |name, details| name.length + details[:value].to_s.length }
99
+ command_lengths.max + GAP + ESCAPE_PADDING
100
+ end
101
+
90
102
  def help_options(lines)
91
103
  lines << "#{'Options'.underline}\n"
92
104
  option_groups.each do |group_name, option_keys|
@@ -98,9 +110,16 @@ module Usps
98
110
 
99
111
  def help_legacy_flags(lines)
100
112
  lines << "#{indent(1)}#{'Legacy Flags'.underline}\n"
101
- lines << "#{indent(2)}The following options are still supported, but have been replaced by subcommands:\n"
113
+ explanation = word_wrap(
114
+ 'The following options are still supported, but have been replaced by subcommands:',
115
+ TERMINAL_WIDTH - indent(2).length
116
+ ).join("\n#{indent(2)}")
117
+ lines << "#{indent(2)}#{explanation}\n"
118
+
102
119
  legacy_flags.each do |flags, replacement|
103
- lines << "#{indent(2)}#{flags.ljust(option_column_width)}use: #{replacement}"
120
+ left_width = indent(2).length + option_column_width
121
+ description = wrap_description("use: #{replacement}", left_width)
122
+ lines << "#{indent(2)}#{flags.ljust(option_column_width)}#{description}"
104
123
  end
105
124
  lines << "\n"
106
125
  end
@@ -27,10 +27,10 @@ Subcommands:
27
27
  - Interact with mapped fields
28
28
  - short: M
29
29
  map:
30
- description: "Shorthand for `<%= 'mapper -f'.green %>` to access a single mapped field"
30
+ description: Shorthand for `%{green:mapper -f}` to access a single mapped field
31
31
  value: field
32
32
  option:
33
- - "Shorthand for <%= '-Mf'.green %> to access a single mapped field"
33
+ - Shorthand for %{green:-Mf} to access a single mapped field
34
34
  - type: string
35
35
  short: m
36
36
  business-objects:
@@ -65,13 +65,13 @@ Options:
65
65
 
66
66
  Business Object or Panel:
67
67
  create:
68
- - "Send a <%= 'POST'.cyan %> request"
68
+ - Send a %{cyan:POST} request
69
69
  - short: C
70
70
  delete:
71
- - "Send a <%= 'DELETE'.cyan %> request"
71
+ - Send a %{cyan:DELETE} request
72
72
  - short: D
73
73
  all:
74
- - "Send a <%= 'GET'.cyan %> request for all records for a member"
74
+ - Send a %{cyan:GET} request for all records for a member
75
75
  - short: A
76
76
 
77
77
  Panel:
@@ -106,7 +106,7 @@ Options:
106
106
  - type: strings
107
107
  short: F
108
108
  data:
109
- - "JSON string input -- <%= 'STDIN'.red %> takes priority"
109
+ - JSON string input -- %{red:STDIN} takes priority
110
110
  - type: string
111
111
  short: d
112
112
 
@@ -126,21 +126,20 @@ Options:
126
126
 
127
127
  Configuration:
128
128
  config:
129
- - "Path to the JSON/YAML config file to use, or one of the following preset options:\
130
- \n`<%= 'local_dot'.yellow %>`, \
131
- `<%= 'local'.yellow %>`, \
132
- `<%= 'local_dot_config'.yellow %>`, \
133
- `<%= 'local_config'.yellow %>`, \
134
- `<%= 'user'.yellow %>`, \
135
- `<%= 'system'.yellow %>`\
136
- \nIf no option is provided, the first matching preset option will be automatically used."
129
+ - >-
130
+ Path to the JSON/YAML config file to use, or one of the following preset options:
131
+
132
+ `%{yellow:local_dot}`, `%{yellow:local}`, `%{yellow:local_dot_config}`,
133
+ `%{yellow:local_config}`, `%{yellow:user}`, `%{yellow:system}`
134
+
135
+ If no option is provided, the first matching preset option will be automatically used.
137
136
  - type: string
138
137
  short: Y
139
138
  show_config:
140
139
  - Return the active config file path
141
140
  - short: X
142
141
  include_ids:
143
- - "Include any <%= 'iMIS ID'.yellow %> and <%= 'Ordinal'.yellow %> properties in returned data"
142
+ - Include any %{yellow:iMIS ID} and %{yellow:Ordinal} properties in returned data
144
143
  - short: N
145
144
  token:
146
145
  - Provide an existing auth token
@@ -149,10 +148,10 @@ Options:
149
148
 
150
149
  Logging:
151
150
  quiet:
152
- - "Suppress logging to <%= 'STDERR'.red %>"
151
+ - Suppress logging to %{red:STDERR}
153
152
  - short: q
154
153
  log:
155
- - "Redirect logging to <%= 'STDOUT'.red %>"
154
+ - Redirect logging to %{red:STDOUT}
156
155
  - short: l
157
156
  log_level:
158
157
  - Set the logging level
@@ -8,8 +8,15 @@ module Usps
8
8
  # @private
9
9
  #
10
10
  module OptionsParserConfig
11
+ STYLE_NAMES = (String.colors + String.modes).map(&:to_s).freeze
12
+ STYLE_PATTERN = /%\{(#{Regexp.union(STYLE_NAMES)}(?:\.#{Regexp.union(STYLE_NAMES)})*):(.*?)\}/
13
+
11
14
  def subcommands
12
- @subcommands ||= yaml['Subcommands'].transform_values { it.transform_keys(&:to_sym) }
15
+ @subcommands ||= yaml['Subcommands'].transform_values do |details|
16
+ details.transform_keys(&:to_sym).tap do |h|
17
+ h[:description] = colorize_text(h[:description]) if h[:description]
18
+ end
19
+ end
13
20
  end
14
21
 
15
22
  def option_groups
@@ -19,7 +26,7 @@ module Usps
19
26
  def options
20
27
  @options ||= merged_options.transform_keys(&:to_sym).transform_values do |description, details|
21
28
  [
22
- description,
29
+ colorize_text(description),
23
30
  details.transform_keys(&:to_sym).each_with_object({}) do |(key, value), hash|
24
31
  hash[key] = %i[type short].include?(key) ? value.to_sym : value
25
32
  end
@@ -51,11 +58,18 @@ module Usps
51
58
  private
52
59
 
53
60
  def yaml
54
- return @yaml if @yaml
61
+ @yaml ||= YAML.safe_load_file("#{File.dirname(__FILE__)}/options.yml")
62
+ end
55
63
 
56
- raw_yaml_erb = File.read("#{File.dirname(__FILE__)}/options.yml.erb")
57
- rendered_yaml = ERB.new(raw_yaml_erb).result.gsub("\x1b", '\u001b')
58
- @yaml = YAML.safe_load(rendered_yaml)
64
+ def colorize_text(text)
65
+ text.gsub(STYLE_PATTERN) { Regexp.last_match(2).colorize(style_args(Regexp.last_match(1))) }
66
+ end
67
+
68
+ def style_args(styles)
69
+ styles.split('.').each_with_object({}) do |name, args|
70
+ key = String.colors.include?(name.to_sym) ? :color : :mode
71
+ args[key] = name.to_sym
72
+ end
59
73
  end
60
74
 
61
75
  def merged_options
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'optimist'
4
4
  require 'colorize'
5
- require 'erb'
6
5
  require 'csv'
6
+ require 'io/console'
7
7
 
8
8
  module Usps
9
9
  module Imis
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.13.4'
5
+ VERSION = '0.13.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-imis-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.4
4
+ version: 0.13.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -97,7 +97,7 @@ files:
97
97
  - lib/usps/imis/command_line/formatters.rb
98
98
  - lib/usps/imis/command_line/help.rb
99
99
  - lib/usps/imis/command_line/interface.rb
100
- - lib/usps/imis/command_line/options.yml.erb
100
+ - lib/usps/imis/command_line/options.yml
101
101
  - lib/usps/imis/command_line/options_parser.rb
102
102
  - lib/usps/imis/command_line/options_parser_config.rb
103
103
  - lib/usps/imis/command_line/performers.rb