Class: Gitdocs::Cli
- Inherits:
-
Thor
- Object
- Thor
- Gitdocs::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/gitdocs/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(path) ⇒ Object
- #clear ⇒ Object
- #create(path, remote) ⇒ Object
- #help(task = nil, subcommand = false) ⇒ Object
- #open ⇒ Object
- #restart ⇒ Object
- #rm(path) ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Class Method Details
.source_root ⇒ Object
11 12 13 |
# File 'lib/gitdocs/cli.rb', line 11 def self.source_root File.('../../', __FILE__) end |
Instance Method Details
#add(path) ⇒ Object
67 68 69 70 71 |
# File 'lib/gitdocs/cli.rb', line 67 def add(path) Share.create_by_path!(normalize_path(path)) say "Added path #{path} to doc list" restart if running? end |
#clear ⇒ Object
83 84 85 86 87 |
# File 'lib/gitdocs/cli.rb', line 83 def clear Share.destroy_all say 'Cleared paths from gitdocs' restart if running? end |
#create(path, remote) ⇒ Object
91 92 93 94 95 |
# File 'lib/gitdocs/cli.rb', line 91 def create(path, remote) Repository.clone(path, remote) add(path) say "Created #{path} path for gitdoc" end |
#help(task = nil, subcommand = false) ⇒ Object
141 142 143 144 |
# File 'lib/gitdocs/cli.rb', line 141 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 |
#open ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/gitdocs/cli.rb', line 126 def open unless running? say 'Gitdocs is not running, cannot open the UI', :red return end Launchy.open("http://localhost:#{web_port}/") end |
#restart ⇒ Object
60 61 62 63 |
# File 'lib/gitdocs/cli.rb', line 60 def restart stop start end |
#rm(path) ⇒ Object
75 76 77 78 79 |
# File 'lib/gitdocs/cli.rb', line 75 def rm(path) Share.remove_by_path(path) say "Removed path #{path} from doc list" restart if running? end |
#start ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitdocs/cli.rb', line 20 def start unless stopped? say 'Gitdocs is already running, please use restart', :red return end Gitdocs::Initializer.verbose = [:verbose] if [:foreground] say 'Run in the foreground', :yellow Gitdocs::Initializer.foreground = true Manager.start(web_port) else # Clear the arguments so that they will not be processed by the # Dante execution. ARGV.clear runner.execute { Manager.start(web_port) } if running? say 'Started gitdocs', :green else say 'Failed to start gitdocs', :red end end end |
#status ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/gitdocs/cli.rb', line 99 def status say "GitDoc v#{VERSION}" say "Running: #{running?}" say "File System Watch Method: #{Gitdocs::Manager.listen_method}" say 'Watched repositories:' tp.set(:max_width, 100) status_display = lambda do |share| repository = Repository.new(share) status = '' status += '*' if repository.dirty? status += '!' if repository.need_sync? status = 'ok' if status.empty? status end tp( Share.all, { sync: { display_method: :sync_type } }, { s: status_display }, :path ) say "\n(Legend: ok everything synced, * change to commit, ! needs sync)" end |
#stop ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/gitdocs/cli.rb', line 48 def stop unless running? say 'Gitdocs is not running', :red return end runner.execute(kill: true) say 'Stopped gitdocs', :red end |