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
# File 'lib/dockerize/config.rb', line 12

def parse(args)
  config = self

  Trollop.options(args) do
    text "Usage: dockerize <project directory> [options]\nOptions:\n"

    # -q/--quiet
    opt :quiet, 'Silence output', type: :flag, short: 'q', default: false

    # -d/--dry-run
    opt :dry_run, 'Dry run, do not write any files',
        type: :flag,
        short: 'd',
        default: false

    # -f/--force
    opt :force, 'Force existing files to be overwritten',
        type: :flag,
        short: 'f',
        default: false

    # -b/--backup
    opt :backup, 'Creates .bak version of files before overwriting them',
        type: :flag,
        short: 'b',
        default: true

    # -r/--registry
    opt :registry, 'The Docker registry to use when writing files',
        type: :string,
        short: 'r',
        default: ENV['DOCKERIZE_REGISTRY'] || 'quay.io/modcloth'

    # -t/--template-dir
    opt :template_dir,
        'The directory containing the templates to be written',
        type: :string,
        short: 't',
        default: ENV['DOCKERIZE_TEMPLATE_DIR'] ||
          "#{config.top}/templates"

    # -m/--maintainer
    opt :maintainer,
        'The default MAINTAINER to use for any Dockerfiles written',
        type: :string,
        short: 'm',
        default: ENV['DOCKERIZE_MAINTAINER'] ||
          "#{ENV['USER']} <#{ENV['USER']}@example.com>"

    # -F/--from
    opt :from,
        'The default base image to use for any Dockerfiles written',
        type: :string,
        short: 'F',
        default: ENV['DOCKERIZE_FROM'] || 'ubuntu:12.04'

    version "dockerize #{Dockerize::VERSION}"

    begin
      config.send(:opts=, parse(args))
    rescue Trollop::CommandlineError => e
      $stderr.puts "Error: #{e.message}."
      $stderr.puts 'Try --help for help.'
      exit 1
    rescue Trollop::HelpNeeded
      educate
      exit
    rescue Trollop::VersionNeeded
      $stderr.puts version
      exit
    end

    config.send(:opts)[:top] = config.top
    config.send(:generate_accessor_methods, self)
  end

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

.set_project_nameObject



111
112
113
# File 'lib/dockerize/config.rb', line 111

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

.topObject



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

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