Module: CommandLine

Defined in:
lib/commandline.rb

Class Method Summary collapse

Class Method Details

.load_default_arguments(cmd) ⇒ Object



42
43
44
45
# File 'lib/commandline.rb', line 42

def self.load_default_arguments(cmd)
  default_arguments_list = LocalSetting.get["local_setting"]
  (default_arguments_list["default_args.#{cmd}"] || "").split
end

.multiple_argument_extract(argv) ⇒ Object

引数をスペース以外による区切り文字で展開する



50
51
52
53
54
55
# File 'lib/commandline.rb', line 50

def self.multiple_argument_extract(argv)
  delimiter = LocalSetting.get["local_setting"]["multiple-delimiter"] || ","
  argv.map! { |arg|
    arg.split(delimiter)
  }.flatten!
end

.run(argv) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/commandline.rb', line 12

def self.run(argv)
  if Helper.os_windows?
    argv.map! do |arg|
      arg.encode(Encoding::UTF_8)
    end
  end
  argv.unshift("help") if argv.empty?
  arg = argv.shift.downcase
  arg = Command::Shortcuts[arg] || arg
  arg = "help" if arg == "-h" || arg == "--help"
  arg = "version" if arg == "-v" || arg == "--version"
  unless Narou.already_init?
    unless ["help", "version", "init"].include?(arg)
      arg = "help"
    end
  end
  unless Command.get_list.include?(arg)
    error "不明なコマンドです"
    puts
    arg = "help"
  end
  if argv.empty?
    argv += load_default_arguments(arg)
  end
  if argv.delete("--multiple")
    multiple_argument_extract(argv)
  end
  Command.get_list[arg].execute(argv)
end