tty 0.5.0 → 0.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/.travis.yml +9 -9
- data/CHANGELOG.md +27 -10
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +2 -2
- data/README.md +40 -182
- data/appveyor.yml +23 -0
- data/lib/tty.rb +2 -65
- data/lib/tty/plugins.rb +46 -19
- data/lib/tty/plugins/plugin.rb +4 -9
- data/lib/tty/version.rb +1 -1
- data/spec/fixtures/foo-0.0.1.gemspec +17 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/tty/plugins/find_spec.rb +11 -19
- data/spec/tty/plugins/load_spec.rb +6 -10
- data/spec/tty/plugins/plugin/load_spec.rb +15 -5
- data/spec/tty/plugins/plugin/new_spec.rb +3 -6
- data/spec/tty/tty_spec.rb +1 -7
- data/tty.gemspec +11 -9
- metadata +89 -94
- data/lib/tty/logger.rb +0 -85
- data/lib/tty/support/coercion.rb +0 -30
- data/lib/tty/support/delegatable.rb +0 -44
- data/lib/tty/support/unicode.rb +0 -35
- data/lib/tty/system.rb +0 -14
- data/lib/tty/system/editor.rb +0 -114
- data/lib/tty/terminal.rb +0 -21
- data/lib/tty/terminal/home.rb +0 -42
- data/lib/tty/vector.rb +0 -116
- data/spec/tty/logger/log_spec.rb +0 -23
- data/spec/tty/logger/new_spec.rb +0 -36
- data/spec/tty/logger/valid_level_spec.rb +0 -33
- data/spec/tty/support/coercion_spec.rb +0 -41
- data/spec/tty/support/delegatable_spec.rb +0 -28
- data/spec/tty/support/fixtures/classes.rb +0 -19
- data/spec/tty/system/editor/available_spec.rb +0 -40
- data/spec/tty/system/editor/build_spec.rb +0 -32
- data/spec/tty/system/editor/command_spec.rb +0 -17
- data/spec/tty/system/editor/executables_spec.rb +0 -13
- data/spec/tty/system/editor/invoke_spec.rb +0 -34
- data/spec/tty/system/editor/open_spec.rb +0 -29
- data/spec/tty/terminal/home_spec.rb +0 -27
- data/spec/tty/vector/new_spec.rb +0 -48
data/appveyor.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
install:
|
3
|
+
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
4
|
+
- ruby --version
|
5
|
+
- gem --version
|
6
|
+
- bundle install
|
7
|
+
build: off
|
8
|
+
test_script:
|
9
|
+
- bundle exec rake ci
|
10
|
+
environment:
|
11
|
+
matrix:
|
12
|
+
- ruby_version: "193"
|
13
|
+
- ruby_version: "200"
|
14
|
+
- ruby_version: "200-x64"
|
15
|
+
- ruby_version: "21"
|
16
|
+
- ruby_version: "21-x64"
|
17
|
+
- ruby_version: "22"
|
18
|
+
- ruby_version: "22-x64"
|
19
|
+
- ruby_version: "23"
|
20
|
+
- ruby_version: "23-x64"
|
21
|
+
matrix:
|
22
|
+
allow_failures:
|
23
|
+
- ruby_version: "193"
|
data/lib/tty.rb
CHANGED
@@ -1,48 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'equatable'
|
4
|
-
require 'pastel'
|
5
|
-
require 'tty-pager'
|
6
|
-
require 'tty-platform'
|
7
|
-
require 'tty-progressbar'
|
8
|
-
require 'tty-screen'
|
9
|
-
require 'tty-spinner'
|
10
|
-
require 'tty-table'
|
11
|
-
require 'tty-which'
|
12
|
-
|
13
3
|
require 'tty/version'
|
14
|
-
require 'tty/support/delegatable'
|
15
|
-
require 'tty/support/coercion'
|
16
|
-
require 'tty/support/unicode'
|
17
|
-
require 'tty/terminal'
|
18
|
-
require 'tty/system'
|
19
|
-
require 'tty/vector'
|
20
|
-
require 'tty/logger'
|
21
4
|
require 'tty/plugins'
|
22
5
|
require 'tty/plugins/plugin'
|
23
|
-
require 'tty/terminal/home'
|
24
|
-
require 'tty/system/editor'
|
25
6
|
|
26
7
|
module TTY
|
27
|
-
|
28
|
-
# Raised when the argument type is different from expected
|
29
|
-
class TypeError < ArgumentError; end
|
30
|
-
|
31
|
-
# Raised when the operation is not implemented
|
32
|
-
class NoImplementationError < NotImplementedError; end
|
33
|
-
|
34
|
-
# Raised when the passed in validation argument is of wrong type
|
35
|
-
class ValidationCoercion < TypeError; end
|
36
|
-
|
37
|
-
# Raised when the attribute is unknown
|
38
|
-
class UnknownAttributeError < IndexError; end
|
39
|
-
|
40
|
-
# Raised when command cannot be invoked
|
41
|
-
class CommandInvocationError < StandardError; end
|
42
|
-
|
43
|
-
# An empty array used as a default value
|
44
|
-
EMPTY_ARRAY = Array.new.freeze
|
45
|
-
|
46
8
|
class << self
|
47
9
|
def included(base)
|
48
10
|
base.send :extend, ClassMethods
|
@@ -50,33 +12,6 @@ module TTY
|
|
50
12
|
end
|
51
13
|
|
52
14
|
module ClassMethods
|
53
|
-
# Return shared terminal instance
|
54
|
-
#
|
55
|
-
# @return [TTY::Terminal]
|
56
|
-
#
|
57
|
-
# @api public
|
58
|
-
def terminal
|
59
|
-
@terminal ||= Terminal.new
|
60
|
-
end
|
61
|
-
|
62
|
-
# Return shared shell instance
|
63
|
-
#
|
64
|
-
# @return [TTY::Shell]
|
65
|
-
#
|
66
|
-
# @api public
|
67
|
-
# def shell(input=$stdin, output=$stdout)
|
68
|
-
# @shell ||= Shell.new(input, output)
|
69
|
-
# end
|
70
|
-
|
71
|
-
# Return shared system object
|
72
|
-
#
|
73
|
-
# @return [TTY::System]
|
74
|
-
#
|
75
|
-
# @api public
|
76
|
-
def system
|
77
|
-
System
|
78
|
-
end
|
79
|
-
|
80
15
|
# Return shared plugins instance
|
81
16
|
#
|
82
17
|
# @return [TTY::Plugins]
|
@@ -89,3 +24,5 @@ module TTY
|
|
89
24
|
|
90
25
|
extend ClassMethods
|
91
26
|
end # TTY
|
27
|
+
|
28
|
+
TTY.plugins.find('tty').load
|
data/lib/tty/plugins.rb
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
module TTY
|
4
4
|
# A class responsible for managing plugins installation
|
5
5
|
class Plugins
|
6
|
-
|
6
|
+
include Enumerable
|
7
7
|
|
8
|
-
|
9
|
-
private :plugins
|
8
|
+
attr_reader :plugins
|
10
9
|
|
11
10
|
# Initialize the Plugins
|
12
11
|
#
|
@@ -15,13 +14,17 @@ module TTY
|
|
15
14
|
@plugins = []
|
16
15
|
end
|
17
16
|
|
18
|
-
#
|
17
|
+
# Iterate over plugins
|
18
|
+
# @example
|
19
|
+
# plugins.each { |plug| ... }
|
20
|
+
#
|
21
|
+
# @return [self]
|
19
22
|
#
|
20
23
|
# @api public
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
def each(&block)
|
25
|
+
return to_enum unless block_given?
|
26
|
+
to_ary.each(&block)
|
27
|
+
self
|
25
28
|
end
|
26
29
|
|
27
30
|
# Register plugin with name in internal array
|
@@ -32,22 +35,35 @@ module TTY
|
|
32
35
|
#
|
33
36
|
# @api public
|
34
37
|
def register(name, plugin = false)
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
+
return unless plugin && !loaded?(name)
|
39
|
+
@plugins << plugin
|
38
40
|
end
|
39
41
|
|
40
42
|
# Find all installed TTY plugins and store them
|
41
43
|
#
|
44
|
+
# @param [String] :lib_name
|
45
|
+
#
|
46
|
+
# @return [self]
|
47
|
+
#
|
42
48
|
# @api private
|
43
|
-
def find
|
49
|
+
def find(lib_name = 'tty')
|
44
50
|
Gem.refresh
|
45
|
-
Gem::Specification.
|
46
|
-
|
47
|
-
|
51
|
+
spec = Gem::Specification.find_by_name(lib_name)
|
52
|
+
spec.runtime_dependencies.each do |gem|
|
53
|
+
next unless gem.name =~ /^#{lib_name}/
|
54
|
+
plugin_name = gem.name[/^#{lib_name}-(.*)/]
|
48
55
|
register(plugin_name, Plugin.new(plugin_name, gem))
|
49
56
|
end
|
50
|
-
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
# Load all plugins that are not enabled
|
61
|
+
#
|
62
|
+
# @api public
|
63
|
+
def load
|
64
|
+
plugins.each do |plugin|
|
65
|
+
plugin.load! unless plugin.enabled?
|
66
|
+
end
|
51
67
|
end
|
52
68
|
|
53
69
|
# Return a list of all plugin names as strings
|
@@ -60,13 +76,24 @@ module TTY
|
|
60
76
|
end
|
61
77
|
end
|
62
78
|
|
63
|
-
private
|
64
|
-
|
65
79
|
# Check if plugin is already loaded
|
66
80
|
#
|
67
81
|
# @api private
|
68
82
|
def loaded?(name)
|
69
|
-
plugins.any? { |plugin| plugin.
|
83
|
+
plugins.any? { |plugin| plugin.name == name }
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_ary
|
87
|
+
@plugins.dup
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_a
|
91
|
+
to_ary
|
92
|
+
end
|
93
|
+
|
94
|
+
def size
|
95
|
+
to_ary.size
|
70
96
|
end
|
97
|
+
alias length size
|
71
98
|
end # PluginManager
|
72
99
|
end # TTY
|
data/lib/tty/plugins/plugin.rb
CHANGED
@@ -7,10 +7,6 @@ module TTY
|
|
7
7
|
|
8
8
|
attr_reader :gem
|
9
9
|
|
10
|
-
attr_reader :gem_name
|
11
|
-
|
12
|
-
attr_accessor :enabled
|
13
|
-
|
14
10
|
# Initialize a Plugin
|
15
11
|
#
|
16
12
|
# @param [String] name
|
@@ -23,7 +19,6 @@ module TTY
|
|
23
19
|
def initialize(name, gem)
|
24
20
|
@name = name
|
25
21
|
@gem = gem
|
26
|
-
@gem_name = "tty-#{name}"
|
27
22
|
@enabled = false
|
28
23
|
end
|
29
24
|
|
@@ -33,7 +28,7 @@ module TTY
|
|
33
28
|
#
|
34
29
|
# @api public
|
35
30
|
def enabled?
|
36
|
-
enabled
|
31
|
+
@enabled
|
37
32
|
end
|
38
33
|
|
39
34
|
# Load the plugin (require the gem)
|
@@ -41,11 +36,11 @@ module TTY
|
|
41
36
|
# @api public
|
42
37
|
def load!
|
43
38
|
begin
|
44
|
-
require
|
39
|
+
require name unless enabled?
|
45
40
|
rescue LoadError => error
|
46
|
-
puts("Unable to load plugin #{
|
41
|
+
puts("Unable to load plugin #{name} due to #{error}.")
|
47
42
|
rescue => error
|
48
|
-
puts("require '#{
|
43
|
+
puts("require '#{name}' failed with #{error}")
|
49
44
|
end
|
50
45
|
@enabled = true
|
51
46
|
end
|
data/lib/tty/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'foo'
|
5
|
+
spec.version = '0.0.1'
|
6
|
+
spec.platform = 'ruby'
|
7
|
+
spec.require_paths = ['lib']
|
8
|
+
spec.summary = 'A foo gem'
|
9
|
+
|
10
|
+
spec.add_dependency 'pastel'
|
11
|
+
spec.add_dependency 'equatable'
|
12
|
+
spec.add_dependency 'tty-command', '~> 0.3.0'
|
13
|
+
spec.add_dependency 'tty-prompt', '~> 0.10.0'
|
14
|
+
spec.add_dependency 'tty-spinner', '~> 0.4.0'
|
15
|
+
|
16
|
+
spec.add_development_dependency 'rake'
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,9 +14,21 @@ if ENV['TRAVIS'] || ENV['COVERAGE']
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
require 'rubygems'
|
17
18
|
require 'tty'
|
18
19
|
|
20
|
+
module Helpers
|
21
|
+
def fixtures_dir
|
22
|
+
File.join(File.dirname(__FILE__), 'fixtures')
|
23
|
+
end
|
24
|
+
|
25
|
+
def fixtures_path(filename = nil)
|
26
|
+
File.join(File.dirname(__FILE__), 'fixtures', filename.to_s)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
19
30
|
RSpec.configure do |config|
|
31
|
+
config.include(Helpers)
|
20
32
|
config.run_all_when_everything_filtered = true
|
21
33
|
config.filter_run :focus
|
22
34
|
config.order = 'random'
|
@@ -3,26 +3,18 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Plugins, '#find' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
it "finds gems with a specific prefix" do
|
7
|
+
plugins = TTY::Plugins.new
|
8
|
+
spec = Gem::Specification.load fixtures_path('foo-0.0.1.gemspec')
|
9
|
+
allow(Gem::Specification).to receive(:find_by_name).with('tty').
|
10
|
+
and_return(spec)
|
10
11
|
|
11
|
-
|
12
|
-
allow(Gem).to receive(:refresh)
|
13
|
-
allow(Gem::Specification).to receive(:each).and_yield(tty_gem).and_yield(gem)
|
14
|
-
}
|
12
|
+
plugins.find('tty')
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
expect(found.first.gem).to eql(tty_gem)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'retrieves only tty plugin' do
|
25
|
-
subject.find
|
26
|
-
expect(subject.names['console'].gem).to eql(tty_gem)
|
14
|
+
expect(plugins.to_a.map(&:name)).to eq([
|
15
|
+
'tty-command',
|
16
|
+
'tty-prompt',
|
17
|
+
'tty-spinner'
|
18
|
+
])
|
27
19
|
end
|
28
20
|
end
|
@@ -3,17 +3,13 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Plugins, '#load' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
subject { object.new }
|
6
|
+
it "activates all plugins" do
|
7
|
+
plugin = double(:plugin, :enabled? => false, :load! => true)
|
8
|
+
plugins = TTY::Plugins.new
|
9
|
+
allow(plugins).to receive(:plugins).and_return([plugin, plugin])
|
11
10
|
|
12
|
-
|
11
|
+
plugins.load
|
13
12
|
|
14
|
-
|
15
|
-
allow(plugin).to receive(:load!)
|
16
|
-
subject.load
|
17
|
-
expect(plugin).to have_received(:load!).twice()
|
13
|
+
expect(plugin).to have_received(:load!).twice
|
18
14
|
end
|
19
15
|
end
|
@@ -4,21 +4,31 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe TTY::Plugin, '#load!' do
|
6
6
|
let(:gem) { Gem::Specification.new('tty-console', '3.1.3')}
|
7
|
-
let(:name) { 'console'}
|
8
7
|
|
9
|
-
|
8
|
+
it "loads a gem" do
|
9
|
+
plugin = TTY::Plugin.new('tty-console', gem)
|
10
|
+
allow(plugin).to receive(:require).with('tty-console').and_return(true)
|
11
|
+
|
12
|
+
plugin.load!
|
13
|
+
|
14
|
+
expect(plugin).to have_received(:require).once
|
15
|
+
end
|
10
16
|
|
11
17
|
it 'fails to load the gem' do
|
12
|
-
|
18
|
+
plugin = TTY::Plugin.new('tty-console', gem)
|
19
|
+
allow(plugin).to receive(:require) { raise LoadError }
|
20
|
+
|
13
21
|
expect {
|
14
22
|
plugin.load!
|
15
23
|
}.to output(/Unable to load plugin tty-console./).to_stdout
|
16
24
|
end
|
17
25
|
|
18
26
|
it 'fails to require the gem' do
|
19
|
-
|
27
|
+
plugin = TTY::Plugin.new('tty-console', gem)
|
28
|
+
allow(plugin).to receive(:require) { raise StandardError }
|
29
|
+
|
20
30
|
expect {
|
21
31
|
plugin.load!
|
22
|
-
}.to output(/
|
32
|
+
}.to output(/require 'tty-console' failed with StandardError\n/).to_stdout
|
23
33
|
end
|
24
34
|
end
|
@@ -4,15 +4,12 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe TTY::Plugin, '#new' do
|
6
6
|
let(:gem) { Gem::Specification.new('tty-console', '3.1.3')}
|
7
|
-
let(:name) { 'console'}
|
8
7
|
|
9
|
-
subject(:plugin) { described_class.new(
|
8
|
+
subject(:plugin) { described_class.new('tty-console', gem) }
|
10
9
|
|
11
|
-
it { expect(plugin.name).to eq(
|
10
|
+
it { expect(plugin.name).to eq('tty-console') }
|
12
11
|
|
13
12
|
it { expect(plugin.gem).to eq(gem) }
|
14
13
|
|
15
|
-
it { expect(plugin.enabled).to eq(false) }
|
16
|
-
|
17
|
-
it { expect(plugin.gem_name).to eq("tty-#{name}") }
|
14
|
+
it { expect(plugin.enabled?).to eq(false) }
|
18
15
|
end
|
data/spec/tty/tty_spec.rb
CHANGED
@@ -5,18 +5,12 @@ require 'spec_helper'
|
|
5
5
|
describe TTY do
|
6
6
|
let(:object) { described_class }
|
7
7
|
|
8
|
-
it { expect(object.terminal).to be_instance_of(TTY::Terminal) }
|
9
|
-
|
10
|
-
#it { expect(object.shell).to be_instance_of(TTY::Shell) }
|
11
|
-
|
12
|
-
it { expect(object.system).to be(TTY::System) }
|
13
|
-
|
14
8
|
it { expect(object.plugins).to be_instance_of(TTY::Plugins) }
|
15
9
|
|
16
10
|
context 'when module' do
|
17
11
|
it 'decorates class' do
|
18
12
|
klass = Class.new { include TTY }
|
19
|
-
expect(klass).to respond_to(:
|
13
|
+
expect(klass).to respond_to(:plugins)
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end # TTY
|