summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorpseudomuto <david.muto@gmail.com>2013-12-18 19:12:43 -0500
committerpseudomuto <david.muto@gmail.com>2013-12-18 19:12:43 -0500
commitd0eef2dbe9d1178111cd768116a66b32a3a4b2b5 (patch)
tree208b1a82ca184af59c8ac95f6541ea1cc181b588 /bin
parentc3a72795ecab47f94527e079b60549051843caa4 (diff)
moving cli to lib and updating bin file
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dashing115
1 files changed, 5 insertions, 110 deletions
diff --git a/bin/dashing b/bin/dashing
index 9d97700..051acba 100755
--- a/bin/dashing
+++ b/bin/dashing
@@ -1,112 +1,7 @@
#!/usr/bin/env ruby
+require "pathname"
+bin_file = Pathname.new(__FILE__).realpath
+$:.unshift File.expand_path("../../lib", bin_file)
-require 'thor'
-require 'net/http'
-require 'json'
-require 'open-uri'
-
-class MockScheduler
- def method_missing(*args)
- yield
- end
-end
-
-SCHEDULER = MockScheduler.new
-
-module Dashing
-
- class CLI < Thor
- include Thor::Actions
-
- class << self
- attr_accessor :auth_token
-
- def hyphenate(str)
- return str.downcase if str =~ /^[A-Z-]+$/
- str.gsub('_', '-').gsub(/\B[A-Z]/, '-\&').squeeze('-').downcase
- end
- end
-
- attr_accessor :name
-
- no_tasks do
- ['widget', 'dashboard', 'job'].each do |type|
- define_method "generate_#{type}" do |name|
- @name = Thor::Util.snake_case(name)
- directory type.to_sym, File.join("#{type}s")
- end
- end
- end
-
- def self.source_root
- File.expand_path('../../templates', __FILE__)
- end
-
- desc "new PROJECT_NAME", "Sets up ALL THE THINGS needed for your dashboard project."
- def new(name)
- @name = Thor::Util.snake_case(name)
- directory :project, @name
- end
-
- desc "generate (widget/dashboard/job) NAME", "Creates a new widget, dashboard, or job."
- def generate(type, name)
- send("generate_#{type}".to_sym, name)
- rescue NoMethodError => e
- puts "Invalid generator. Either use widget, dashboard, or job"
- end
- map "g" => :generate
-
- desc "install GIST_ID", "Installs a new widget from a gist."
- def install(gist_id)
- public_url = "https://gist.github.com/#{gist_id}"
- gist = JSON.parse(open("https://api.github.com/gists/#{gist_id}").read)
-
- gist['files'].each do |filename, contents|
- if filename.end_with?(".rb")
- create_file File.join(Dir.pwd, 'jobs', filename), contents['content']
- elsif filename.end_with?(".coffee", ".html", ".scss")
- widget_name = File.basename(filename, '.*')
- create_file File.join(Dir.pwd, 'widgets', widget_name, filename), contents['content']
- end
- end
-
- print set_color("Don't forget to edit the ", :yellow)
- print set_color("Gemfile ", :yellow, :bold)
- print set_color("and run ", :yellow)
- print set_color("bundle install ", :yellow, :bold)
- say set_color("if needed. More information for this widget can be found at #{public_url}", :yellow)
-
- rescue OpenURI::HTTPError => e
- say set_color("Could not find gist at #{public_url}"), :red
- end
- map "i" => :install
-
- desc "start", "Starts the server in style!"
- method_option :job_path, :desc => "Specify the directory where jobs are stored"
- def start(*args)
- port_option = args.include?('-p')? '' : ' -p 3030'
- args = args.join(" ")
- command = "bundle exec thin -R config.ru start #{port_option} #{args}"
- command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path]
- system(command)
- end
- map "s" => :start
-
- desc "stop", "Stops the thin server"
- def stop
- command = "bundle exec thin stop"
- system(command)
- end
-
- desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job. Make sure to supply your auth token if you have one set."
- def job(name, auth_token = "")
- Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require file }
- self.class.auth_token = auth_token
- f = File.join(Dir.pwd, "jobs", "#{name}.rb")
- require f
- end
-
- end
-end
-
-Dashing::CLI.start
+require 'dashing'
+Dashing::CLI.start(ARGV)