output_mode 1.5.2 → 1.6.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/bin/bundle +114 -0
- data/bin/coderay +29 -0
- data/bin/htmldiff +29 -0
- data/bin/ldiff +29 -0
- data/bin/pry +29 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/lib/output_mode/callable.rb +10 -4
- data/lib/output_mode/default_erb.rb +23 -1
- data/lib/output_mode/non_interactive_erb.rb +41 -0
- data/lib/output_mode/outputs/tabulated.rb +6 -1
- data/lib/output_mode/tldr/show.rb +22 -22
- data/lib/output_mode/version.rb +1 -1
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4d5f1fa1744eeff5535f33a65593b370d317124736089a8b24e2d76cb824b6e
|
|
4
|
+
data.tar.gz: 10e77ade81138ebe9c6ca3e6b3299ba864c213603e54682eebb611057f72e2d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a754089932ba840c19e0070b03e99e10fd4a957e4204ee08806dde91d54d51899950f817b8a34d3736f6c1fa9df4f85321fd938909c381f12230fe53df312ed1
|
|
7
|
+
data.tar.gz: 7d5858053e4d55868893bbfa2c13ed63a52bd39f05f6b4ae690a29072c0ab7f7a4d9919204c6fd387dc2bd0ad19efec2fa5e0d023e22929452d2efa616cdf6d6
|
data/bin/bundle
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "rubygems"
|
|
12
|
+
|
|
13
|
+
m = Module.new do
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
def invoked_as_script?
|
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def env_var_version
|
|
21
|
+
ENV["BUNDLER_VERSION"]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cli_arg_version
|
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
|
27
|
+
bundler_version = nil
|
|
28
|
+
update_index = nil
|
|
29
|
+
ARGV.each_with_index do |a, i|
|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
|
31
|
+
bundler_version = a
|
|
32
|
+
end
|
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
|
34
|
+
bundler_version = $1
|
|
35
|
+
update_index = i
|
|
36
|
+
end
|
|
37
|
+
bundler_version
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def gemfile
|
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
|
43
|
+
|
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def lockfile
|
|
48
|
+
lockfile =
|
|
49
|
+
case File.basename(gemfile)
|
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
|
51
|
+
else "#{gemfile}.lock"
|
|
52
|
+
end
|
|
53
|
+
File.expand_path(lockfile)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def lockfile_version
|
|
57
|
+
return unless File.file?(lockfile)
|
|
58
|
+
lockfile_contents = File.read(lockfile)
|
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
|
60
|
+
Regexp.last_match(1)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def bundler_version
|
|
64
|
+
@bundler_version ||=
|
|
65
|
+
env_var_version || cli_arg_version ||
|
|
66
|
+
lockfile_version
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def bundler_requirement
|
|
70
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
|
71
|
+
|
|
72
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
|
73
|
+
|
|
74
|
+
requirement = bundler_gem_version.approximate_recommendation
|
|
75
|
+
|
|
76
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
|
77
|
+
|
|
78
|
+
requirement += ".a" if bundler_gem_version.prerelease?
|
|
79
|
+
|
|
80
|
+
requirement
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def load_bundler!
|
|
84
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
|
85
|
+
|
|
86
|
+
activate_bundler
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def activate_bundler
|
|
90
|
+
gem_error = activation_error_handling do
|
|
91
|
+
gem "bundler", bundler_requirement
|
|
92
|
+
end
|
|
93
|
+
return if gem_error.nil?
|
|
94
|
+
require_error = activation_error_handling do
|
|
95
|
+
require "bundler/version"
|
|
96
|
+
end
|
|
97
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
|
98
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
|
99
|
+
exit 42
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def activation_error_handling
|
|
103
|
+
yield
|
|
104
|
+
nil
|
|
105
|
+
rescue StandardError, LoadError => e
|
|
106
|
+
e
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
m.load_bundler!
|
|
111
|
+
|
|
112
|
+
if m.invoked_as_script?
|
|
113
|
+
load Gem.bin_path("bundler", "bundle")
|
|
114
|
+
end
|
data/bin/coderay
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'coderay' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "pathname"
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "rubygems"
|
|
27
|
+
require "bundler/setup"
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path("coderay", "coderay")
|
data/bin/htmldiff
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'htmldiff' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "pathname"
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "rubygems"
|
|
27
|
+
require "bundler/setup"
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path("diff-lcs", "htmldiff")
|
data/bin/ldiff
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'ldiff' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "pathname"
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "rubygems"
|
|
27
|
+
require "bundler/setup"
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path("diff-lcs", "ldiff")
|
data/bin/pry
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'pry' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "pathname"
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "rubygems"
|
|
27
|
+
require "bundler/setup"
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path("pry", "pry")
|
data/bin/rake
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "pathname"
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "rubygems"
|
|
27
|
+
require "bundler/setup"
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "pathname"
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "rubygems"
|
|
27
|
+
require "bundler/setup"
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/lib/output_mode/callable.rb
CHANGED
|
@@ -34,7 +34,9 @@ module OutputMode
|
|
|
34
34
|
@callables = []
|
|
35
35
|
case callables
|
|
36
36
|
when Array, Callables
|
|
37
|
-
callables.each
|
|
37
|
+
callables.each do |c|
|
|
38
|
+
@callables << (c.is_a?(Callable) ? c : Callable.new(&c))
|
|
39
|
+
end
|
|
38
40
|
when nil
|
|
39
41
|
# NOOP
|
|
40
42
|
else
|
|
@@ -70,14 +72,14 @@ module OutputMode
|
|
|
70
72
|
end
|
|
71
73
|
opts.empty? ? field.call(*ctx) : field.call(*ctx, **opts)
|
|
72
74
|
else
|
|
73
|
-
field
|
|
75
|
+
field
|
|
74
76
|
end
|
|
75
77
|
end
|
|
76
78
|
|
|
77
|
-
max_length = fields.map
|
|
79
|
+
max_length = fields.map { |f| f.to_s.length }.max
|
|
78
80
|
pads = self.each_with_index.map do |callable, idx|
|
|
79
81
|
field = fields[idx]
|
|
80
|
-
length = max_length - field.length
|
|
82
|
+
length = max_length - field.to_s.length
|
|
81
83
|
[callable, { padding: ' ' * length, field: field }]
|
|
82
84
|
end
|
|
83
85
|
|
|
@@ -99,6 +101,10 @@ module OutputMode
|
|
|
99
101
|
end
|
|
100
102
|
Callables.new(selected)
|
|
101
103
|
end
|
|
104
|
+
|
|
105
|
+
def length
|
|
106
|
+
@callables.length
|
|
107
|
+
end
|
|
102
108
|
end
|
|
103
109
|
|
|
104
110
|
class Callable
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
#==============================================================================
|
|
2
|
-
#
|
|
2
|
+
# Copyright 2021 William McCumstie
|
|
3
|
+
#
|
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
|
6
|
+
#
|
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer.
|
|
9
|
+
#
|
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
# and/or other materials provided with the distribution.
|
|
13
|
+
#
|
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
15
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
18
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
19
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
20
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
21
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
22
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
23
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
24
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
3
25
|
#==============================================================================
|
|
4
26
|
|
|
5
27
|
require 'erb'
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#==============================================================================
|
|
2
|
+
# Copyright 2021 William McCumstie
|
|
3
|
+
#
|
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
|
6
|
+
#
|
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer.
|
|
9
|
+
#
|
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
# and/or other materials provided with the distribution.
|
|
13
|
+
#
|
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
15
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
18
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
19
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
20
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
21
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
22
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
23
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
24
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
25
|
+
#==============================================================================
|
|
26
|
+
|
|
27
|
+
require 'erb'
|
|
28
|
+
|
|
29
|
+
module OutputMode
|
|
30
|
+
NON_INTERACTIVE_ERB = ERB.new(<<~TEMPLATE, nil, '-')
|
|
31
|
+
<% each do |value, field:, padding:, **_| -%>
|
|
32
|
+
<% if value.nil? && field.nil? -%>
|
|
33
|
+
\t
|
|
34
|
+
<% elsif field.nil? -%>
|
|
35
|
+
\t<%= value %>
|
|
36
|
+
<% else -%>
|
|
37
|
+
<%= field -%>\t<%= value.to_s.dump[1...-1] %>
|
|
38
|
+
<% end -%>
|
|
39
|
+
<% end -%>
|
|
40
|
+
TEMPLATE
|
|
41
|
+
end
|
|
@@ -77,11 +77,16 @@ module OutputMode
|
|
|
77
77
|
|
|
78
78
|
private
|
|
79
79
|
|
|
80
|
+
def has_header?
|
|
81
|
+
callables.any? { |c| c.config.key?(:header) }
|
|
82
|
+
end
|
|
83
|
+
|
|
80
84
|
# Colorizes the header when requested
|
|
81
85
|
def processed_header
|
|
86
|
+
return nil unless has_header?
|
|
82
87
|
callables.map do |callable|
|
|
83
88
|
header = callable.config.fetch(:header, '')
|
|
84
|
-
color = callable.config.fetch(:header_color) || header_color
|
|
89
|
+
color = callable.config.fetch(:header_color, nil) || header_color
|
|
85
90
|
case color
|
|
86
91
|
when nil
|
|
87
92
|
header.to_s
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
#==============================================================================
|
|
26
26
|
|
|
27
27
|
require 'tty-color'
|
|
28
|
+
require 'output_mode/default_erb'
|
|
29
|
+
require 'output_mode/non_interactive_erb'
|
|
28
30
|
|
|
29
31
|
module OutputMode
|
|
30
32
|
module TLDR
|
|
@@ -67,11 +69,15 @@ module OutputMode
|
|
|
67
69
|
# for consumption by machines. This output ignores the provided +verbose+
|
|
68
70
|
# flag as it is always verbose.
|
|
69
71
|
#
|
|
70
|
-
# The +template+ overrides the default erb template for
|
|
72
|
+
# The +template+ overrides the default erb template for interactive sessions.
|
|
73
|
+
# The +non_interactive_template+ overrides the template for non-interactive
|
|
74
|
+
# sessions.
|
|
71
75
|
#
|
|
72
76
|
# An interative/ non-interactive output can be forced by setting the
|
|
73
77
|
# +interactive+ flag to +true+/+false+ respectively
|
|
74
|
-
def build_output(verbose: nil, ascii: nil, interactive: nil,
|
|
78
|
+
def build_output(verbose: nil, ascii: nil, interactive: nil, context: {},
|
|
79
|
+
template: OutputMode::DEFAULT_ERB,
|
|
80
|
+
non_interactive_template: OutputMode::NON_INTERACTIVE_ERB)
|
|
75
81
|
# Set the interactive and verbose flags if not provided
|
|
76
82
|
interactive = $stdout.tty? if interactive.nil?
|
|
77
83
|
verbose = !interactive if verbose.nil?
|
|
@@ -96,28 +102,22 @@ module OutputMode
|
|
|
96
102
|
callables.reject { |o| o.interactive? }
|
|
97
103
|
end
|
|
98
104
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
# Define the templating parameters
|
|
106
|
+
opts = if ascii && interactive
|
|
107
|
+
{ yes: 'yes', no: 'no', colorize: false, default: '(none)', template: template }
|
|
108
|
+
elsif interactive
|
|
109
|
+
{ yes: '✓', no: '✕', colorize: TTY::Color.color?, default: '(none)', template: template }
|
|
110
|
+
else
|
|
111
|
+
{ yes: 'yes', no: 'no', colorize: false, default: '', template: non_interactive_template }
|
|
112
|
+
end
|
|
106
113
|
|
|
107
|
-
|
|
114
|
+
sections = callables.map { |o| o.config[:section] }
|
|
108
115
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
context: context,
|
|
115
|
-
**opts)
|
|
116
|
-
else
|
|
117
|
-
# Creates the machine readable output
|
|
118
|
-
Outputs::Delimited.new(*callables, col_sep: "\t", yes: 'yes', no: 'no', default: nil,
|
|
119
|
-
context: context)
|
|
120
|
-
end
|
|
116
|
+
Outputs::Templated.new(*callables,
|
|
117
|
+
fields: callables.map { |c| c.config.fetch(:header, 'missing') },
|
|
118
|
+
sections: sections,
|
|
119
|
+
context: context,
|
|
120
|
+
**opts)
|
|
121
121
|
end
|
|
122
122
|
end
|
|
123
123
|
end
|
data/lib/output_mode/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: output_mode
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- William McCumsite
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-05-
|
|
11
|
+
date: 2021-05-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: tty-table
|
|
@@ -122,14 +122,22 @@ files:
|
|
|
122
122
|
- LICENSE.txt
|
|
123
123
|
- README.md
|
|
124
124
|
- Rakefile
|
|
125
|
+
- bin/bundle
|
|
126
|
+
- bin/coderay
|
|
125
127
|
- bin/console
|
|
126
128
|
- bin/demo
|
|
129
|
+
- bin/htmldiff
|
|
130
|
+
- bin/ldiff
|
|
131
|
+
- bin/pry
|
|
132
|
+
- bin/rake
|
|
133
|
+
- bin/rspec
|
|
127
134
|
- bin/setup
|
|
128
135
|
- lib/output_mode.rb
|
|
129
136
|
- lib/output_mode/builder_dsl.rb
|
|
130
137
|
- lib/output_mode/callable.rb
|
|
131
138
|
- lib/output_mode/default_erb.rb
|
|
132
139
|
- lib/output_mode/errors.rb
|
|
140
|
+
- lib/output_mode/non_interactive_erb.rb
|
|
133
141
|
- lib/output_mode/output.rb
|
|
134
142
|
- lib/output_mode/outputs.rb
|
|
135
143
|
- lib/output_mode/outputs/delimited.rb
|