Skip to content

Commit

Permalink
Move command-line handling to separate wildcat_publish.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
brentsimmons committed Apr 3, 2018
1 parent 3f6e8db commit f59a255
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
9 changes: 5 additions & 4 deletions server/wildcat.cgi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby -wKU
#!/usr/bin/env ruby -wU

# Implements MetaWeblog API.
# Does not implement Blogger API.
Expand Down Expand Up @@ -43,7 +43,7 @@ class MetaWeblogCommand

def initialize(username, password, blog_id)
# TODO: authenticate
raise XMLRPC::FaultException.new(EXCEPTION_MESSAGE_LOGIN_INVALID, EXCEPTION_CODE_LOGIN_INVALID)
# raise XMLRPC::FaultException.new(EXCEPTION_MESSAGE_LOGIN_INVALID, EXCEPTION_CODE_LOGIN_INVALID)
@blog_id = blog_id
@wildcat = wildcat
end
Expand Down Expand Up @@ -126,6 +126,7 @@ class MetaWeblogCommand
end

websites_folder = ENV[ENV_KEY_WEBSITES_FOLDER]
puts websites_folder
if websites_folder.nil? || websites_folder.empty?
raise_cant_find_websites_folder
end
Expand Down Expand Up @@ -201,7 +202,7 @@ end
#
# end

class MetaWeblogAPI
class MetaWeblog

def getRecentPosts(blog_id, username, password, number_of_posts)
command = MetaWeblogCommand.new(username, password, blog_id)
Expand Down Expand Up @@ -239,5 +240,5 @@ class MetaWeblogAPI
end

s = XMLRPC::CGIServer.new()
s.add_handler("metaWeblog", MetaWeblogAPI.new())
s.add_handler("metaWeblog", MetaWeblog.new())
s.serve()
31 changes: 0 additions & 31 deletions wildcat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,3 @@ def perform_rsync_if_needed
WildcatUtils.rsync_remote(@settings.output_folder, rsync_path)
end
end

# Command-line
# Assumes the current directory is inside the top level of the website project folder.
# Call it like this:
# ruby /path/to/wildcat.rb
#
# Default settings file is wildcat_settings.
# To do a preview (for instance) instead, specify a separate settings file, as in:
# ruby wildcat.rb --settings preview_settings
#
# Tip: create an alias for your shell to shorten things.
# For instance, I use pi — “Publish Inessential” — as an alias like this:
# pushd "/Users/brent/path/to/inessential.com";ruby wildcat.rb;popd

settings_file = nil
next_argument_is_settings = false
found_alternate_settings_file = false

ARGV.each do |arg|
if next_argument_is_settings && !found_alternate_settings_file
settings_file = arg
found_alternate_settings_file = true
end
if arg == '--settings' && !found_alternate_settings_file
next_argument_is_settings = true
end
end

folder = Dir.pwd
wildcat = Wildcat.new(folder, settings_file)
wildcat.build
34 changes: 34 additions & 0 deletions wildcat_publish.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env ruby -wU

require_relative 'wildcat'

# Command-line
# Assumes the current directory is inside the top level of the website project folder.
# Call it like this:
# ruby /path/to/wildcat_publish.rb
#
# Default settings file is wildcat_settings.
# To do a preview (for instance) instead, specify a separate settings file, as in:
# ruby wildcat_publish.rb --settings preview_settings
#
# Tip: create an alias for your shell to shorten things.
# For instance, I use pi — “Publish Inessential” — as an alias like this:
# pushd "/Users/brent/path/to/inessential.com";ruby wildcat_publish.rb;popd

settings_file = nil
next_argument_is_settings = false
found_alternate_settings_file = false

ARGV.each do |arg|
if next_argument_is_settings && !found_alternate_settings_file
settings_file = arg
found_alternate_settings_file = true
end
if arg == '--settings' && !found_alternate_settings_file
next_argument_is_settings = true
end
end

folder = Dir.pwd
wildcat = Wildcat.new(folder, settings_file)
wildcat.build

0 comments on commit f59a255

Please sign in to comment.