Class: Texico::CLI::Command::Base
- Inherits:
-
Object
- Object
- Texico::CLI::Command::Base
show all
- Defined in:
- lib/texico/cli/command/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(prompt, opts) ⇒ Base
Returns a new instance of Base.
7
8
9
10
|
# File 'lib/texico/cli/command/base.rb', line 7
def initialize(prompt, opts)
@prompt = prompt
@opts = opts
end
|
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
5
6
7
|
# File 'lib/texico/cli/command/base.rb', line 5
def opts
@opts
end
|
#prompt ⇒ Object
Returns the value of attribute prompt.
5
6
7
|
# File 'lib/texico/cli/command/base.rb', line 5
def prompt
@prompt
end
|
Class Method Details
.inherited(klass) ⇒ Object
38
39
40
|
# File 'lib/texico/cli/command/base.rb', line 38
def inherited(klass)
(@commands ||= []) << { klass: klass, prio: klass.priority }
end
|
.match(command, *args) ⇒ Object
50
51
52
53
|
# File 'lib/texico/cli/command/base.rb', line 50
def match(command, *args)
klass = select(command)
klass.new(*args) if klass
end
|
.match?(command) ⇒ Boolean
30
31
32
|
# File 'lib/texico/cli/command/base.rb', line 30
def match?(command)
true
end
|
.priority ⇒ Object
34
35
36
|
# File 'lib/texico/cli/command/base.rb', line 34
def priority
0
end
|
.select(command) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/texico/cli/command/base.rb', line 42
def select(command)
@commands&.sort_by { |e| -e[:prio] }
&.map! { |e| e[:klass] }
&.each { |k| sk = k.select command; return sk if sk }
match?(command) && self
end
|
Instance Method Details
#load_config(full = true) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/texico/cli/command/base.rb', line 16
def load_config(full = true)
ConfigFile.load(opts, full).tap do |config|
unless config
prompt.say 'I Couldn\'t find a valid config file. Run ' + \
prompt.decorate('texico init', :bold, :yellow) + \
' to setup a new project'
exit
end
end
end
|
#run ⇒ Object
12
13
14
|
# File 'lib/texico/cli/command/base.rb', line 12
def run
prompt.error "I don't know what you mean with '#{opts[:cmd]}'"
end
|