Class: ZonePrint

Inherits:
Command show all
Defined in:
lib/zone.rb

Instance Attribute Summary

Attributes inherited from Command

#desc, #name

Instance Method Summary collapse

Methods inherited from Command

#add_arg, #add_cmd, #add_flow, #add_flow_from_usage, #add_input, #add_option, #command_name?, #create_args, #create_flows, #flow_passes_parse, #flow_passes_preconditions, #get_args_used, #initialize, #option_help_string, #run, #show_help, #show_help_option

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#add_options ⇒ Object



82
83
84
85
86
87
88
# File 'lib/zone.rb', line 82

def add_options 
  add_option({ short_name: 'j', long_name: 'json', method: :set_format_json, takes_value: false})
  add_option({ short_name: 't', long_name: 'type', method: :set_format, takes_value: ["csv", "json"]})
  add_option({ short_name: 'n', long_name: 'no-header', method: :unset_header, takes_value: false})
  add_option({ short_name: 'c', long_name: 'columns', method: :set_columns, takes_value: /[[:alpha:],]+|\*/, regexp_description: "comma separated column names, or * for all columns"})
  # add_option({ short_name: 'f', long_name: 'force-online', method: :force_online, takes_value: false})
end

#execute(args, rest) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/zone.rb', line 106

def execute(args, rest)
  struct = @input["struct"]
  level = @input["level"]
  sep_char = @input["sep_char"]
  if @format == :json
    puts JSON.pretty_generate(struct)
  else
    StructurePrint.new(sep_char, @header, @format, @columns).structure_print(struct, level)
  end
end

#init ⇒ Object



77
78
79
80
# File 'lib/zone.rb', line 77

def init
  @header = true
  @format = nil
end

#set_columns(column_list) ⇒ Object



102
103
104
# File 'lib/zone.rb', line 102

def set_columns(column_list)
  @columns = column_list
end

#set_format(format) ⇒ Object



98
99
100
# File 'lib/zone.rb', line 98

def set_format(format)
  @format = format.to_sym
end

#set_format_json ⇒ Object



94
95
96
# File 'lib/zone.rb', line 94

def set_format_json
  @format = :json
end

#unset_header ⇒ Object



90
91
92
# File 'lib/zone.rb', line 90

def unset_header
  @header = false
end