Class: Aspera::Transfer::SpecDoc
- Inherits:
-
Object
- Object
- Aspera::Transfer::SpecDoc
- Defined in:
- lib/aspera/transfer/spec_doc.rb
Overview
translate transfer specification to ascp parameter list
Constant Summary collapse
- AGENT_LIST =
Agents shown in manual for parameters (sub list)
Agent::Factory.instance.list.map do |agent_sym| [agent_sym, agent_sym.to_s.capitalize, agent_to_short(agent_sym)] end.sort_by(&:last).freeze
Class Method Summary collapse
-
.agent_to_short(agent_sym) ⇒ Object
first letter of agent name symbol.
-
.man_table(formatter, include_option: false, agent_columns: true, schema: Spec::SCHEMA) ⇒ Array
A table suitable to display in manual.
Class Method Details
.agent_to_short(agent_sym) ⇒ Object
first letter of agent name symbol
11 12 13 |
# File 'lib/aspera/transfer/spec_doc.rb', line 11 def agent_to_short(agent_sym) agent_sym.to_sym.eql?(:direct) ? :a : agent_sym.to_s[0].to_sym end |
.man_table(formatter, include_option: false, agent_columns: true, schema: Spec::SCHEMA) ⇒ Array
Returns a table suitable to display in manual.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/aspera/transfer/spec_doc.rb', line 20 def man_table(formatter, include_option: false, agent_columns: true, schema: Spec::SCHEMA) col_local = agent_to_short(:direct) cols = %i[name type description] cols.insert(-2, *AGENT_LIST.map(&:last)) if agent_columns rows = [] schema['properties'].each do |name, info| if info['type'].eql?('object') && info['properties'] rows.concat(man_table(formatter, include_option: include_option, agent_columns: agent_columns, schema: info).last.map { |h| h.merge(name: "#{name}.#{h[:name]}") }) end # manual table columns = { name: name, type: info['type'], description: [] } # replace "back solidus" HTML entity with its text value, highlight keywords, and split lines columns[:description] = info['description'] .gsub('\', '\\') .gsub(/`([a-z0-9_.+-]+)`/){formatter.keyword_highlight(Regexp.last_match(1))} .split("\n") if info.key?('description') columns[:description].unshift("DEPRECATED: #{info['x-deprecation']}") if info.key?('x-deprecation') # add flags for supported agents in doc agents = [] AGENT_LIST.each do |agent_info| agents.push(agent_info.last) if info['x-agents'].nil? || info['x-agents'].include?(agent_info.first.to_s) end Aspera.assert(agents.include?(col_local)){"#{name}: x-cli-option requires agent direct (or nil)"} if info['x-cli-option'] if agent_columns AGENT_LIST.each do |agent_info| columns[agent_info.last] = formatter.tick(agents.include?(agent_info.last)) end else columns[:description].push("(#{agents.map(&:upcase).join(', ')})") unless agents.length.eql?(AGENT_LIST.length) end # only keep lines that are usable in supported agents next false if agents.empty? columns[:description].push("Allowed values: #{info['enum'].map{ |v| formatter.keyword_highlight(v)}.join(', ')}") if info.key?('enum') if include_option envvar_prefix = '' cli_option = if info.key?('x-cli-envvar') envvar_prefix = 'env:' info['x-cli-envvar'] elsif info['x-cli-switch'] info['x-cli-option'] elsif info['x-cli-option'] arg_type = info.key?('enum') ? '{enum}' : "{#{[info['type']].flatten.join('|')}}" # conversion_tag = info['x-cli-convert'] conversion_tag = info.key?('x-cli-convert') ? 'conversion' : nil sep = info['x-cli-option'].start_with?('--') ? '=' : ' ' "#{info['x-cli-option']}#{sep}#{"(#{conversion_tag})" if conversion_tag}#{arg_type}" end columns[:description].push("(#{'special:' if info['x-cli-special']}#{envvar_prefix}#{formatter.keyword_highlight(cli_option)})") if cli_option end rows.push(formatter.check_row(columns)) end [cols, rows.sort_by{ |i| i[:name]}] end |