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.
-
#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.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#srcdir ⇒ Object
readonly
Returns the value of attribute srcdir.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#apply(config) ⇒ Object
Apply these flags to ‘config`.
- #debug? ⇒ Boolean
- #disable_services? ⇒ Boolean
- #enable_services? ⇒ Boolean
- #env? ⇒ Boolean
- #fde? ⇒ 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
- #stealth? ⇒ Boolean
- #to_s ⇒ Object
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 |
# 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 @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 "--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| @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 "--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 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 |
#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 |
#password ⇒ Object (readonly)
Returns the value of attribute password.
15 16 17 |
# File 'lib/boxen/flags.rb', line 15 def password @password end |
#srcdir ⇒ Object (readonly)
Returns the value of attribute srcdir.
16 17 18 |
# File 'lib/boxen/flags.rb', line 16 def srcdir @srcdir 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`.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/boxen/flags.rb', line 117 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.password = password if password config.pretend = pretend? config.profile = profile? config.srcdir = srcdir if srcdir config.stealth = stealth? config.user = user if user config end |
#debug? ⇒ Boolean
133 134 135 |
# File 'lib/boxen/flags.rb', line 133 def debug? @debug end |
#disable_services? ⇒ Boolean
149 150 151 |
# File 'lib/boxen/flags.rb', line 149 def disable_services? @disable_services end |
#enable_services? ⇒ Boolean
153 154 155 |
# File 'lib/boxen/flags.rb', line 153 def enable_services? @enable_services end |
#env? ⇒ Boolean
137 138 139 |
# File 'lib/boxen/flags.rb', line 137 def env? @env end |
#fde? ⇒ Boolean
141 142 143 |
# File 'lib/boxen/flags.rb', line 141 def fde? @fde end |
#help? ⇒ Boolean
145 146 147 |
# File 'lib/boxen/flags.rb', line 145 def help? @help end |
#list_services? ⇒ Boolean
157 158 159 |
# File 'lib/boxen/flags.rb', line 157 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`.
164 165 166 167 168 169 170 171 |
# File 'lib/boxen/flags.rb', line 164 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
173 174 175 |
# File 'lib/boxen/flags.rb', line 173 def pretend? @pretend end |
#profile? ⇒ Boolean
177 178 179 |
# File 'lib/boxen/flags.rb', line 177 def profile? @profile end |
#projects? ⇒ Boolean
181 182 183 |
# File 'lib/boxen/flags.rb', line 181 def projects? @projects end |
#stealth? ⇒ Boolean
185 186 187 |
# File 'lib/boxen/flags.rb', line 185 def stealth? @stealth end |
#to_s ⇒ Object
189 190 191 |
# File 'lib/boxen/flags.rb', line 189 def to_s @options.to_s end |