Class: Boxen::Flags

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

Overview

Various flags and settings parsed from the command line. See Setup::Configuration for more info.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Flags

Create a new instance, optionally providing CLI ‘args` to parse immediately.



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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/boxen/flags.rb', line 26

def initialize(*args)
  @args             = []
  @debug            = false
  @env              = false
  @fde              = true
  @help             = false
  @pretend          = false
  @profile          = false
  @report           = false
  @graph            = false
  @projects         = false
  @stealth          = false
  @disable_service  = false
  @enable_service   = false
  @restart_service  = false
  @disable_services = false
  @enable_services  = false
  @restart_services = false
  @list_services    = false
  @color            = true

  @options = OptionParser.new do |o|
    o.banner = "Usage: #{File.basename $0} [options] [projects...]\n\n"

    o.on "--debug", "Be really verbose." do
      @debug = true
    end

    o.on "--pretend", "--noop", "Don't make changes." do
      @pretend = true
    end

    o.on "--report", "Enable puppet reports." do
      @report = true
    end

    o.on "--graph", "Enable generation of dependency graphs." do
      @graph = true
    end

    o.on "--env", "Show useful environment variables." do
      @env = true
    end

    o.on "--help", "-h", "-?", "Show help." do
      @help = true
    end

    o.on "--disable-service SERVICE", "Disable a Boxen service." do |service|
      @disable_service = service
    end

    o.on "--enable-service SERVICE", "Enable a Boxen service." do |service|
      @enable_service = service
    end

    o.on "--restart-service SERVICE", "Restart a Boxen service." do |service|
      @restart_service = service
    end

    o.on "--disable-services", "Disable all Boxen services." do
      @disable_services = true
    end

    o.on "--enable-services", "Enable all Boxen services." do
      @enable_services = true
    end

    o.on "--restart-services", "Restart all Boxen services." do
      @restart_services = true
    end

    o.on "--list-services", "List Boxen services." do
      @list_services = true
    end

    o.on "--homedir DIR", "Boxen's home directory." do |homedir|
      @homedir = homedir
    end

    o.on "--logfile DIR", "Boxen's log file." do |logfile|
      @logfile = logfile
    end

    o.on "--login LOGIN", "Your GitHub login." do ||
      @login = 
    end

    o.on "--no-fde", "Don't require full disk encryption." do
      @fde = false
    end

    # --no-pull is used before options are parsed, but consumed here.

    o.on "--no-pull", "Don't try to update code before applying."

    o.on "--no-issue", "--stealth", "Don't open an issue on failure." do
      @stealth = true
    end

    o.on "--token TOKEN", "Your GitHub OAuth token." do |token|
      @token = token
    end

    o.on "--profile", "Profile the Puppet run." do
      @profile = true
    end

    o.on "--future-parser", "Enable the Puppet future parser" do
      @future_parser = true
    end

    o.on "--projects", "Show available projects." do
      @projects = true
    end

    o.on "--srcdir DIR", "The directory where repos live." do |srcdir|
      @srcdir = srcdir
    end

    o.on "--user USER", "Your local user." do |user|
      @user = user
    end

    o.on "--no-color", "Disable colors." do
      @color = false
    end
  end

  parse args.flatten.compact
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



11
12
13
# File 'lib/boxen/flags.rb', line 11

def args
  @args
end

#disable_serviceObject (readonly)

Returns the value of attribute disable_service.



19
20
21
# File 'lib/boxen/flags.rb', line 19

def disable_service
  @disable_service
end

#enable_serviceObject (readonly)

Returns the value of attribute enable_service.



20
21
22
# File 'lib/boxen/flags.rb', line 20

def enable_service
  @enable_service
end

#homedirObject (readonly)

Returns the value of attribute homedir.



12
13
14
# File 'lib/boxen/flags.rb', line 12

def homedir
  @homedir
end

#logfileObject (readonly)

Returns the value of attribute logfile.



13
14
15
# File 'lib/boxen/flags.rb', line 13

def logfile
  @logfile
end

#loginObject (readonly)

Returns the value of attribute login.



14
15
16
# File 'lib/boxen/flags.rb', line 14

def 
  @login
end

#restart_serviceObject (readonly)

Returns the value of attribute restart_service.



21
22
23
# File 'lib/boxen/flags.rb', line 21

def restart_service
  @restart_service
end

#srcdirObject (readonly)

Returns the value of attribute srcdir.



16
17
18
# File 'lib/boxen/flags.rb', line 16

def srcdir
  @srcdir
end

#tokenObject (readonly)

Returns the value of attribute token.



15
16
17
# File 'lib/boxen/flags.rb', line 15

def token
  @token
end

#userObject (readonly)

Returns the value of attribute user.



17
18
19
# File 'lib/boxen/flags.rb', line 17

def user
  @user
end

Instance Method Details

#apply(config) ⇒ Object

Apply these flags to ‘config`. Returns `config`.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/boxen/flags.rb', line 160

def apply(config)
  config.debug         = debug?
  config.fde           = fde?     if config.fde?
  config.homedir       = homedir  if homedir
  config.logfile       = logfile  if logfile
  config.         =     if 
  config.token         = token    if token
  config.pretend       = pretend?
  config.profile       = profile?
  config.future_parser = future_parser?
  config.report        = report?
  config.graph         = graph?
  config.srcdir        = srcdir   if srcdir
  config.stealth       = stealth?
  config.user          = user     if user
  config.color         = color?

  config
end

#color?Boolean

Returns:

  • (Boolean)


274
275
276
# File 'lib/boxen/flags.rb', line 274

def color?
  @color
end

#debug?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/boxen/flags.rb', line 180

def debug?
  @debug
end

#disable_service?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/boxen/flags.rb', line 204

def disable_service?
  @disable_service
end

#disable_services?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/boxen/flags.rb', line 196

def disable_services?
  @disable_services
end

#enable_service?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/boxen/flags.rb', line 208

def enable_service?
  @enable_service
end

#enable_services?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/boxen/flags.rb', line 200

def enable_services?
  @enable_services
end

#env?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/boxen/flags.rb', line 184

def env?
  @env
end

#fde?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/boxen/flags.rb', line 188

def fde?
  @fde
end

#future_parser?Boolean

Returns:

  • (Boolean)


254
255
256
# File 'lib/boxen/flags.rb', line 254

def future_parser?
  @future_parser
end

#graph?Boolean

Returns:

  • (Boolean)


262
263
264
# File 'lib/boxen/flags.rb', line 262

def graph?
  @graph
end

#help?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/boxen/flags.rb', line 192

def help?
  @help
end

#list_services?Boolean

Returns:

  • (Boolean)


220
221
222
# File 'lib/boxen/flags.rb', line 220

def list_services?
  @list_services
end

#parse(*args) ⇒ Object

Parse ‘args` as an array of CLI argument Strings. Raises Boxen::Error if anything goes wrong. Returns `self`.



237
238
239
240
241
242
243
244
# File 'lib/boxen/flags.rb', line 237

def parse(*args)
  @args = @options.parse! args.flatten.compact.map(&:to_s)

  self

rescue OptionParser::MissingArgument, OptionParser::InvalidOption => e
  raise Boxen::Error, "#{e.message}\n#@options"
end

#pretend?Boolean

Returns:

  • (Boolean)


246
247
248
# File 'lib/boxen/flags.rb', line 246

def pretend?
  @pretend
end

#profile?Boolean

Returns:

  • (Boolean)


250
251
252
# File 'lib/boxen/flags.rb', line 250

def profile?
  @profile
end

#projects?Boolean

Returns:

  • (Boolean)


266
267
268
# File 'lib/boxen/flags.rb', line 266

def projects?
  @projects
end

#report?Boolean

Returns:

  • (Boolean)


258
259
260
# File 'lib/boxen/flags.rb', line 258

def report?
  @report
end

#restart_service?Boolean

Returns:

  • (Boolean)


212
213
214
# File 'lib/boxen/flags.rb', line 212

def restart_service?
  @restart_service
end

#restart_services?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/boxen/flags.rb', line 216

def restart_services?
  @restart_services
end

#run?Boolean

Returns:

  • (Boolean)


224
225
226
227
228
229
230
231
232
# File 'lib/boxen/flags.rb', line 224

def run?
  !(
    list_services? ||
    restart_services? || restart_service? ||
    enable_services? || enable_service? ||
    disable_services? || disable_service? ||
    help?
  )
end

#stealth?Boolean

Returns:

  • (Boolean)


270
271
272
# File 'lib/boxen/flags.rb', line 270

def stealth?
  @stealth
end

#to_sObject



278
279
280
# File 'lib/boxen/flags.rb', line 278

def to_s
  @options.to_s
end