Permalink
Browse files

Now it actually does something.

Fix ARGV. I'm ashamed of myself for this code, but hey, it did fix it!

Browser aliases.

It's a symbol.

Open-source code in company repository should not contain abusive language

I am sometimes frustrated as everyone is, but one should be able
to formulate things in better way
  • Loading branch information...
1 parent 9c17650 commit 61a04be7640e15d86a67fbd5806172a3bdf90437 @botanicus botanicus committed with Almad Jul 20, 2012
Showing with 35 additions and 2 deletions.
  1. +27 −0 bin/apiary
  2. +8 −2 lib/apiary/commands/preview.rb
View
@@ -25,3 +25,30 @@ Nake.args["-H", "--help"] = lambda do |*|
exit
end
+
+# Hack around RubyGems that reportedly ignore nake shebang
+unless File.basename($0) == "nake"
+ # Not using the shebang results in different ARGV.
+ ARGV.unshift("./bin/apiary")
+
+ # This code is not cool. I have to finish nake first.
+ begin
+ #Nake.run(ARGV)
+
+ begin
+ Nake.run_task
+ rescue Nake::TaskNotFound => exception
+ abort exception.message
+ rescue SystemExit => exception
+ exit exception.status
+ rescue Exception => exception
+ require "nake/helpers"
+ print_exception_with_backtrace_and_abort(exception)
+ end
+
+ # exit with exit status of the last command
+ exit $? ? $?.exitstatus : 0
+ rescue Nake::TaskNotFound => exception
+ abort "[#{"ERROR".red}] #{exception.message}"
+ end
+end
@@ -4,7 +4,7 @@
# apiary preview
# apiary preview my_apib_file.apib
# apiary preview [my_apib_file.apib] --api_host=api.apiary.io
-# apiary preview [my_apib_file.apib] --browser=Safari
+# apiary preview [my_apib_file.apib] --browser=chrome
# apiary preview [my_apib_file.apib] --server
# apiary preview [my_apib_file.apib] --server --port=8010
@@ -13,6 +13,12 @@
require "rest_client"
Nake::Task.new(:preview) do |task|
+ BROWSERS ||= {
+ safari: "Safari",
+ chrome: "Google Chrome",
+ firefox: "Firefox"
+ }
+
task.description = "Display preview of local blueprint file"
# Configuration.
@@ -34,7 +40,7 @@ def default_apib_path
end
def browser(options)
- options[:browser] || self.config[:browser]
+ BROWSERS[options[:browser].to_sym] || options[:browser] || BROWSERS[self.config[:browser]] || self.config[:browser]
end
def api_host(options)

0 comments on commit 61a04be

Please sign in to comment.