Class: Fig::Command::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/command/options.rb

Overview

Command-line processing.

Constant Summary collapse

USAGE =
<<-EOF
Usage:

fig [...] [DESCRIPTOR] [--update | --update-if-missing] [-- COMMAND]
fig [...] [DESCRIPTOR] [--update | --update-if-missing] [--command-extra-args VALUES]

fig {--publish | --publish-local} DESCRIPTOR
    [--resource PATH]
    [--archive  PATH]
    [--include  DESCRIPTOR]
    [--override DESCRIPTOR]
    [--force]
    [...]

fig --clean DESCRIPTOR [...]

fig --get VARIABLE                                         [DESCRIPTOR] [...]
fig --list-configs                                         [DESCRIPTOR] [...]
fig --list-dependencies [--list-tree] [--list-all-configs] [DESCRIPTOR] [...]
fig --list-variables [--list-tree] [--list-all-configs]    [DESCRIPTOR] [...]
fig {--list-local | --list-remote}                                      [...]

fig {--version | --help}


A DESCRIPTOR looks like <package name>[/<version>][:<config>] e.g. "foo",
"foo/1.2.3", and "foo/1.2.3:default". Whether ":<config>" and "/<version>" are
required or allowed is dependent upon what your are doing.

Standard options (represented as "[...]" above):

    [--set    VARIABLE=VALUE]
    [--append VARIABLE=VALUE]
    [--file PATH] [--no-file]
    [--config CONFIG]
    [--login]
    [--log-level LEVEL] [--log-config PATH]
    [--figrc PATH] [--no-figrc]
    [--suppress-warning-include-statement-missing-version]

Environment variables:

FIG_REMOTE_URL (required),
FIG_HOME (path to local repository cache, defaults to $HOME/.fighome).
EOF
LOG_LEVELS =
%w[ off fatal error warn info debug all ]
LOG_ALIASES =
{ 'warning' => 'warn' }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



71
72
73
# File 'lib/fig/command/options.rb', line 71

def initialize(argv)
  process_command_line(argv)
end

Instance Attribute Details

#command_extra_argvObject (readonly)

Returns the value of attribute command_extra_argv.



67
68
69
# File 'lib/fig/command/options.rb', line 67

def command_extra_argv
  @command_extra_argv
end

#descriptorObject (readonly)

Returns the value of attribute descriptor.



68
69
70
# File 'lib/fig/command/options.rb', line 68

def descriptor
  @descriptor
end

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



69
70
71
# File 'lib/fig/command/options.rb', line 69

def exit_code
  @exit_code
end

#shell_commandObject (readonly)

Returns the value of attribute shell_command.



66
67
68
# File 'lib/fig/command/options.rb', line 66

def shell_command
  @shell_command
end

Instance Method Details

#archivesObject



75
76
77
# File 'lib/fig/command/options.rb', line 75

def archives()
  return @options[:archives]
end

#clean?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/fig/command/options.rb', line 79

def clean?()
  return @options[:clean]
end

#configObject



83
84
85
# File 'lib/fig/command/options.rb', line 83

def config()
  return @options[:config]
end

#environment_statementsObject



135
136
137
# File 'lib/fig/command/options.rb', line 135

def environment_statements()
  return @options[:environment_statements]
end

#figrcObject



87
88
89
# File 'lib/fig/command/options.rb', line 87

def figrc()
  return @options[:figrc]
end

#force?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/fig/command/options.rb', line 91

def force?()
  return @options[:force]
end

#getObject



95
96
97
# File 'lib/fig/command/options.rb', line 95

def get()
  return @options[:get]
end

#helpObject

This needs to be public for efficient use of custom command.rb wrappers.



213
214
215
216
217
218
219
220
221
222
223
# File 'lib/fig/command/options.rb', line 213

def help()
  puts @help_message
  puts <<-'END_MESSAGE'
      --                           end of Fig options; anything after this is used as a command to run
      --command-extra-args         end of Fig options; anything after this is appended to the end of a
                                   "command" statement in a "config" block.

  END_MESSAGE

  return 0
end

#help?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/fig/command/options.rb', line 99

def help?()
  return @options[:help]
end

#homeObject



103
104
105
# File 'lib/fig/command/options.rb', line 103

def home()
  return @options[:home]
end

#list_all_configs?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/fig/command/options.rb', line 115

def list_all_configs?()
  return @options[:list_all_configs]
end

#list_tree?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/fig/command/options.rb', line 111

def list_tree?()
  return @options[:list_tree]
end

#listingObject



107
108
109
# File 'lib/fig/command/options.rb', line 107

def listing()
  return @options[:listing]
end

#log_configObject



119
120
121
# File 'lib/fig/command/options.rb', line 119

def log_config()
  return @options[:log_config]
end

#log_levelObject



127
128
129
# File 'lib/fig/command/options.rb', line 127

def log_level()
  return @options[:log_level]
end

#login?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/fig/command/options.rb', line 123

def login?()
  return @options[:login]
end

#no_figrc?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/fig/command/options.rb', line 131

def no_figrc?()
  return @options[:no_figrc]
end

#package_definition_fileObject



139
140
141
# File 'lib/fig/command/options.rb', line 139

def package_definition_file()
  return @options[:package_definition_file]
end

#publish?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/fig/command/options.rb', line 143

def publish?()
  return @options[:publish]
end

#publish_local?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/fig/command/options.rb', line 147

def publish_local?()
  return @options[:publish_local]
end

#publishing?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/fig/command/options.rb', line 151

def publishing?()
  return publish? || publish_local?
end

#reset_environment?Boolean

Answers whether we should reset the environment to nothing, sort of like the standardized environment that cron(1) creates. At present, we’re only setting this when we’re listing variables. One could imagine allowing this to be set by a command-line option in general; if we do this, the Environment class will need to be changed to support deletion of values from ENV.

Returns:

  • (Boolean)


185
186
187
# File 'lib/fig/command/options.rb', line 185

def reset_environment?()
  return listing() == :variables
end

#resourcesObject



155
156
157
# File 'lib/fig/command/options.rb', line 155

def resources()
  return @options[:resources]
end

#strip_shell_command(argv) ⇒ Object

This needs to be public for efficient use of custom command.rb wrappers.



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/fig/command/options.rb', line 190

def strip_shell_command(argv)
  argv.each_with_index do |arg, i|
    terminating_option = nil

    case arg
      when '--'
        terminating_option = arg
        @shell_command = argv[(i+1)..-1]
      when '--command-extra-args'
        terminating_option = arg
        @command_extra_argv = argv[(i+1)..-1]
    end

    if terminating_option
      argv.slice!(i..-1)
      break
    end
  end

  return
end

#suppress_warning_include_statement_missing_version?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/fig/command/options.rb', line 159

def suppress_warning_include_statement_missing_version?()
  return @options[:suppress_warning_include_statement_missing_version]
end

#update?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/fig/command/options.rb', line 163

def update?()
  return @options[:update]
end

#update_if_missing?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/fig/command/options.rb', line 167

def update_if_missing?()
  return @options[:update_if_missing]
end

#updating?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/fig/command/options.rb', line 171

def updating?()
  return update? || update_if_missing?
end

#version?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/fig/command/options.rb', line 175

def version?()
  return @options[:version]
end