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.



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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/boxen/flags.rb', line 22

def initialize(*args)
  @args             = []
  @debug            = false
  @env              = false
  @fde              = true
  @help             = false
  @pretend          = false
  @profile          = false
  @projects         = false
  @stealth          = false
  @disable_services = false
  @enable_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 "--env", "Show useful environment variables." do
      @env = true
    end

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

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

    o.on "--enable-services", "Enable Boxen services." do
      @enable_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 "--password PASSWORD", "Your GitHub password." do |password|
      @password = password
    end

    o.on "--profile", "Profile the Puppet run." do
      @profile = 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", "Enable 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

#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

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#srcdirObject (readonly)

Returns the value of attribute srcdir.



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

def srcdir
  @srcdir
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`.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/boxen/flags.rb', line 122

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.password = password if password
  config.pretend  = pretend?
  config.profile  = profile?
  config.srcdir   = srcdir   if srcdir
  config.stealth  = stealth?
  config.user     = user     if user
  config.color    = color?

  config
end

#color?Boolean

Returns:

  • (Boolean)


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

def color?
  @color
end

#debug?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/boxen/flags.rb', line 139

def debug?
  @debug
end

#disable_services?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/boxen/flags.rb', line 155

def disable_services?
  @disable_services
end

#enable_services?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/boxen/flags.rb', line 159

def enable_services?
  @enable_services
end

#env?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/boxen/flags.rb', line 143

def env?
  @env
end

#fde?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/boxen/flags.rb', line 147

def fde?
  @fde
end

#help?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/boxen/flags.rb', line 151

def help?
  @help
end

#list_services?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/boxen/flags.rb', line 163

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`.



170
171
172
173
174
175
176
177
# File 'lib/boxen/flags.rb', line 170

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)


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

def pretend?
  @pretend
end

#profile?Boolean

Returns:

  • (Boolean)


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

def profile?
  @profile
end

#projects?Boolean

Returns:

  • (Boolean)


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

def projects?
  @projects
end

#stealth?Boolean

Returns:

  • (Boolean)


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

def stealth?
  @stealth
end

#to_sObject



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

def to_s
  @options.to_s
end