cli-format 0.2.2 → 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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/cli_format/presenter/markdown.rb +20 -0
- data/lib/cli_format/presenter/space.rb +41 -0
- data/lib/cli_format/presenter.rb +5 -3
- data/lib/cli_format/version.rb +1 -1
- data/lib/cli_format.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '082a3544f56a8fe91e0250769c433422dc4c02a045dca8e9f7e374ca954e4aab'
|
4
|
+
data.tar.gz: '09d4753e88d4055d96e3c0028ea15a61764c0f65dc8699671cbb174abeaff9e7'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e557258c906638acfa29d8b7b459b5f423bf1a0c5bc71fa80a4cedf518d45214157f210c03f2c1d9119c1d40a85c58d270ea8acdeb85055f212fc17328478270
|
7
|
+
data.tar.gz: f4c036785d8a0590985dbd8ec2a5c1aa73f258645e4adf364d3a79f6b0b75e43fc6ac705ce710e2aed97ce06f4e57010df5b04aa67b0426411617f4c2b5596f9
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely* adheres to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [0.4.0] - 2023-10-04
|
7
|
+
- [#4](https://github.com/boltops-tools/cli-format/pull/4) markdown format support
|
8
|
+
|
9
|
+
## [0.3.0] - 2023-09-26
|
10
|
+
- [#3](https://github.com/boltops-tools/cli-format/pull/3) space format
|
11
|
+
|
6
12
|
## [0.2.2] - 2022-02-15
|
7
13
|
- [#2](https://github.com/boltops-tools/cli-format/pull/2) add equal format
|
8
14
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CliFormat::Presenter
|
2
|
+
class Markdown < Space
|
3
|
+
def text
|
4
|
+
if @header
|
5
|
+
@buffer << format_row(@header, max_widths)
|
6
|
+
second_line = @header.map { |h| "---" }
|
7
|
+
@buffer << format_row(second_line, max_widths)
|
8
|
+
end
|
9
|
+
@rows.each do |row|
|
10
|
+
@buffer << format_row(row, max_widths)
|
11
|
+
end
|
12
|
+
@buffer.join("\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
# interface method
|
16
|
+
def formatted_row_separator
|
17
|
+
" | "
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class CliFormat::Presenter
|
2
|
+
class Space < Base
|
3
|
+
extend Memoist
|
4
|
+
|
5
|
+
def text
|
6
|
+
@buffer << format_row(@header, max_widths) if @header
|
7
|
+
@rows.each do |row|
|
8
|
+
@buffer << format_row(row, max_widths)
|
9
|
+
end
|
10
|
+
|
11
|
+
@buffer.join("\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
def max_widths
|
15
|
+
all_rows = [@header, *@rows].compact
|
16
|
+
max_widths = Array.new(all_rows[0].size, 0)
|
17
|
+
|
18
|
+
all_rows.each do |row|
|
19
|
+
row.each_with_index do |col, idx|
|
20
|
+
max_widths[idx] = [max_widths[idx], col.to_s.length].max
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
max_widths
|
25
|
+
end
|
26
|
+
memoize :max_widths
|
27
|
+
|
28
|
+
def format_row(row, max_widths)
|
29
|
+
formatted_row = row.each_with_index.map do |col, idx|
|
30
|
+
idx == row.size - 1 ? col.to_s : col.to_s.ljust(max_widths[idx])
|
31
|
+
end
|
32
|
+
|
33
|
+
formatted_row.join(formatted_row_separator)
|
34
|
+
end
|
35
|
+
|
36
|
+
# interface method
|
37
|
+
def formatted_row_separator
|
38
|
+
" "
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/cli_format/presenter.rb
CHANGED
@@ -6,10 +6,12 @@ module CliFormat
|
|
6
6
|
@rows = []
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
delegate :text, :show, to: :presenter
|
10
|
+
|
11
|
+
def presenter
|
12
|
+
return @presenter if @presenter
|
10
13
|
presenter_class = "CliFormat::Presenter::#{format.camelize}".constantize
|
11
|
-
presenter = presenter_class.new(@options, @header, @rows)
|
12
|
-
presenter.show
|
14
|
+
@presenter = presenter_class.new(@options, @header, @rows)
|
13
15
|
end
|
14
16
|
|
15
17
|
# Formats: tabs, markdown, json, csv, table, etc
|
data/lib/cli_format/version.rb
CHANGED
data/lib/cli_format.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -120,6 +120,8 @@ files:
|
|
120
120
|
- lib/cli_format/presenter/csv.rb
|
121
121
|
- lib/cli_format/presenter/equal.rb
|
122
122
|
- lib/cli_format/presenter/json.rb
|
123
|
+
- lib/cli_format/presenter/markdown.rb
|
124
|
+
- lib/cli_format/presenter/space.rb
|
123
125
|
- lib/cli_format/presenter/tab.rb
|
124
126
|
- lib/cli_format/presenter/table.rb
|
125
127
|
- lib/cli_format/version.rb
|
@@ -143,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
145
|
- !ruby/object:Gem::Version
|
144
146
|
version: '0'
|
145
147
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
148
|
+
rubygems_version: 3.4.17
|
147
149
|
signing_key:
|
148
150
|
specification_version: 4
|
149
151
|
summary: 'Format cli output in different ways: tab, table, csv, json, etc'
|