This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,71 @@ | ||
require "option_parser" | ||
require "./crankypants" | ||
require "./crankypants/web" | ||
|
||
# Process command line options | ||
OptionParser.parse! do |parser| | ||
parser.banner = <<-EOF | ||
Crankypants #{Crankypants::VERSION} | ||
require "option_parser" | ||
require "colorize" | ||
|
||
Usage: crankypants [arguments] | ||
module Crankypants | ||
module CLI | ||
def self.run! | ||
parse_cli_options! | ||
|
||
EOF | ||
# Log Crecto queries to STDOUT | ||
{% unless flag?(:release) %} | ||
Crecto::DbLogger.set_handler(STDOUT) | ||
{% end %} | ||
|
||
parser.on "-p PORT", "--port=PORT", "The port to listen on (default: 3000)" do |port| | ||
Crankypants.settings.port = port.to_i32 | ||
end | ||
Habitat.raise_if_missing_settings! | ||
Crankypants.prepare_database | ||
print_banner! | ||
Crankypants::Web.run | ||
end | ||
|
||
parser.on "-b IP", "--binding=IP", "The interface to bind to (default: 0.0.0.0)" do |interface| | ||
Crankypants.settings.interface = interface | ||
end | ||
private def self.parse_cli_options! | ||
OptionParser.parse! do |parser| | ||
parser.banner = <<-EOF | ||
Crankypants #{Crankypants::VERSION} | ||
parser.on "--asset-host HOST", "Host to load assets from (default: blank)" do |arg| | ||
Crankypants.settings.asset_host = arg | ||
end | ||
Usage: crankypants [arguments] | ||
parser.on "-h", "--help", "Show this help" do | ||
puts parser | ||
exit | ||
end | ||
end | ||
EOF | ||
|
||
# Log Crecto queries to STDOUT | ||
{% unless flag?(:release) %} | ||
Crecto::DbLogger.set_handler(STDOUT) | ||
{% end %} | ||
parser.on "-p PORT", "--port=PORT", "The port to listen on (default: 3000)" do |port| | ||
Crankypants.settings.port = port.to_i32 | ||
end | ||
|
||
# Check settings | ||
# | ||
Habitat.raise_if_missing_settings! | ||
parser.on "-b IP", "--binding=IP", "The interface to bind to (default: 0.0.0.0)" do |interface| | ||
Crankypants.settings.interface = interface | ||
end | ||
|
||
parser.on "--asset-host HOST", "Host to load assets from (default: blank)" do |arg| | ||
Crankypants.settings.asset_host = arg | ||
end | ||
|
||
parser.on "-h", "--help", "Show this help" do | ||
puts parser | ||
exit | ||
end | ||
end | ||
end | ||
|
||
private def self.print_banner! | ||
base_url = "http://#{Crankypants.settings.interface}:#{Crankypants.settings.port}/" | ||
puts ["Welcome to ", "CrankyPants".colorize(:white), "! ", ":D ".colorize(:yellow), "(#{Crankypants::VERSION})".colorize(:dark_gray)].join | ||
puts ["-> ".colorize(:green), "Your blog: ", base_url.colorize(:cyan)].join | ||
|
||
# We only want to mount /app and /api if the required environment | ||
# variables are available. | ||
# | ||
if ENV["CRANKY_LOGIN"]? && ENV["CRANKY_PASSWORD"]? | ||
puts ["-> ".colorize(:green), "Your app: ", "#{base_url}app/".colorize(:cyan)].join | ||
else | ||
puts ["-> ".colorize(:yellow), "/app".colorize(:white), " and ", "/api".colorize(:white), " are disabled. Please provide CRANKY_LOGIN and CRANKY_PASSWORD!"].join | ||
end | ||
|
||
puts ["Enjoy! ", "<3<3<3".colorize(:red)].join | ||
puts | ||
end | ||
end | ||
end | ||
|
||
# Fire things up. | ||
# | ||
Crankypants.prepare_database | ||
Crankypants::Web.run | ||
Crankypants::CLI.run! |