class CommandLine::Command

Attributes

args[R]
input_stream[R]
opt_parser[R]
options[R]
terminal[R]
tokens[R]

Public Class Methods

new(new_args, new_input_stream = STDIN) click to toggle source
# File lib/git/contest/command_line/command.rb, line 30
def initialize(new_args, new_input_stream = STDIN)
  @input_stream = new_input_stream
  @terminal = ::HighLine.new(new_input_stream)
  init_global # TODO: remove
  init_home   # TODO:remove
  @args = new_args.clone
  @options = {}
  @tokens = [] # init after parse options
  @opt_parser = OptionParser.new do |opt|
    opt.version = Git::Contest::VERSION
  end
end

Public Instance Methods

define_options() click to toggle source
# File lib/git/contest/command_line/command.rb, line 43
def define_options
  raise "not implement"
end
init() click to toggle source
# File lib/git/contest/command_line/command.rb, line 51
def init
  define_options
  parse_line_options
  @tokens = args
  set_default_options
end
run() click to toggle source
# File lib/git/contest/command_line/command.rb, line 58
def run
  raise "not implement"
end
set_default_options() click to toggle source
# File lib/git/contest/command_line/command.rb, line 47
def set_default_options
  raise "not implement"
end

Private Instance Methods

has_next_token?() click to toggle source
# File lib/git/contest/command_line/command.rb, line 111
def has_next_token?
  not @tokens.empty?
end
has_subcommand?() click to toggle source
# File lib/git/contest/command_line/command.rb, line 100
def has_subcommand?
  return false if args.empty?
  return false if args[0].start_with?("-")
  return true
end
is_line_option?(s) click to toggle source
# File lib/git/contest/command_line/command.rb, line 90
def is_line_option?(s)
  return true if /^-[a-zA-Z0-9]$/ === s
  return true if /^--/ === s
  return false
end
is_not_line_option?(s) click to toggle source
# File lib/git/contest/command_line/command.rb, line 96
def is_not_line_option?(s)
  is_line_option?(s) === false
end
last_line_option_index() click to toggle source
# File lib/git/contest/command_line/command.rb, line 79
def last_line_option_index
  args.index do |arg|
    is_not_line_option?(arg)
  end
end
next_token() click to toggle source
–opt1, –opt2, token1, token2

> token1

# File lib/git/contest/command_line/command.rb, line 107
def next_token
  @tokens.shift
end
parse_line_options() click to toggle source
# File lib/git/contest/command_line/command.rb, line 64
def parse_line_options
  return if args.empty?
  last_ind = last_line_option_index
  if last_ind.nil?
    parsed = args.clone
  else
    parsed = args[0 .. last_ind]
  end
  if last_ind.nil?
    @args = opt_parser.parse(parsed)
  else
    @args = opt_parser.parse(parsed).concat(args[last_ind + 1..-1])
  end
end
to_command_class_sym(s) click to toggle source

hello -> HelloCommand

# File lib/git/contest/command_line/command.rb, line 86
def to_command_class_sym(s)
  "#{s.capitalize}Command".to_sym
end