class Markdo::CLI

Public Class Methods

new(command_support = CommandSupport.new) click to toggle source
# File lib/markdo/cli.rb, line 5
def initialize(command_support = CommandSupport.new)
  @stdin = command_support.stdin
  @stdout = command_support.stdout
  @stderr = command_support.stderr
  @full_env = command_support.env
end

Public Instance Methods

run(command_name = 'help', *args) click to toggle source
# File lib/markdo/cli.rb, line 12
def run(command_name = 'help', *args)
  command = case command_name
            when 'q'
              QueryCommand
            when 'starred'
              StarCommand
            when '--version'
              VersionCommand
            else
              choose_command_class(command_name)
            end

  command_support = CommandSupport.new(stdin: @stdin,
                                       stdout: @stdout,
                                       stderr: @stderr,
                                       env: merged_env)
  command.new(command_support).run(*args)
end

Private Instance Methods

choose_command_class(command_name) click to toggle source
# File lib/markdo/cli.rb, line 33
def choose_command_class(command_name)
  command_class_name = "#{command_name.capitalize}Command"
  ::Markdo.const_get(command_class_name)
rescue NameError
  HelpCommand
end
default_env() click to toggle source
# File lib/markdo/cli.rb, line 40
def default_env
  {
    'MARKDO_ROOT' => '.',
    'MARKDO_INBOX' => 'Inbox.md',
  }
end
merged_env() click to toggle source
# File lib/markdo/cli.rb, line 47
def merged_env
  default_env.merge(@full_env)
end