wisco 0.2.6 → 0.2.7

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: 922149837870023d570403cf2ef875643e7201eee6eb425eab6cb98b360448d5
4
- data.tar.gz: a55d53569027d2628c5dffc31cc078582b1ec1feca64bee7c0087f459e4d8172
3
+ metadata.gz: 684776c3daf8185ae8be30ecc9afbeacdb216190f4f7c9d080ff3d8acc7bf5cb
4
+ data.tar.gz: b577efaddd5424680968a77acefaad54217cca76665a936c18f5083d8d4b8289
5
5
  SHA512:
6
- metadata.gz: f46fcfb9b5869a7f7bfd1e797752731bb7850bcd81f62209a878703504b578f9f4333bda6ed67db235c29c638e8af095d23f8588c1cd402c490b406a0ef19047
7
- data.tar.gz: b7a6f96e3899a947d6423bdf6877dc539bbf16c7de569ec39e4c5761092c995fcaebc88f9f4e110aaee200df91eacf681e24fc4470cb56302eb3e0f7a4691f9c
6
+ metadata.gz: 2c13a0b3baad7d55e1c21b02d6be5d9a023e0f119265f57cc604b628711ac9639825505259e362c3f5be3035eec0f3be0523841de48dff6b4184a30a8f3185f7
7
+ data.tar.gz: a6ff5b3f26ea143eceb6068e76c28fce4622ffd8393fd63b45fc78404e2c28d0be755f6cdddd22cd0f53237892b712e7c7bee406dc23136e01259135fd96ea5a
@@ -17,7 +17,7 @@ module Wisco
17
17
  config_path = Wisco.config_path(target_dir)
18
18
 
19
19
  unless File.exist?(config_path)
20
- warn "Error: No #{Wisco::WISCO_DIR}/#{Wisco::CONFIG_FILENAME} found in #{target_dir}."
20
+ Wisco::TerminalOutput.emit_error "Error: No #{Wisco::WISCO_DIR}/#{Wisco::CONFIG_FILENAME} found in #{target_dir}."
21
21
  warn " Run '#{Wisco::CLI_NAME} init' first."
22
22
  exit 1
23
23
  end
@@ -27,7 +27,7 @@ module Wisco
27
27
  connector_file = config.dig('connector', 'file')
28
28
 
29
29
  if connector_path.nil? || connector_file.nil?
30
- warn "Error: #{Wisco::WISCO_DIR}/#{Wisco::CONFIG_FILENAME} is missing connector path/file. Run '#{Wisco::CLI_NAME} init' again."
30
+ Wisco::TerminalOutput.emit_error "Error: #{Wisco::WISCO_DIR}/#{Wisco::CONFIG_FILENAME} is missing connector path/file. Run '#{Wisco::CLI_NAME} init' again."
31
31
  exit 1
32
32
  end
33
33
 
@@ -53,13 +53,13 @@ module Wisco
53
53
  cf_file = File.join(fixtures_dir, 'config_fields.json')
54
54
  cf_opt = nil # set to cf_file once the user has filled it in
55
55
 
56
- if raw_cf
56
+ if raw_cf.present?
57
57
  if config_fields_ready?(cf_file)
58
58
  cf_opt = cf_file
59
59
  else
60
60
  write_config_fields_template(raw_cf, cf_file)
61
61
  warn " Written: #{cf_file}"
62
- warn " Action required: fill in config_fields.json, then re-run fixtures."
62
+ Wisco::TerminalOutput.emit_warning(" Action required: fill in config_fields.json, then re-run fixtures.")
63
63
  next
64
64
  end
65
65
  end
@@ -231,7 +231,7 @@ module Wisco
231
231
 
232
232
  def read_json_without_sentinel(path)
233
233
  lines = File.readlines(path)
234
- lines.shift if lines.first&.chomp == SENTINEL
234
+ lines.shift while lines.first&.lstrip&.start_with?('#')
235
235
  JSON.parse(lines.join)
236
236
  rescue StandardError
237
237
  {}
@@ -251,10 +251,29 @@ module Wisco
251
251
  def write_config_fields_template(config_fields_array, output_file)
252
252
  stringified = stringify_keys_deep(config_fields_array)
253
253
  template = schema_to_template(stringified)
254
- content = "#{SENTINEL}\n#{JSON.pretty_generate(template)}\n"
254
+ comments = build_config_fields_comments(stringified)
255
+ content = "#{SENTINEL}\n#{comments}#{JSON.pretty_generate(template)}\n"
255
256
  File.write(output_file, content)
256
257
  end
257
258
 
259
+ def build_config_fields_comments(fields)
260
+ return '' if fields.empty?
261
+
262
+ lines = ['# Config fields:']
263
+ fields.each do |field|
264
+ parts = []
265
+ parts << "label: #{field['label'].inspect}" if field['label']
266
+ parts << "hint: #{field['hint'].inspect}" if field['hint']
267
+ parts << "type: #{field['type'] || 'string'}"
268
+ parts << (field.fetch('optional', true) ? 'optional' : 'required')
269
+ parts << "control_type: #{field['control_type']}" if field['control_type']
270
+ parts << "pick_list: #{field['pick_list']}" if field['pick_list']
271
+ lines << "# #{field['name']}: #{parts.join(', ')}"
272
+ end
273
+ lines << '#'
274
+ lines.map { |l| "#{l}\n" }.join
275
+ end
276
+
258
277
  def stringify_keys_deep(obj)
259
278
  case obj
260
279
  when Hash then obj.transform_keys(&:to_s).transform_values { |v| stringify_keys_deep(v) }
@@ -0,0 +1,22 @@
1
+ module Wisco
2
+ module TerminalOutput
3
+ RED = 31
4
+ YELLOW = 33
5
+
6
+ module_function
7
+
8
+ def emit_error(message)
9
+ warn(colorize(message, RED))
10
+ end
11
+
12
+ def emit_warning(message)
13
+ warn(colorize(message, YELLOW))
14
+ end
15
+
16
+ def colorize(message, color_code)
17
+ return message unless $stderr.tty?
18
+
19
+ "\e[#{color_code}m#{message}\e[0m"
20
+ end
21
+ end
22
+ end
data/lib/wisco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wisco
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
data/lib/wisco.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'thor'
3
3
  require_relative 'wisco/version'
4
+ require_relative 'wisco/terminal_output'
4
5
 
5
6
  module Wisco
6
7
  CLI_NAME = 'wisco'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wisco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - mbillington
@@ -73,6 +73,7 @@ files:
73
73
  - lib/wisco/config.rb
74
74
  - lib/wisco/connector.rb
75
75
  - lib/wisco/path_utils.rb
76
+ - lib/wisco/terminal_output.rb
76
77
  - lib/wisco/version.rb
77
78
  - lib/wisco/workato_api.rb
78
79
  homepage: https://github.com/billingtonm/wisco