wisco 0.3.9 → 0.4.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: b4b85a40b2a730027328f11d2ad3689c278450ed80f84f4a6348d8e4ed0f011a
4
- data.tar.gz: 3b2798e4939b06bd8c7171bd1cecfb962f0f570d110b13e00324d91a4b8c7241
3
+ metadata.gz: 9d0223c07b265d6b699acec69facb0abc3cded752a3b99791454507bf8623490
4
+ data.tar.gz: 82b76acb11a65728840067d60bb809f0fb4f88421b0efeac922b967915cef2dc
5
5
  SHA512:
6
- metadata.gz: 4a933e918f07db02c27d52169ddcb846d956a1d9ed528a8ac42fcc65c79c72c39648e0ff1da8c0053832f486b0fcce99eaf3e5d349175f507a85d7e9c56592dd
7
- data.tar.gz: 1d76c173b1a1ef13a95e24e4e6c879e14aa82a6d26ea910bb4fb4caf56bdd81d3f088df2390e7aa1d55ebb92c2de6a4463972be24d8421118707fd45f3c94382
6
+ metadata.gz: 91cae2af261537aa28ab79a66f817fc4095f06c7d2f7cc16281e181872e4d5101b09386cc31793b1d8da09dbf03040946d2b162c41d3705062c4a7b77a5bd7a9
7
+ data.tar.gz: 8355aa7b644b559c082d656ca19134b3af9c3a2803f1e31ba7e27b4a31d11af9ea1788a558f259e69d7c4d0af88b5e6f27abf19d223b312c1aa1c273cda93d9b
@@ -12,9 +12,14 @@ module Wisco
12
12
 
13
13
  module_function
14
14
 
15
- def run(subcommand, target, sort: nil)
15
+ def run(subcommand, target, sort: nil, format: nil)
16
16
  validate_sort!(sort)
17
17
 
18
+ if format
19
+ run_formatted(target, format: format)
20
+ return
21
+ end
22
+
18
23
  case subcommand
19
24
  when nil then run_tree(target)
20
25
  when 'actions' then run_actions(target, sort: sort)
@@ -93,6 +98,69 @@ module Wisco
93
98
  run_triggers(target_dir, sort: sort)
94
99
  end
95
100
 
101
+ # ---------------------------------------------------------------------------
102
+ # Machine-readable output
103
+ # ---------------------------------------------------------------------------
104
+
105
+ def run_formatted(target_dir, format:)
106
+ require 'yaml' if format.downcase == 'yaml'
107
+ connector = Wisco::Connector.load_connector_from_config(target_dir)
108
+ data = build_connector_hash(connector)
109
+ if format.downcase == 'yaml'
110
+ puts data.to_yaml
111
+ else
112
+ puts JSON.pretty_generate(data)
113
+ end
114
+ end
115
+
116
+ def build_connector_hash(connector)
117
+ {
118
+ 'title' => connector[:title].to_s,
119
+ 'connection' => build_connection(connector[:connection]),
120
+ 'actions' => build_section(connector[:actions]),
121
+ 'triggers' => build_section(connector[:triggers]),
122
+ 'methods' => (connector[:methods] || {}).keys.map(&:to_s).sort,
123
+ 'pick_lists' => (connector[:pick_lists] || {}).keys.map(&:to_s).sort
124
+ }
125
+ end
126
+
127
+ def build_connection(conn)
128
+ return { 'fields' => [] } unless conn.is_a?(Hash)
129
+
130
+ fields = conn[:fields] || []
131
+ { 'fields' => fields.map { |f| safe_serialize(f) }.compact }
132
+ end
133
+
134
+ def build_section(section)
135
+ return {} unless section.is_a?(Hash)
136
+
137
+ section.keys.sort_by(&:to_s).each_with_object({}) do |key, h|
138
+ item = section[key]
139
+ h[key.to_s] = {
140
+ 'title' => title_for(key, item),
141
+ 'subtitle' => subtitle_for(item).to_s
142
+ }
143
+ end
144
+ end
145
+
146
+ # Recursively converts a connector value to a JSON-safe structure.
147
+ # Proc/lambda values are dropped (returned as nil so callers can compact).
148
+ def safe_serialize(value)
149
+ case value
150
+ when Hash
151
+ value.each_with_object({}) do |(k, v), h|
152
+ next if v.is_a?(Proc)
153
+
154
+ serialized = safe_serialize(v)
155
+ h[k.to_s] = serialized
156
+ end
157
+ when Array then value.map { |v| safe_serialize(v) }
158
+ when Proc then nil
159
+ when Symbol then value.to_s
160
+ else value
161
+ end
162
+ end
163
+
96
164
  # ---------------------------------------------------------------------------
97
165
  # List utilities
98
166
  # ---------------------------------------------------------------------------
data/lib/wisco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wisco
2
- VERSION = '0.3.9'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/wisco.rb CHANGED
@@ -68,13 +68,14 @@ module Wisco
68
68
  all Show tree + actions + triggers
69
69
  PATH defaults to the current directory.
70
70
  DESC
71
- option :sort, type: :string, desc: 'Sort actions/triggers by key or title', enum: %w[key title]
71
+ option :sort, type: :string, desc: 'Sort actions/triggers by key or title', enum: %w[key title]
72
+ option :format, type: :string, desc: 'Machine-readable output format (use with "all")', enum: %w[json yaml]
72
73
  def list(subcommand = nil, path = nil)
73
74
  if subcommand&.match?(%r{^[./~\\]|^[A-Za-z]:[/\\]})
74
75
  path = subcommand
75
76
  subcommand = nil
76
77
  end
77
- Wisco::Commands::List.run(subcommand, path || Dir.pwd, sort: options[:sort])
78
+ Wisco::Commands::List.run(subcommand, path || Dir.pwd, sort: options[:sort], format: options[:format])
78
79
  end
79
80
 
80
81
  desc 'exec PATH [TARGET_DIR]', 'Execute connector methods against fixture data'
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.3.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mbillington