Skip to content

Commit f5f07eb

Browse files
Added template path CLI option
1 parent 9b9eb6a commit f5f07eb

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ruby-nginx (1.0.0.pre.beta.3)
4+
ruby-nginx (1.0.0.pre.beta.4)
55
erb
66
thor
77
tty-command (~> 0.10, >= 0.10.1)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Options:
156156
-r, [--root-path=ROOT_PATH] # default: $PWD
157157
-s, [--ssl], [--no-ssl], [--skip-ssl] # default: false
158158
-l, [--log], [--no-log], [--skip-log] # default: false
159+
-t, [--template-path=TEMPLATE_PATH] # default: [GEM_PATH]/nginx/templates/nginx.conf
159160
-cert-file, [--ssl-certificate-path=SSL_CERTIFICATE_PATH] # default: ~/.ruby-nginx/certs/_[DOMAIN].pem
160161
-key-file, [--ssl-certificate-key-path=SSL_CERTIFICATE_KEY_PATH] # default: ~/.ruby-nginx/certs/_[DOMAIN]-key.pem
161162
-access-log, [--access-log-path=ACCESS_LOG_PATH] # default: ~/.ruby-nginx/logs/[DOMAIN].access.log

lib/ruby/nginx/cli.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def self.default_paths(param)
2525
method_option :root_path, aliases: "-r", type: :string, desc: "default: $PWD"
2626
method_option :ssl, aliases: "-s", type: :boolean, desc: defaults(:ssl)
2727
method_option :log, aliases: "-l", type: :boolean, desc: defaults(:log)
28+
method_option :template_path, aliases: "-t", type: :string, desc: "default: [GEM_PATH]/nginx/templates/nginx.conf"
2829
method_option :ssl_certificate_path, aliases: "-cert-file", type: :string, desc: default_paths(:ssl_certificate_path)
2930
method_option :ssl_certificate_key_path, aliases: "-key-file", type: :string, desc: default_paths(:ssl_certificate_key_path)
3031
method_option :access_log_path, aliases: "-access-log", type: :string, desc: default_paths(:access_log_path)
@@ -35,6 +36,7 @@ def add
3536
port: options.port,
3637
host: options.host,
3738
root_path: options.root_path,
39+
template_path: options.template_path,
3840
ssl: options.ssl,
3941
log: options.log,
4042
ssl_certificate_path: options.ssl_certificate_path,

lib/ruby/nginx/configuration.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def generate!
3636
create_ssl_certs! if options[:ssl]
3737
create_log_files! if options[:log]
3838

39-
ERB.new(File.read(options[:template_path])).result(binding)
39+
ERB.new(load_template).result(binding)
4040
end
4141

4242
def defaults
@@ -82,6 +82,16 @@ def apply_dynamic_defaults!
8282
self.options = default_paths.merge(options)
8383
end
8484

85+
def load_template
86+
File.read(options[:template_path])
87+
rescue Errno::EISDIR
88+
raise Ruby::Nginx::AbortError, "Template is a directory: #{options[:template_path]}"
89+
rescue Errno::ENOENT
90+
raise Ruby::Nginx::AbortError, "Template does not exist at: #{options[:template_path]}"
91+
rescue => e
92+
raise Ruby::Nginx::AbortError, "Failed to read template.", cause: e
93+
end
94+
8595
def create_ssl_certs!
8696
System::Mkcert.create!(
8797
options[:domain],

lib/ruby/nginx/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Ruby
44
module Nginx
5-
VERSION = "1.0.0-beta.3"
5+
VERSION = "1.0.0-beta.4"
66

77
Version = Gem::Version
88
end

0 commit comments

Comments
 (0)