wisco 0.2.6 → 0.3.0

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: e7d2ff5de3204724be5413d65d04854a3abbf36b9d04d0fe2331512ba74f6e68
4
+ data.tar.gz: 81791bed785af9f096dae7de781a3620a14a96f4a28dc3514d24b4bdabc80e1c
5
5
  SHA512:
6
- metadata.gz: f46fcfb9b5869a7f7bfd1e797752731bb7850bcd81f62209a878703504b578f9f4333bda6ed67db235c29c638e8af095d23f8588c1cd402c490b406a0ef19047
7
- data.tar.gz: b7a6f96e3899a947d6423bdf6877dc539bbf16c7de569ec39e4c5761092c995fcaebc88f9f4e110aaee200df91eacf681e24fc4470cb56302eb3e0f7a4691f9c
6
+ metadata.gz: b4e9a41746dc88a8ef8d08595dd56c01bae20fcbabaefd6bd08758ab4d2fa8611745a3cce8c8a929a4a433fa76458a821ecf074f96720e30b824d98a9005c51c
7
+ data.tar.gz: d5f6560ffec23678d08131a232808f957b4aec436bd17ff87822fd45fcf6fb1bd06d9a438ba76a1904cf6eb6babb7344c1ca7d206f3c042843144f7c917e355b
@@ -10,7 +10,7 @@ module Wisco
10
10
  module Exec
11
11
  module_function
12
12
 
13
- def run(path_arg, target_dir, input: nil, pagination: true, debug: false)
13
+ def run(path_arg, target_dir, input: nil, pagination: true, verbose: true, debug: false)
14
14
  target_dir = File.expand_path(target_dir)
15
15
  config_path = Wisco.config_path(target_dir)
16
16
 
@@ -32,6 +32,12 @@ module Wisco
32
32
  connector_full_path = File.join(connector_path, connector_file)
33
33
  connection = config['connection']
34
34
 
35
+ # ── connection test short-circuit ──────────────────────────────────
36
+ if path_arg == 'test'
37
+ run_test(target_dir, connector_full_path, connection, verbose: verbose, debug: debug)
38
+ return
39
+ end
40
+
35
41
  connector = Wisco::Connector.load_connector_from_config(target_dir)
36
42
  pairs = Wisco::PathUtils.parse_path(path_arg, connector)
37
43
 
@@ -52,7 +58,7 @@ module Wisco
52
58
  if %w[pick_lists methods].include?(section)
53
59
  # No-param pick list or method — execute once with no input file
54
60
  execute_one(section, key, nil, fixtures_dir, connector_full_path, connection,
55
- pagination: pagination, debug: debug)
61
+ pagination: pagination, verbose: verbose, debug: debug)
56
62
  else
57
63
  warn "\tWarning: No ready input files found in #{fixture_dir_output}"
58
64
  end
@@ -61,7 +67,7 @@ module Wisco
61
67
 
62
68
  input_files.each do |input_file|
63
69
  execute_one(section, key, input_file, fixtures_dir,
64
- connector_full_path, connection, pagination: pagination, debug: debug)
70
+ connector_full_path, connection, pagination: pagination, verbose: verbose, debug: debug)
65
71
  end
66
72
  end
67
73
  end
@@ -93,8 +99,45 @@ module Wisco
93
99
  first_line == Wisco::Commands::Fixtures::SENTINEL
94
100
  end
95
101
 
102
+ def run_test(target_dir, connector_full_path, connection, verbose: true, debug: false)
103
+ puts "Testing connection"
104
+ fixtures_dir = File.join(target_dir, 'fixtures', 'connection', 'test')
105
+ FileUtils.mkdir_p(fixtures_dir)
106
+
107
+ output_file = File.join(fixtures_dir, 'output_test.json')
108
+ error_file = File.join(fixtures_dir, 'error_test.txt')
109
+
110
+ options = { connector: connector_full_path, output: output_file }
111
+ options[:connection] = connection if connection
112
+ options[:verbose] = verbose
113
+
114
+ if debug
115
+ warn "[exec] path: test"
116
+ warn "[exec] connector: #{connector_full_path}"
117
+ warn "[exec] connection: #{connection.inspect}"
118
+ warn "[exec] output: #{output_file}"
119
+ end
120
+
121
+ begin
122
+ cmd = Workato::CLI::ExecCommand.new(path: 'test', options: options)
123
+ cmd.call
124
+ rescue StandardError => e
125
+ File.write(error_file, "#{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}\n")
126
+ warn "Error testing connection: #{e.message}"
127
+ warn " Details written to: #{error_file}"
128
+ return
129
+ end
130
+
131
+ FileUtils.rm_f(error_file)
132
+ return unless File.exist?(output_file)
133
+
134
+ pretty = JSON.pretty_generate(JSON.parse(File.read(output_file)))
135
+ File.write(output_file, pretty + "\n")
136
+ puts " Written: #{output_file}"
137
+ end
138
+
96
139
  def execute_one(section, key, input_file, fixtures_dir, connector_full_path, connection,
97
- pagination: true, debug: false)
140
+ pagination: true, verbose: true, debug: false)
98
141
  stem = input_file ? File.basename(input_file, '.*') : 'execute'
99
142
  output_file = File.join(fixtures_dir, "output_#{stem}.json")
100
143
  error_file = File.join(fixtures_dir, "error_#{stem}.txt")
@@ -110,6 +153,7 @@ module Wisco
110
153
 
111
154
  options = { connector: connector_full_path, output: output_file }
112
155
  options[:connection] = connection if connection
156
+ options[:verbose] = verbose
113
157
  if use_args
114
158
  options[:args] = input_file if input_file
115
159
  else
@@ -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.3.0'
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'
@@ -85,6 +86,7 @@ module Wisco
85
86
  option :input, type: :string, desc: 'Specific input file'
86
87
  option :pagination, type: :boolean, default: true,
87
88
  desc: 'Triggers only: true = .poll (with pagination), false = .poll_page (without)'
89
+ option :verbose, type: :boolean, default: true, desc: 'Enable detailed SDK logging'
88
90
  option :debug, type: :boolean, default: false, desc: 'Print ExecCommand call details'
89
91
  def exec(path_arg, target_dir = nil)
90
92
  Wisco::Commands::Exec.run(
@@ -92,6 +94,7 @@ module Wisco
92
94
  target_dir || Dir.pwd,
93
95
  input: options[:input],
94
96
  pagination: options[:pagination],
97
+ verbose: options[:verbose],
95
98
  debug: options[:debug]
96
99
  )
97
100
  end
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.3.0
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