Class: ProvisionVagrant::Options

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

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



9
10
# File 'lib/options.rb', line 9

def initialize
end

Instance Method Details

#help(msg = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/options.rb', line 76

def help(msg = nil)
  if msg
    puts(Paint["\n#{msg}\n", :yellow])
    exit(false)
  end

  msg = <<~END_HELP
    provision-vagrant: Generates and provisions a new vagrant vm box using template files

    Syntax: provision-vagrant NEW_BOX_NAME

    Options:
      -c Specify a path to the config yml file to use (default: ~/provision-vagrant.yml)
      -d Delete files copied over from init command
      -h Show this help message
      -t Specify a path to the Vagrantfile template to use (default: ~/Vagrantfile.template)
      -v Show version number

    Example:

      provision-vagrant foo-bar-app

    This will do the following:

      - Create a new directory "foo-bar-app" under your home directory
      - Create a "dev-box" directory within that directory (~/foo-bar-app/dev-box/)
      - Copy over ~/Vagrantfile.template and replace the {{vars}} with project/config vars

    See:
      https://github.com/sbraford/provision-vagrant
  END_HELP

  puts(Paint[msg, :magenta])
  exit(true)
end

#parse_optionsObject



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
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
71
72
73
74
# File 'lib/options.rb', line 12

def parse_options
  options = { verbose: false }
  OptionParser.new do |parser|
    @parser = parser

    parser.on("-c", "--config", "Specify the yml config file to use") do |c|
      options[:config] = c
    end

    parser.on("-d", "--delete", "Delete files copied over from init command") do |d|
      options[:delete] = true
    end

    parser.on("-f", "--force", "Force initialization even if target files already exist") do |f|
      options[:force] = true
    end

    parser.on("-t", "--template", "Specify the path the to the Vagrantfile template") do |t|
      options[:template] = t
    end

    parser.on("-v", "--version", "Shows the version number") do |v|
      options[:version] = true
    end

    parser.on("-h", "--help", "Show this help message") do |h|
      options[:help] = true
    end

    parser.on("-i", "--init", "Initialize provision-vagrant with files it needs to operate") do |i|
      options[:init] = true
    end
  end.parse!

  if options[:version]
    help(ProvisionVagrant.version)
  end

  if options[:help]
    help
  end

  if options[:delete]
    Generator.new.delete
    exit(true)
  end

  if options[:config] && !File.exist?(options[:config])
    help "Error: Invalid config file specified (not found): #{CONFIG}"
  end

  if options[:temlpate] && !File.exist(options[:template])
    help "Error: Invalid template file specified (not found): #{TEMPLATE}"
  end

  if options[:init]
    initiliazer = PvInitializer.new(options)
    initiliazer.init
    exit(true)
  end

  options
end