Class: Dockerize::Config

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optsObject

Returns the value of attribute opts.



10
11
12
# File 'lib/dockerize/config.rb', line 10

def opts
  @opts
end

.project_dirObject

Returns the value of attribute project_dir.



9
10
11
# File 'lib/dockerize/config.rb', line 9

def project_dir
  @project_dir
end

Class Method Details

.parse(args) ⇒ 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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/dockerize/config.rb', line 12

def parse(args)
  # defaults
  @opts = {
    quiet: false,
    dry_run: false,
    force: false,
    backup: true,
    registry: ENV['DOCKERIZE_REGISTRY'] || 'quay.io/modcloth',
    template_dir: ENV['DOCKERIZE_TEMPLATE_DIR'] || "#{top}/templates",
    maintainer: ENV['DOCKERIZE_MAINTAINER'] ||
      "#{ENV['USER']} <#{ENV['USER']}@example.com>",
    from: ENV['DOCKERIZE_FROM'] || 'ubuntu:12.04'
  }

  OptionParser.new do |opt|
    # -q/--quiet
    opt.on('-q', '--[no-]quiet', 'Silence output') do |q|
      opts[:quiet] = q
    end

    # -d/--dry-run
    opt.on(
      '-d', '--[no-]dry-run', 'Dry run, do not write any files'
    ) do |d|
      opts[:dry_run] = d
    end

    # -f/--force
    opt.on(
      '-f', '--[no-]force', 'Force existing files to be overwritten'
    ) { |f| opts[:force] = f }

    # -b/--backup
    opt.on(
      '-b',
      '--[no-]backup',
      'Creates .bak version of files before overwriting them'
    ) { |b| opts[:backup] = b }

    # -r/--registry
    opt.on(
      '-r REGISTRY',
      '--registry REGISTRY',
      'The Docker registry to use when writing files'
    ) { |r| opts[:registry] = r }

    # -t/--template-dir
    opt.on(
      '-t TEMPLATE_DIR',
      '--template-dir TEMPLATE_DIR',
      'The directory containing the templates to be written'
    ) { |t| opts[:template_dir] = t }

    # -m/--maintainer
    opt.on(
      '-m MAINTAINER',
      '--maintainer MAINTAINER',
      'The default MAINTAINER to use for any Dockerfiles written'
    ) { |m| opts[:maintainer] = m }

    # -F/--from
    opt.on(
      '-F FROM',
      '--from FROM',
      'The default base image to use for any Dockerfiles written'
    ) { |f| opts[:from] = f }

    # -h/--help
    opt.on_tail('-h', '--help', 'Display this message') do
      $stderr.puts opt.help
      exit
    end

    # -v/--version
    opt.on_tail('-v', '--version', 'Show version and exit') do
      $stderr.puts "dockerize #{Dockerize::VERSION}"
      exit
    end
  end.parse!(args)

  self.project_dir = args[0]
  set_project_name unless opts[:project_name]
  generate_accessor_methods
end

.set_project_nameObject



116
117
118
# File 'lib/dockerize/config.rb', line 116

def set_project_name
  opts[:project_name] ||= File.basename(project_dir)
end

.topObject



120
121
122
# File 'lib/dockerize/config.rb', line 120

def top
  @top ||= Gem::Specification.find_by_name('dockerize').gem_dir
end