Class: Boxen::Flags
- Inherits:
-
Object
- Object
- Boxen::Flags
- 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
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#disable_service ⇒ Object
readonly
Returns the value of attribute disable_service.
-
#enable_service ⇒ Object
readonly
Returns the value of attribute enable_service.
-
#homedir ⇒ Object
readonly
Returns the value of attribute homedir.
-
#logfile ⇒ Object
readonly
Returns the value of attribute logfile.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#restart_service ⇒ Object
readonly
Returns the value of attribute restart_service.
-
#srcdir ⇒ Object
readonly
Returns the value of attribute srcdir.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#apply(config) ⇒ Object
Apply these flags to ‘config`.
- #color? ⇒ Boolean
- #debug? ⇒ Boolean
- #disable_service? ⇒ Boolean
- #disable_services? ⇒ Boolean
- #enable_service? ⇒ Boolean
- #enable_services? ⇒ Boolean
- #env? ⇒ Boolean
- #fde? ⇒ Boolean
- #future_parser? ⇒ Boolean
- #help? ⇒ Boolean
-
#initialize(*args) ⇒ Flags
constructor
Create a new instance, optionally providing CLI ‘args` to parse immediately.
- #list_services? ⇒ Boolean
-
#parse(*args) ⇒ Object
Parse ‘args` as an array of CLI argument Strings.
- #pretend? ⇒ Boolean
- #profile? ⇒ Boolean
- #projects? ⇒ Boolean
- #report? ⇒ Boolean
- #restart_service? ⇒ Boolean
- #restart_services? ⇒ Boolean
- #stealth? ⇒ Boolean
- #to_s ⇒ Object
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 |
# 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 @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. = "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 "--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| @login = 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
#args ⇒ Object (readonly)
Returns the value of attribute args.
11 12 13 |
# File 'lib/boxen/flags.rb', line 11 def args @args end |
#disable_service ⇒ Object (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_service ⇒ Object (readonly)
Returns the value of attribute enable_service.
20 21 22 |
# File 'lib/boxen/flags.rb', line 20 def enable_service @enable_service end |
#homedir ⇒ Object (readonly)
Returns the value of attribute homedir.
12 13 14 |
# File 'lib/boxen/flags.rb', line 12 def homedir @homedir end |
#logfile ⇒ Object (readonly)
Returns the value of attribute logfile.
13 14 15 |
# File 'lib/boxen/flags.rb', line 13 def logfile @logfile end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
14 15 16 |
# File 'lib/boxen/flags.rb', line 14 def login @login end |
#restart_service ⇒ Object (readonly)
Returns the value of attribute restart_service.
21 22 23 |
# File 'lib/boxen/flags.rb', line 21 def restart_service @restart_service end |
#srcdir ⇒ Object (readonly)
Returns the value of attribute srcdir.
16 17 18 |
# File 'lib/boxen/flags.rb', line 16 def srcdir @srcdir end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
15 16 17 |
# File 'lib/boxen/flags.rb', line 15 def token @token end |
#user ⇒ Object (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`.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/boxen/flags.rb', line 155 def apply(config) config.debug = debug? config.fde = fde? if config.fde? config.homedir = homedir if homedir config.logfile = logfile if logfile config.login = login if login config.token = token if token config.pretend = pretend? config.profile = profile? config.future_parser = future_parser? config.report = report? config.srcdir = srcdir if srcdir config.stealth = stealth? config.user = user if user config.color = color? config end |
#color? ⇒ Boolean
254 255 256 |
# File 'lib/boxen/flags.rb', line 254 def color? @color end |
#debug? ⇒ Boolean
174 175 176 |
# File 'lib/boxen/flags.rb', line 174 def debug? @debug end |
#disable_service? ⇒ Boolean
198 199 200 |
# File 'lib/boxen/flags.rb', line 198 def disable_service? @disable_service end |
#disable_services? ⇒ Boolean
190 191 192 |
# File 'lib/boxen/flags.rb', line 190 def disable_services? @disable_services end |
#enable_service? ⇒ Boolean
202 203 204 |
# File 'lib/boxen/flags.rb', line 202 def enable_service? @enable_service end |
#enable_services? ⇒ Boolean
194 195 196 |
# File 'lib/boxen/flags.rb', line 194 def enable_services? @enable_services end |
#env? ⇒ Boolean
178 179 180 |
# File 'lib/boxen/flags.rb', line 178 def env? @env end |
#fde? ⇒ Boolean
182 183 184 |
# File 'lib/boxen/flags.rb', line 182 def fde? @fde end |
#future_parser? ⇒ Boolean
238 239 240 |
# File 'lib/boxen/flags.rb', line 238 def future_parser? @future_parser end |
#help? ⇒ Boolean
186 187 188 |
# File 'lib/boxen/flags.rb', line 186 def help? @help end |
#list_services? ⇒ Boolean
214 215 216 |
# File 'lib/boxen/flags.rb', line 214 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`.
221 222 223 224 225 226 227 228 |
# File 'lib/boxen/flags.rb', line 221 def parse(*args) @args = @options.parse! args.flatten.compact.map(&:to_s) self rescue OptionParser::MissingArgument, OptionParser::InvalidOption => e raise Boxen::Error, "#{e.}\n#@options" end |
#pretend? ⇒ Boolean
230 231 232 |
# File 'lib/boxen/flags.rb', line 230 def pretend? @pretend end |
#profile? ⇒ Boolean
234 235 236 |
# File 'lib/boxen/flags.rb', line 234 def profile? @profile end |
#projects? ⇒ Boolean
246 247 248 |
# File 'lib/boxen/flags.rb', line 246 def projects? @projects end |
#report? ⇒ Boolean
242 243 244 |
# File 'lib/boxen/flags.rb', line 242 def report? @report end |
#restart_service? ⇒ Boolean
206 207 208 |
# File 'lib/boxen/flags.rb', line 206 def restart_service? @restart_service end |
#restart_services? ⇒ Boolean
210 211 212 |
# File 'lib/boxen/flags.rb', line 210 def restart_services? @restart_services end |
#stealth? ⇒ Boolean
250 251 252 |
# File 'lib/boxen/flags.rb', line 250 def stealth? @stealth end |
#to_s ⇒ Object
258 259 260 |
# File 'lib/boxen/flags.rb', line 258 def to_s @options.to_s end |