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(:letsencrypt_account_email, 'The email address associated with your account.', [StringValidator.new]), Field.new(:api_url, 'The URL to the Webfaction API.', [StringValidator.new]), Field.new(:username, 'The username for your Webfaction account.', [StringValidator.new]), Field.new(:password, 'The password for your Webfaction account.', [StringValidator.new]), Field.new(:servername, 'The server on which this application resides (e.g. Web123).', [StringValidator.new]), Field.new(:cert_name, 'The name of the certificate in the Webfaction UI.', [StringValidator.new]), ].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.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 39 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 or version. parse! end |
Instance Attribute Details
#email_configuration ⇒ Object (readonly)
EMail config is special, as it only comes from the config file, due to complexity.
37 38 39 |
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 37 def email_configuration @email_configuration end |
Instance Method Details
#errors ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 52 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
65 66 67 |
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 65 def valid? errors.empty? end |