bin/jekyll-auth in jekyll-auth-2.0.0 vs bin/jekyll-auth in jekyll-auth-2.1.0
- old
+ new
@@ -1,22 +1,21 @@
#!/usr/bin/env ruby
# Command-line interface for jekyll-auth
-require 'mercenary'
-require 'jekyll-auth'
-require 'open3'
+require "mercenary"
+require "jekyll-auth"
+require "open3"
Mercenary.program("jekyll-auth") do |p|
- p.version JekyllAuth::VERSION
+ p.version JekyllAuth::VERSION
p.description "A simple way to use Github OAuth to serve a protected jekyll site to your GitHub organization"
- p.syntax 'jekyll-auth <subcommand> options'
+ p.syntax "jekyll-auth <subcommand> options"
p.command(:new) do |c|
- c.syntax 'new'
+ c.syntax "new"
c.description "Initialize an existing Jekyll site as a Jekyll Auth site"
- c.action do |args, options|
-
+ c.action do |_args, _options|
JekyllAuth::Commands.copy_templates
if JekyllAuth::Commands.changed?
puts "Looks like we've made some changes, you may want to do a git commit and git push sometime soon".yellow
end
@@ -27,27 +26,26 @@
# Run the standard jekyll build command
# Called by Rake task, to allow the gem
# to add functionality here in the future
p.command(:build) do |c|
- c.syntax 'build'
+ c.syntax "build"
c.description "Build the Jekyll site"
- c.action do |args, options|
- require 'jekyll'
+ c.action do |_args, options|
+ require "jekyll"
Jekyll::Commands::Build.process(options)
end
end
p.command(:team_id) do |c|
- c.syntax 'team_id --org <ORG> --team <TEAM>'
+ c.syntax "team_id --org <ORG> --team <TEAM>"
c.description "Retrieve a team's ID"
- c.option 'org', '--org <ORG>', 'The GitHub Organization, e.g., "jekyll"'
- c.option 'team', '--team <TEAM>', 'The team name, e.g., "maintainers"'
+ c.option "org", "--org <ORG>", 'The GitHub Organization, e.g., "jekyll"'
+ c.option "team", "--team <TEAM>", 'The team name, e.g., "maintainers"'
- c.action do |args, options|
-
- if !JekyllAuth::Commands.env_var_set? "GITHUB_TOKEN"
+ c.action do |_args, options|
+ unless JekyllAuth::Commands.env_var_set? "GITHUB_TOKEN"
puts "You'll need to go to https://github.com/settings/tokens/new and create a personal access token".red
puts "Once you've got the token, prefix the jekyll-auth command with GITHUB_TOKEN=[YOUR TOKEN]".red
puts "You can also add it to a `.env` file in this directory".red
exit 1
end
@@ -72,38 +70,41 @@
end
p.command(:serve) do |c|
c.syntax "serve"
c.description "Run Jekyll Auth site locally"
- c.action do |args, options|
+ c.option "host", "--host <HOST>", "Listen at the given hostname, e.g., 127.0.0.1"
+ c.option "port", "--port <PORT>", "Listen on the given port, e.g., 4000"
+ c.action do |_args, options|
# Ensure environmental variables are set
- unless ["GITHUB_CLIENT_ID", "GITHUB_CLIENT_SECRET"].all? { |v| JekyllAuth::Commands.env_var_set?(v) }
+ unless %w(GITHUB_CLIENT_ID GITHUB_CLIENT_SECRET).all? { |v| JekyllAuth::Commands.env_var_set?(v) }
puts "Whoops. Looks like you forgot to tell Jekyll Auth about your app".red
puts "Be sure to run export GITHUB_CLIENT_ID=[client id], export GITHUB_CLIENT_SECRET=[client secret], and export GITHUB_ORG_NAME=[org name] (or GITHUB_TEAM_ID)".red
puts "See the readme for more information on where to find these".red
exit 1
end
# build site
p.go ["build"]
+ host = options["host"] || "0.0.0.0"
+ port = options["port"] || "4000"
+
puts "Spinning up the server with authentication. Use CTRL-C to stop."
puts "To preview the site without authentication, use the `jekyll serve` command"
- JekyllAuth::Commands.execute_command "bundle", "exec", "rackup", "-p", "4000"
-
+ JekyllAuth::Commands.execute_command "bundle", "exec", "rackup", "-o", host, "-p", port
end
end
p.command(:setup) do |c|
c.syntax "setup"
c.description "Configure Heroku for use with your Jekyll Auth site"
c.option "client_id", "--client_id", "Your oauth app client id"
c.option "client_secret", "--client_secret", "Your oauth app client secret"
c.option "team_id", "--team_id", "The team to authenticate against"
c.option "org_name", "--org_name", "An organization to authenticate against"
- c.action do |args, options|
-
+ c.action do |_args, options|
if find_executable("heroku").nil?
say "Looks like we're missing the Heroku client. Let's see if we can't install it..."
JekyllAuth::Commands.execute_command "wget", "-qO-", "https://toolbelt.heroku.com/install.sh", "|", "sh"
end