cli-format 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +10 -4
- data/lib/cli_format/presenter.rb +1 -1
- data/lib/cli_format/version.rb +1 -1
- data/lib/cli_format.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cc42997cc91028ae2aa592dd9a11092ad911cf676e67e4466bd31c1f2adcdeb
|
4
|
+
data.tar.gz: 0ff02cc5a9ca4394f3b7f72b76fc9b11555c084864b97d712eeba513930506bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e238aa9201e7e32e7efac040756e66b92c4ecde8ba2c1a04598747a75a778eda8cd559673a941109433c3a956bae2f3dc9e92477b6f31250a246103bb37fa0b2
|
7
|
+
data.tar.gz: 251775062d7fa8545efcb95e97e3ae3c309be90061d9692c8552493e348ec3d7c8d9d08018ed2a189133a355ef519c58adb42e0332788738f6d515a4cd36aede
|
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.5.0] - 2023-12-02
|
7
|
+
- make options optional
|
8
|
+
|
9
|
+
## [0.4.0] - 2023-10-04
|
10
|
+
- [#4](https://github.com/boltops-tools/cli-format/pull/4) markdown format support
|
11
|
+
|
6
12
|
## [0.3.0] - 2023-09-26
|
7
13
|
- [#3](https://github.com/boltops-tools/cli-format/pull/3) space 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
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class CliFormat::Presenter
|
2
2
|
class Space < Base
|
3
|
-
|
4
|
-
max_widths = calculate_max_widths
|
3
|
+
extend Memoist
|
5
4
|
|
5
|
+
def text
|
6
6
|
@buffer << format_row(@header, max_widths) if @header
|
7
7
|
@rows.each do |row|
|
8
8
|
@buffer << format_row(row, max_widths)
|
@@ -11,7 +11,7 @@ class CliFormat::Presenter
|
|
11
11
|
@buffer.join("\n")
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def max_widths
|
15
15
|
all_rows = [@header, *@rows].compact
|
16
16
|
max_widths = Array.new(all_rows[0].size, 0)
|
17
17
|
|
@@ -23,13 +23,19 @@ class CliFormat::Presenter
|
|
23
23
|
|
24
24
|
max_widths
|
25
25
|
end
|
26
|
+
memoize :max_widths
|
26
27
|
|
27
28
|
def format_row(row, max_widths)
|
28
29
|
formatted_row = row.each_with_index.map do |col, idx|
|
29
30
|
idx == row.size - 1 ? col.to_s : col.to_s.ljust(max_widths[idx])
|
30
31
|
end
|
31
32
|
|
32
|
-
formatted_row.join(
|
33
|
+
formatted_row.join(formatted_row_separator)
|
34
|
+
end
|
35
|
+
|
36
|
+
# interface method
|
37
|
+
def formatted_row_separator
|
38
|
+
" "
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
data/lib/cli_format/presenter.rb
CHANGED
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.5.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: 2023-
|
11
|
+
date: 2023-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -120,6 +120,7 @@ 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
|
123
124
|
- lib/cli_format/presenter/space.rb
|
124
125
|
- lib/cli_format/presenter/tab.rb
|
125
126
|
- lib/cli_format/presenter/table.rb
|
@@ -144,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
145
|
- !ruby/object:Gem::Version
|
145
146
|
version: '0'
|
146
147
|
requirements: []
|
147
|
-
rubygems_version: 3.4.
|
148
|
+
rubygems_version: 3.4.20
|
148
149
|
signing_key:
|
149
150
|
specification_version: 4
|
150
151
|
summary: 'Format cli output in different ways: tab, table, csv, json, etc'
|