Class: LetsencryptWebfaction::ArgsParser
- Inherits:
-
Object
- Object
- LetsencryptWebfaction::ArgsParser
- Defined in:
- lib/letsencrypt_webfaction/args_parser.rb,
lib/letsencrypt_webfaction/args_parser/field.rb,
lib/letsencrypt_webfaction/args_parser/array_validator.rb,
lib/letsencrypt_webfaction/args_parser/string_validator.rb,
lib/letsencrypt_webfaction/args_parser/defined_values_validator.rb
Defined Under Namespace
Classes: ArrayValidator, DefinedValuesValidator, Field, StringValidator
Constant Summary collapse
- BANNER =
'Usage: letsencrypt_webfaction [options]'.freeze
- DEFAULTS_PATH =
'config.defaults.yml'.freeze
- VALID_KEY_SIZES =
[2048, 4096].freeze
- FIELDS =
[ Field::IntegerField.new(:key_size, 'Size of private key (e.g. 4096)', [DefinedValuesValidator.new(VALID_KEY_SIZES)]), Field.new(:endpoint, 'ACME endpoint (e.g. https://acme-v01.api.letsencrypt.org/)', [StringValidator.new]), Field::ListField.new(:domains, 'Comma separated list of domains. The first one will be the common name.', [ArrayValidator.new]), Field.new(:public, 'Location on the filesystem served by the desired site (e.g. ~/webapps/myapp/public_html)', [StringValidator.new]), Field.new(:output_dir, 'Location on the filesystem to which the certs will be saved.', [StringValidator.new]), Field.new(:support_email, 'The email address of the ISP support.', []), Field.new(:account_email, 'The email address associated with your account.', [StringValidator.new]), Field.new(:admin_notification_email, 'The email address associated with your account. Defaults to the value of account_email.', []), Field.new(:letsencrypt_account_email, 'The email address associated with your account. Defaults to the value of account_email.', []), ].freeze
Instance Attribute Summary collapse
-
#email_configuration ⇒ Object
readonly
EMail config is special, as it only comes from the config file, due to complexity.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(options) ⇒ ArgsParser
constructor
A new instance of ArgsParser.
- #valid? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ ArgsParser
Returns a new instance of ArgsParser.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 35 def initialize() @options = @errors = {} # Set defaults from default config file. file_path = File.join(File.dirname(__FILE__), '../../', DEFAULTS_PATH) load_config!(File.(file_path)) # TODO: Rework this to not exit on instantiation due to help text. parse! end |
Instance Attribute Details
#email_configuration ⇒ Object (readonly)
EMail config is special, as it only comes from the config file, due to complexity.
33 34 35 |
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 33 def email_configuration @email_configuration end |
Instance Method Details
#errors ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 48 def errors errors = {} FIELDS.each do |field| val = instance_variable_get("@#{field.identifier}") next if field.valid? val errors[field.identifier] ||= [] errors[field.identifier] << "Invalid #{field.identifier} '#{val}'" end errors end |
#valid? ⇒ Boolean
61 62 63 |
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 61 def valid? errors.empty? end |