lib/gitdocs/cli.rb in gitdocs-0.3.3 vs lib/gitdocs/cli.rb in gitdocs-0.3.4
- old
+ new
@@ -7,36 +7,34 @@
def self.source_root; File.expand_path('../../', __FILE__); end
desc "start", "Starts a daemonized gitdocs process"
method_option :debug, :type => :boolean, :aliases => "-D"
def start
- if !self.running? && !options[:debug]
- self.runner(:daemonize => true, :pid_path => self.pid_path).execute { Gitdocs.run }
- until_true(5) { self.running? }
+ if self.stopped? && !options[:debug]
+ self.runner.execute { Gitdocs.run }
self.running? ? say("Started gitdocs", :green) : say("Failed to start gitdocs", :red)
- elsif !self.running? && options[:debug]
- say "Running in debug mode", :yellow
+ elsif self.stopped? && options[:debug]
+ say "Starting in debug mode", :yellow
Gitdocs.run(nil, true)
else # already running
say "Gitdocs is already running, please use restart", :red
end
end
desc "stop", "Stops the gitdocs process"
def stop
if self.running?
- self.runner(:kill => true, :pid_path => self.pid_path).execute
+ self.runner.execute(:kill => true)
say "Stopped gitdocs", :red
else # not running
say "Gitdocs is not running", :red
end
end
desc "restart", "Restarts the gitdocs process"
def restart
self.stop
- until_true(5) { self.running? }
self.start
end
desc "add PATH", "Adds a path to gitdocs"
def add(path)
@@ -52,11 +50,11 @@
self.restart if self.running?
end
desc "clear", "Clears all paths from gitdocs"
def clear
- self.config.paths = []
+ self.config.clear
say "Cleared paths from gitdocs"
end
desc "create PATH REMOTE", "Creates a new gitdoc root based on an existing remote"
def create(path, remote)
@@ -86,37 +84,26 @@
end
# Helpers for thor
no_tasks do
def runner(options={})
- Dante::Runner.new('gitdocs', options)
+ Dante::Runner.new('gitdocs', options.merge(:debug => false, :daemonize => true, :pid_path => self.pid_path))
end
def config
@config ||= Configuration.new
end
def running?
- return false unless File.exist?(pid_path)
- Process.kill 0, File.read(pid_path).to_i
- true
- rescue Errno::ESRCH
- false
+ self.runner.daemon_running?
end
- def pid_path
- "/tmp/gitdocs.pid"
+ def stopped?
+ self.runner.daemon_stopped?
end
- # Runs until the block condition is met or the retry_count is exceeded
- # until_true(10) { ...return_condition... }
- def until_true(retry_count, &block)
- count = 0
- while count < retry_count && block.call != true
- count += 1
- sleep(1)
- end
- count < retry_count
+ def pid_path
+ "/tmp/gitdocs.pid"
end
end
end
end