Revision bef0fdde

View differences:

src/cli/cli_helper.rb
166 166
                (0..ncolumns-1).collect{ |i|
167 167
                    dat=l[i]
168 168
                    col=@default_columns[i]
169

  
170
                    if @columns[col] && @columns[col][:humanize]
171
                        dat = @columns[col][:humanize].call(dat)
172
                    end
173

  
174 169
                    format_str(col, dat)
175 170
                }.join(' ')
176 171
            }.join("\n")
......
193 188
        end
194 189

  
195 190
        def format_str(field, data)
196
            minus=( @columns[field][:left] ? "-" : "" )
197
            size=@columns[field][:size]
198
            "%#{minus}#{size}.#{size}s" % [ data.to_s ]
191
            if @columns[field]
192
                minus=( @columns[field][:left] ? "-" : "" )
193
                size=@columns[field][:size]
194
                return "%#{minus}#{size}.#{size}s" % [ data.to_s ]
195
            else
196
                puts "Column not defined"
197
                exit -1
198
            end
199 199
        end
200 200

  
201 201
        def update_columns(options)
202
            config = YAML.load_file(@conf)
202
            begin
203
                config = YAML.load_file(@conf)
203 204

  
204
            default = config.delete(:default)
205
            @default_columns = default unless default.empty?
205
                default = config.delete(:default)
206
                @default_columns = default unless default.empty?
206 207

  
207
            @default_columns = options[:list].collect{|o| o.to_sym} if options[:list]
208
                @columns.merge!(config) { |key, oldval, newval|
209
                    oldval.merge(newval)
210
                }
211
            rescue Exception => e
212
            end
208 213

  
209
            @columns.merge!(config) { |key, oldval, newval|
210
                oldval.merge(newval)
211
            }
214
            @default_columns = options[:list].collect{|o| o.to_sym} if options[:list]
212 215
        end
213 216

  
214 217
        def header_str
......
216 219
                if @columns[c]
217 220
                    format_str(c, c.to_s)
218 221
                else
219
                    ""
222
                    puts "Column not defined"
223
                    exit -1
220 224
                end
221 225
            }.compact.join(' ')
222 226
        end

Also available in: Unified diff