class Gemstash::CLI

Base Command Line Interface class.

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/gemstash/cli.rb, line 24
def self.exit_on_failure?
  true
end
start(args = ARGV) click to toggle source
Calls superclass method
# File lib/gemstash/cli.rb, line 28
def self.start(args = ARGV)
  help_flags = %w[-h --help]

  if args.any? {|a| help_flags.include?(a) }
    super(%w[help] + args.reject {|a| help_flags.include?(a) })
  else
    super
  end
end

Public Instance Methods

authorize(*args) click to toggle source
# File lib/gemstash/cli.rb, line 62
def authorize(*args)
  Gemstash::CLI::Authorize.new(self, *args).run
end
help(command = nil) click to toggle source
Calls superclass method
# File lib/gemstash/cli.rb, line 38
def help(command = nil)
  command ||= "readme"
  page = manpage(command)

  if page && which("man")
    exec "man", page
  elsif page
    puts File.read("#{page}.txt")
  else
    super
  end
end
setup() click to toggle source
# File lib/gemstash/cli.rb, line 73
def setup
  Gemstash::CLI::Setup.new(self).run
end
start() click to toggle source
# File lib/gemstash/cli.rb, line 82
def start
  Gemstash::CLI::Start.new(self).run
end
status() click to toggle source
# File lib/gemstash/cli.rb, line 89
def status
  Gemstash::CLI::Status.new(self).run
end
stop() click to toggle source
# File lib/gemstash/cli.rb, line 96
def stop
  Gemstash::CLI::Stop.new(self).run
end
version() click to toggle source
# File lib/gemstash/cli.rb, line 101
def version
  say "Gemstash version #{Gemstash::VERSION}"
end

Private Instance Methods

manpage(command) click to toggle source
# File lib/gemstash/cli.rb, line 108
def manpage(command)
  page = File.expand_path("../man/gemstash-#{command}", __FILE__)
  return page if File.file?(page)

  1.upto(8) do |section|
    page = File.expand_path("../man/gemstash-#{command}.#{section}", __FILE__)
    return page if File.file?(page)
  end

  nil
end
which(executable) click to toggle source
# File lib/gemstash/cli.rb, line 120
def which(executable)
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
    exe_path = File.join(path, executable)
    return exe_path if File.file?(exe_path) && File.executable?(exe_path)
  end

  nil
end