Class: Gitdocs::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/gitdocs/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



7
# File 'lib/gitdocs/cli.rb', line 7

def self.source_root; File.expand_path('../../', __FILE__); end

Instance Method Details

#add(path) ⇒ Object



41
42
43
44
45
# File 'lib/gitdocs/cli.rb', line 41

def add(path)
  self.config.add_path(path)
  say "Added path #{path} to doc list"
  self.restart if self.running?
end

#clearObject



55
56
57
58
# File 'lib/gitdocs/cli.rb', line 55

def clear
  self.config.clear
  say "Cleared paths from gitdocs"
end

#configObject



77
78
79
# File 'lib/gitdocs/cli.rb', line 77

def config
  # TODO make this work
end

#create(path, remote) ⇒ Object



61
62
63
64
65
66
# File 'lib/gitdocs/cli.rb', line 61

def create(path, remote)
  FileUtils.mkdir_p(File.dirname(path))
  system("git clone -q #{remote} #{ShellTools.escape(path)}") or raise "Unable to clone into #{path}"
  self.add(path)
  say "Created #{path} path for gitdoc"
end

#help(task = nil, subcommand = false) ⇒ Object



82
83
84
85
# File 'lib/gitdocs/cli.rb', line 82

def help(task = nil, subcommand = false)
  say "\nGitdocs: Collaborate with ease.\n\n"
  task ? self.class.task_help(shell, task) : self.class.help(shell, subcommand)
end

#restartObject



35
36
37
38
# File 'lib/gitdocs/cli.rb', line 35

def restart
  self.stop
  self.start
end

#rm(path) ⇒ Object



48
49
50
51
52
# File 'lib/gitdocs/cli.rb', line 48

def rm(path)
  self.config.remove_path(path)
  say "Removed path #{path} from doc list"
  self.restart if self.running?
end

#startObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitdocs/cli.rb', line 12

def start
  if self.stopped? && !options[:debug]
    self.runner.execute { Gitdocs.start(:port => options[:port]) }
    self.running? ? say("Started gitdocs", :green) : say("Failed to start gitdocs", :red)
  elsif self.stopped? && options[:debug]
    say "Starting in debug mode", :yellow
    Gitdocs.start(:debug => true, :port => options[:port])
  else # already running
    say "Gitdocs is already running, please use restart", :red
  end
end

#statusObject



69
70
71
72
73
74
# File 'lib/gitdocs/cli.rb', line 69

def status
  say "GitDoc v#{VERSION}"
  say "Running: #{self.running?}"
  say "Watching paths:"
  say self.config.shares.map { |s| "  - #{s.path}" }.join("\n")
end

#stopObject



25
26
27
28
29
30
31
32
# File 'lib/gitdocs/cli.rb', line 25

def stop
  if self.running?
    self.runner.execute(:kill => true)
    say "Stopped gitdocs", :red
  else # not running
    say "Gitdocs is not running", :red
  end
end