output_mode 1.0.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.
@@ -0,0 +1,34 @@
1
+ #==============================================================================
2
+ # Copyright 2020 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
+ module OutputMode
28
+ module TLDR
29
+ Dir.glob(File.expand_path('tldr/*.rb', __dir__)).each do |path|
30
+ autoload File.basename(path).chomp('.rb').capitalize, path
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,55 @@
1
+ #==============================================================================
2
+ # Refer to LICENSE.txt for licensing terms
3
+ #==============================================================================
4
+
5
+ module OutputMode
6
+ module TLDR
7
+ module Index
8
+ include BuilderDSL
9
+
10
+ # Register a new column in the Index table
11
+ # @overload register_callable(header:, verbose: true)
12
+ # @param header: The column's header field when displaying to humans
13
+ # @param verbose: Whether the column will be shown in the verbose output
14
+ # @yieldparam model The subject the column is describing, some sort of data model
15
+ def register_callable(header:, verbose: nil, &b)
16
+ super(modes: { verbose: verbose }, header: header, &b)
17
+ end
18
+
19
+ # Creates an new +output+ from the verbosity flag. This method only uses
20
+ # +$stdout+ as part of it's output class discovery logic. It does not
21
+ # print to the output directly
22
+ #
23
+ # If +$stdout+ is an interactive shell (aka a TTY), then it will display using
24
+ # {OutputMode::Outputs::Tabulated}. This is intended for human consumption
25
+ # and will obey the provided +verbose+ flag.
26
+ #
27
+ # If +$stdout+ is non-interactive, then it will display using
28
+ # {OutputMode::Outputs::Delimited} using tab delimiters. This is intended
29
+ # for consumption by machines. This output ignores the provided +verbose+
30
+ # flag as it is always verbose.
31
+ def build_output(verbose: false)
32
+ callables = if verbose || !$stdout.tty?
33
+ # Filter out columns that are explicitly not verbose
34
+ output_callables.select(&:verbose!)
35
+ else
36
+ # Filter out columns that are explicitly verbose
37
+ output_callables.reject(&:verbose?)
38
+ end
39
+
40
+ if $stdout.tty?
41
+ # Creates the human readable output
42
+ Outputs::Tabulated.new(*callables,
43
+ header: callables.map { |c| c.config.fetch(:header, 'missing') },
44
+ renderer: :unicode,
45
+ padding: [0,1],
46
+ default: '(none)',
47
+ yes: '✓', no: '✕')
48
+ else
49
+ # Creates the machine readable output
50
+ Outputs::Delimited.new(*callables, col_sep: "\t", yes: 'y', no: 'n', default: '')
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,56 @@
1
+ #==============================================================================
2
+ # Refer to LICENSE.txt for licensing terms
3
+ #==============================================================================
4
+
5
+ require 'tty-color'
6
+
7
+ module OutputMode
8
+ module TLDR
9
+ module Show
10
+ include BuilderDSL
11
+
12
+ # Register a field when displaying a model
13
+ # @overload register_callable(header:, verbose: true)
14
+ # @param header: The human readable key to the field, uses the term 'header' for consistency
15
+ # @param verbose: Whether the field will be shown in the verbose output
16
+ # @yieldparam model The subject the column is describing, some sort of data model
17
+ def register_callable(header:, verbose: nil, &b)
18
+ super(modes: { verbose: verbose }, header: header, &b)
19
+ end
20
+
21
+ # Creates an new +output+ from the verbosity flag. This method only uses
22
+ # +$stdout+ as part of it's output class discovery logic. It does not
23
+ # print to the io directly
24
+ #
25
+ # If +$stdout+ is an interactive shell (aka a TTY), then it will display using
26
+ # {OutputMode::Outputs::Templated}. This is intended for human consumption
27
+ # and will obey the provided +verbose+ flag.
28
+ #
29
+ # If +$stdout+ is non-interactive, then it will display using
30
+ # {OutputMode::Outputs::Delimited} using tab delimiters. This is intended
31
+ # for consumption by machines. This output ignores the provided +verbose+
32
+ # flag as it is always verbose.
33
+ def build_output(verbose: false)
34
+ callables = if verbose || !$stdout.tty?
35
+ # Filter out columns that are explicitly not verbose
36
+ output_callables.select(&:verbose!)
37
+ else
38
+ # Filter out columns that are explicitly verbose
39
+ output_callables.reject(&:verbose?)
40
+ end
41
+
42
+ if $stdout.tty?
43
+ # Creates the human readable output
44
+ Outputs::Templated.new(*callables,
45
+ fields: callables.map { |c| c.config.fetch(:header, 'missing') },
46
+ colorize: TTY::Color.color?,
47
+ default: '(none)',
48
+ yes: '✓', no: '✕')
49
+ else
50
+ # Creates the machine readable output
51
+ Outputs::Delimited.new(*callables, col_sep: "\t", yes: 'y', no: 'n', default: '')
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,29 @@
1
+ #==============================================================================
2
+ # Copyright 2020 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
+ module OutputMode
28
+ VERSION = "1.0.0"
29
+ end
@@ -0,0 +1,59 @@
1
+ #==============================================================================
2
+ # Copyright 2020 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
+ lib = File.expand_path("lib", __dir__)
28
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
29
+ require "output_mode/version"
30
+
31
+ Gem::Specification.new do |spec|
32
+ spec.name = "output_mode"
33
+ spec.version = OutputMode::VERSION
34
+ spec.authors = ["William McCumsite"]
35
+ spec.email = ["openlicense.williams@gmail.com"]
36
+
37
+ spec.summary = %q{Toggle human and machine readable outputs}
38
+ spec.homepage = "https://github.com/WilliamMcCumstie/output_mode"
39
+
40
+ spec.metadata["homepage_uri"] = spec.homepage
41
+
42
+ # Specify which files should be added to the gem when it is released.
43
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
44
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
45
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
46
+ end
47
+ spec.bindir = "exe"
48
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
49
+ spec.require_paths = ["lib"]
50
+
51
+ spec.add_runtime_dependency 'tty-table', '~> 0.11'
52
+ spec.add_runtime_dependency 'pastel', '~> 0.7'
53
+ spec.add_runtime_dependency 'tty-color', '~> 0.5'
54
+
55
+ spec.add_development_dependency "bundler", "~> 2.0"
56
+ spec.add_development_dependency "rake", ">= 12.3.3"
57
+ spec.add_development_dependency "rspec", "~> 3.0"
58
+ spec.add_development_dependency "pry", "> 0.11"
59
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: output_mode
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - William McCumsite
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-table
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pastel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-color
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 12.3.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 12.3.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ description:
112
+ email:
113
+ - openlicense.williams@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/demo
127
+ - bin/setup
128
+ - lib/output_mode.rb
129
+ - lib/output_mode/builder_dsl.rb
130
+ - lib/output_mode/callable.rb
131
+ - lib/output_mode/default_erb.rb
132
+ - lib/output_mode/errors.rb
133
+ - lib/output_mode/output.rb
134
+ - lib/output_mode/outputs.rb
135
+ - lib/output_mode/outputs/delimited.rb
136
+ - lib/output_mode/outputs/tabulated.rb
137
+ - lib/output_mode/outputs/templated.rb
138
+ - lib/output_mode/tldr.rb
139
+ - lib/output_mode/tldr/index.rb
140
+ - lib/output_mode/tldr/show.rb
141
+ - lib/output_mode/version.rb
142
+ - output_mode.gemspec
143
+ homepage: https://github.com/WilliamMcCumstie/output_mode
144
+ licenses: []
145
+ metadata:
146
+ homepage_uri: https://github.com/WilliamMcCumstie/output_mode
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubygems_version: 3.0.3
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Toggle human and machine readable outputs
166
+ test_files: []