class Texico::CLI::Command::Base

Attributes

opts[R]
prompt[R]

Public Class Methods

new(prompt, opts) click to toggle source
# File lib/texico/cli/command/base.rb, line 7
def initialize(prompt, opts)
  @prompt = prompt
  @opts   = opts
end

Protected Class Methods

inherited(klass) click to toggle source
# File lib/texico/cli/command/base.rb, line 38
def inherited(klass)
  (@commands ||= []) << { klass: klass, prio: klass.priority }
end
match(command, *args) click to toggle source
# File lib/texico/cli/command/base.rb, line 50
def match(command, *args)
  klass = select(command)
  klass.new(*args) if klass
end
match?(command) click to toggle source
# File lib/texico/cli/command/base.rb, line 30
def match?(command)
  true
end
priority() click to toggle source
# File lib/texico/cli/command/base.rb, line 34
def priority
  0
end
select(command) click to toggle source
# 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

Public Instance Methods

load_config(full = true) click to toggle source
# 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() click to toggle source
# File lib/texico/cli/command/base.rb, line 12
def run
  prompt.error "I don't know what you mean with '#{opts[:cmd]}'"
end