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
# 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

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



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/boxen/flags.rb', line 102

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
end

#debug?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/boxen/flags.rb', line 118

def debug?
  @debug
end

#env?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/boxen/flags.rb', line 122

def env?
  @env
end

#fde?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/boxen/flags.rb', line 126

def fde?
  @fde
end

#help?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/boxen/flags.rb', line 130

def help?
  @help
end

#parse(*args) ⇒ Object

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



137
138
139
140
141
142
143
144
# File 'lib/boxen/flags.rb', line 137

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)


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

def pretend?
  @pretend
end

#profile?Boolean

Returns:

  • (Boolean)


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

def profile?
  @profile
end

#projects?Boolean

Returns:

  • (Boolean)


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

def projects?
  @projects
end

#stealth?Boolean

Returns:

  • (Boolean)


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

def stealth?
  @stealth
end

#to_sObject



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

def to_s
  @options.to_s
end