This repository has been archived by the owner on Dec 16, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
207 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'optparse' | ||
require_relative File.join('..', 'lib', 'snmp_table_viewer') | ||
|
||
def parse_command_line | ||
options = { | ||
SNMPTableViewer::Formatter::Table => { | ||
transpose: false, | ||
}, | ||
headings: [], | ||
formatter: SNMPTableViewer::Formatter::Table, | ||
} | ||
|
||
parser = OptionParser.new do |opts| | ||
opts.banner = "Usage: table-from-stdin [options]" | ||
|
||
opts.on('-h', '--help', '-?', 'Prints this help.') do | ||
puts opts | ||
exit | ||
end | ||
|
||
opts.on('--headings HEADINGS', Array, 'Headings to use in the table (e.g. "A, Bc, D").') do |v| | ||
options[:headings] += v.map(&:strip) | ||
end | ||
|
||
opts.on('--headings-for TYPE', String, "Use headings for this table type (#{SNMPTableViewer::HEADINGS_FOR.keys.join('|')}).") do |v| | ||
options[:headings] += SNMPTableViewer::HEADINGS_FOR[v] || [] | ||
end | ||
|
||
opts.on('--format FORMAT', String, "How to format the output (#{SNMPTableViewer::FORMATTERS.keys.join('|')}) (default table).") do |v| | ||
options[:formatter] = SNMPTableViewer::FORMATTERS[v.downcase] | ||
end | ||
|
||
opts.on('--converter CONVERTER', String, "A converter to run on the data before formatting (#{SNMPTableViewer::CONVERTERS.keys.join('|')}).") do |v| | ||
options[:converter] = SNMPTableViewer::CONVERTERS[v.downcase] | ||
end | ||
|
||
|
||
opts.separator "\nTable formatter options:" | ||
opts.on('--[no-]transpose-table', 'Transpose the output table (swap rows and columns).') do |v| | ||
options[SNMPTableViewer::Formatter::Table][:transpose] = v | ||
end | ||
|
||
end # create parser | ||
|
||
parser.parse!(ARGV) | ||
options | ||
end | ||
|
||
|
||
options = parse_command_line | ||
data = STDIN.readlines.map(&:strip) | ||
data = SNMPTableViewer::Fetcher.from_array(data) | ||
|
||
converter = options[:converter] | ||
data = converter.convert(data) unless converter.nil? | ||
|
||
formatter = options[:formatter] | ||
formatter_options = options[formatter] || {} | ||
formatter = formatter.new(data: data, headings: options[:headings]) | ||
puts formatter.output(**formatter_options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module SNMPTableViewer | ||
VERSION = "0.0.4" | ||
VERSION = "0.0.5" | ||
end |