class Canoe::CmdParser

Public Class Methods

new(options) click to toggle source
# File lib/cmd.rb, line 13
def initialize(options)
  @options = options
end

Public Instance Methods

parse(args) click to toggle source
# File lib/cmd.rb, line 17
def parse(args)
  if args.size < 1
    abort_on_err "please give one command among #{@options.join(", ")}"
  end

  unless @options.include?(args[0])
    abort_on_err "unknown command #{args[0]}"
  end

  self.send "parse_#{args[0]}", args[1..]
end

Private Instance Methods

parse_add(args) click to toggle source
# File lib/cmd.rb, line 51
def parse_add(args)
  if args.size < 1
    abort_on_err "it's not reasonable to add a component with no name given"
  end

  current_workspace.add args
end
parse_build(args) click to toggle source
# File lib/cmd.rb, line 59
def parse_build(args)
  options = {[] => 'target', ['all'] => 'all', ['test'] => 'test', ['base'] => 'base'}
  abort_on_err "Unkown subcommand #{args.join(" ").red}" unless options.include?(args)
  current_workspace.build options[args]
end
parse_clean(args) click to toggle source
# File lib/cmd.rb, line 77
def parse_clean(args)
  options = {
    [] => 'all', ['all'] => 'all',
    ['target'] => 'target', ['tests'] => 'tests', ['obj'] => 'obj'
  }
  abort_on_err "Unkown subcommand #{args.join(" ").red}" unless options.include?(args)
  current_workspace.clean options[args]
end
parse_dep(args) click to toggle source
# File lib/cmd.rb, line 73
def parse_dep(args)
  current_workspace.dep
end
parse_generate(args) click to toggle source
# File lib/cmd.rb, line 65
def parse_generate(args)
  current_workspace.generate
end
parse_help(args) click to toggle source
# File lib/cmd.rb, line 94
def parse_help(args)
  WorkSpace.help
end
parse_make(args) click to toggle source
# File lib/cmd.rb, line 102
def parse_make(args)
  current_workspace.make
end
parse_new(args) click to toggle source
# File lib/cmd.rb, line 30
def parse_new(args)
  abort_on_err "not enough arguments to canoe new" if args.size < 1

  name, mode = nil, "bin"
  suffixes = ["cpp", "hpp"]

  args.each do |arg|
    case arg
    when "--bin", "--lib"
      mode = arg[2..]
    when /--suffix=(\w+)\:(\w+)/
      suffixes[0], suffixes[1] = $1, $2
    else
      name = arg unless name
    end
  end

  abort_on_err('please give a name to this project') unless name
  WorkSpace.new(name, mode.to_sym, suffixes[0], suffixes[1], true).new
end
parse_run(args) click to toggle source
# File lib/cmd.rb, line 69
def parse_run(args)
  current_workspace.run args
end
parse_test(args) click to toggle source
# File lib/cmd.rb, line 86
def parse_test(args)
  current_workspace.test args
end
parse_update(args) click to toggle source
# File lib/cmd.rb, line 98
def parse_update(args)
  current_workspace.update
end
parse_version(args) click to toggle source
# File lib/cmd.rb, line 90
def parse_version(args)
  WorkSpace.version
end