Class: DoCli::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/docli/options_parse.rb

Class Method Summary collapse

Class Method Details

.droplets_parse(argv) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/docli/options_parse.rb', line 7

def self.droplets_parse argv
  opt_parser = OptionParser.new do |opt|
    opt.banner = "Usage: docli droplets [COMMAND]"
    opt.separator  ""
    opt.separator  "Commands"
    opt.separator  "     create: create new droplets on DigitalOcean"
    opt.separator  "     list: list all droplets on DigitalOcean"
    opt.separator  ""
    opt.separator  "Options"
    opt.on("-h","--help","show help message")
    opt.separator  ""
    opt.separator  "Show help command:"
    opt.separator  "docli droplets [COMMAND] --help"
  end

  case ARGV[1]
  when "create"
    Docli::Droplets.create_new_droplets argv
  when "list"
    DoCli::Droplets.list_all_droplets
  else
    puts opt_parser
  end
end

.file_parse(argv) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/docli/options_parse.rb', line 32

def self.file_parse argv
  options = {}
  opt_parser = OptionParser.new do |opt|
    opt.banner = "Usage: docli create -f [FILE]"
    opt.banner = "     docli apply --file [FILE]"
    opt.separator  ""
    opt.separator  "Commands"
    opt.separator  "     create: create new droplets on DigitalOcean"
    opt.separator  "     list: list all droplets on DigitalOcean"
    opt.separator  ""
    opt.separator  "Options"
    opt.on("-f ","--file ","File contain the resources define") do |file|
      options[:file_config] = file
    end
    opt.on("-h","--help","show help message")
    opt.separator  ""
    opt.separator  "Show help command:"
    opt.separator  "docli droplets [COMMAND] --help"
  end

  opt_parser.parse!
  if options[:file_config].nil?
    puts "Please specify your config file".red
    puts opt_parser
    exit
  end
  context = YAML.load(File.open(options[:file_config]))

  context.each do |key, value|
    case value["resource_type"]
    when "droplets"
      Cmd::NewDroplets.create_new_droplets_from_file value
    else
      puts "Cannot get resource_type" + value['resource_type']
      puts opt_parser
      exit
    end
  end
end