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



11
12
13
# File 'lib/gitdocs/cli.rb', line 11

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

Instance Method Details

#add(path) ⇒ Object



59
60
61
62
63
# File 'lib/gitdocs/cli.rb', line 59

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

#clearObject



74
75
76
77
# File 'lib/gitdocs/cli.rb', line 74

def clear
  config.clear
  say 'Cleared paths from gitdocs'
end

#create(path, remote) ⇒ Object



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

def create(path, remote)
  Gitdocs::Repository.clone(path, remote)
  add(path)
  say "Created #{path} path for gitdoc"
end

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



133
134
135
136
# File 'lib/gitdocs/cli.rb', line 133

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

#openObject



116
117
118
119
120
121
122
123
124
125
# File 'lib/gitdocs/cli.rb', line 116

def open
  unless running?
    say 'Gitdocs is not running, cannot open the UI', :red
    return
  end

  web_port = options[:port]
  web_port ||= config.web_frontend_port
  Launchy.open("http://localhost:#{web_port}/")
end

#restartObject



52
53
54
55
# File 'lib/gitdocs/cli.rb', line 52

def restart
  stop
  start
end

#rm(path) ⇒ Object



67
68
69
70
71
# File 'lib/gitdocs/cli.rb', line 67

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

#startObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gitdocs/cli.rb', line 19

def start
  unless stopped?
    say 'Gitdocs is already running, please use restart', :red
    return
  end

  if options[:debug]
    say 'Starting in debug mode', :yellow
    Gitdocs.start(debug: true, port: options[:port])
  else
    runner.execute { Gitdocs.start(port: options[:port]) }
    if running?
      say 'Started gitdocs', :green
    else
      say 'Failed to start gitdocs', :red
    end
  end
end

#statusObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/gitdocs/cli.rb', line 89

def status
  say "GitDoc v#{VERSION}"
  say "Running: #{running?}"
  say "File System Watch Method: #{file_system_watch_method}"
  say 'Watched repositories:'
  tp.set(:max_width, 100)
  status_display = lambda do |share|
    repository = Gitdocs::Repository.new(share)

    status = ''
    status += '*' if repository.dirty?
    status += '!' if repository.need_sync?

    status = 'ok' if status.empty?
    status
  end
  tp(
    config.shares,
    { sync: { display_method: :sync_type } },
    { s: status_display },
    :path
  )
  say "\n(Legend: ok everything synced, * change to commit, ! needs sync)"
end

#stopObject



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

def stop
  unless running?
    say 'Gitdocs is not running', :red
    return
  end

  runner.execute(kill: true)
  say 'Stopped gitdocs', :red
end