ginatra 3.0.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -15
  3. data/.travis.yml +7 -6
  4. data/CONTRIBUTING.md +30 -0
  5. data/Gemfile +1 -9
  6. data/LICENSE.txt +30 -0
  7. data/README.md +63 -114
  8. data/Rakefile +10 -12
  9. data/bin/ginatra +79 -63
  10. data/config.ru +35 -3
  11. data/ginatra.gemspec +29 -18
  12. data/lib/ginatra.rb +161 -148
  13. data/lib/ginatra/config.rb +18 -121
  14. data/lib/ginatra/errors.rb +10 -0
  15. data/lib/ginatra/helpers.rb +154 -139
  16. data/lib/ginatra/repo.rb +67 -82
  17. data/lib/ginatra/repo_list.rb +25 -18
  18. data/lib/ginatra/repo_stats.rb +93 -0
  19. data/lib/ginatra/version.rb +4 -0
  20. data/lib/git/webby.rb +292 -0
  21. data/lib/git/webby/extensions.rb +10 -0
  22. data/lib/git/webby/http_backend.rb +177 -0
  23. data/lib/sinatra/partials.rb +1 -1
  24. data/public/css/application.css +6 -0
  25. data/public/css/custom.css +57 -0
  26. data/public/css/lib/bootstrap-responsive.min.css +9 -0
  27. data/public/css/lib/bootstrap.min.css +9 -0
  28. data/public/css/lib/highlight.css +209 -0
  29. data/public/img/glyphicons-halflings-white.png +0 -0
  30. data/public/img/glyphicons-halflings.png +0 -0
  31. data/public/img/spin.gif +0 -0
  32. data/public/js/application.js +5 -0
  33. data/public/js/custom.js +51 -0
  34. data/public/js/lib/bootstrap.min.js +6 -0
  35. data/public/js/lib/jquery.lazyload.min.js +2 -0
  36. data/public/js/lib/jquery.min.js +2 -0
  37. data/public/js/lib/jquery.pjax.js +739 -0
  38. data/repos/README.md +21 -8
  39. data/spec/ginatra/helpers_spec.rb +95 -0
  40. data/spec/ginatra/repo_list_spec.rb +66 -0
  41. data/spec/ginatra/repo_spec.rb +78 -0
  42. data/spec/ginatra/repo_stats_spec.rb +27 -0
  43. data/spec/ginatra_spec.rb +121 -0
  44. data/spec/spec_helper.rb +8 -17
  45. data/views/404.erb +18 -0
  46. data/views/500.erb +18 -0
  47. data/views/_footer.erb +7 -0
  48. data/views/_header.erb +12 -6
  49. data/views/_tree_nav.erb +53 -0
  50. data/views/atom.erb +32 -0
  51. data/views/blob.erb +27 -8
  52. data/views/commit.erb +95 -17
  53. data/views/empty_repo.erb +10 -0
  54. data/views/index.erb +27 -11
  55. data/views/layout.erb +16 -20
  56. data/views/log.erb +74 -54
  57. data/views/stats.erb +89 -0
  58. data/views/tree.erb +32 -20
  59. metadata +168 -94
  60. data/bin/ginatra-daemon +0 -87
  61. data/bin/ginatra-directory +0 -55
  62. data/bin/ginatra-server +0 -27
  63. data/bin/ginatra-setup +0 -28
  64. data/lib/ginatra/graph_commit.rb +0 -77
  65. data/public/img/add.png +0 -0
  66. data/public/img/diff.png +0 -0
  67. data/public/img/doc.png +0 -0
  68. data/public/img/rm.png +0 -0
  69. data/public/img/tree.png +0 -0
  70. data/public/src/branch-graph.js +0 -170
  71. data/public/src/colour.css +0 -86
  72. data/public/src/commit.css +0 -211
  73. data/public/src/ginatra.js +0 -7
  74. data/public/src/github.css +0 -129
  75. data/public/src/graph.css +0 -9
  76. data/public/src/highlight.pack.js +0 -1
  77. data/public/src/index.css +0 -92
  78. data/public/src/lists.css +0 -25
  79. data/public/src/raphael.js +0 -7
  80. data/public/src/reset.css +0 -49
  81. data/public/src/table.css +0 -33
  82. data/public/src/type.css +0 -30
  83. data/rackup.ru +0 -5
  84. data/spec/graph_commit_spec.rb +0 -54
  85. data/spec/repo_list_spec.rb +0 -84
  86. data/spec/repo_spec.rb +0 -61
  87. data/views/_actor_box.erb +0 -13
  88. data/views/_commit_info_box.erb +0 -27
  89. data/views/_tree_part.erb +0 -11
  90. data/views/atom.builder +0 -32
  91. data/views/graph.erb +0 -15
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da7d713fca1a0a2164d09c4af9e0e68446f24e3b
4
+ data.tar.gz: 5dc258e8d928ba24192294dabc70be2b6555a124
5
+ SHA512:
6
+ metadata.gz: 9f724bc83773853892f4250f32858751dbc690ff629c0829c18cbb354affa9047557dfbfece6c1c3d39188cd291621c778540940a7629a9a6d4e55b4b20ca908
7
+ data.tar.gz: b8da76765605a82e326d2c4722644c49614934cda7a555758d3ff5dcf040e921a14a20250667282d7791fb4d0bafa2742bc1eabd8989c824872a35c1f6b1efa5
data/.gitignore CHANGED
@@ -1,16 +1,19 @@
1
- repos/*/
2
- public/*.esproj
3
- tmp/*
4
- .DS_Store
5
- *.log
6
- webrat*
7
- spec/*.html
8
- public/*.html
9
- _site/
10
- _layouts/
11
- **/*.swp
12
- *.swp
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
13
5
  .yardoc
14
- doc/*
15
- pkg/*
16
- Gemfile.lock
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+
18
+ repos/
19
+ config.yml
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
- ---
2
1
  rvm:
3
- - 1.9.2
4
- script: "bundle exec rake spec"
5
- before_script:
6
- - "bundle exec ./bin/ginatra setup"
7
- - "bundle exec rake repo"
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ notifications:
6
+ email:
7
+ on_success: never # default: change
8
+ on_failure: change # default: always
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,30 @@
1
+ # How to contribute
2
+
3
+ In the spirit of open source software, **everyone** is encouraged to help
4
+ improve this project.
5
+
6
+ ## Your Pull Request
7
+
8
+ To make it easy to review and understand your change please keep the following
9
+ things in mind before submitting your pull request:
10
+
11
+ * Work on the latest possible state of **ginatra/master**
12
+ * Create a branch which is dedicated to your change
13
+ * Test your changes before creating a pull request (`bundle exec rake`)
14
+ * If possible write a test case which confirms your change
15
+ * Don't mix several features or bug-fixes in one pull request
16
+ * Create a meaningful commit message
17
+ * Explain your change (i.e. with a link to the issue you are fixing)
18
+ * Keep it simple: don't overcomplicate things and add extra dependencies unless
19
+ you have a *special* reason
20
+
21
+ **IMPORTANT**:
22
+
23
+ Before you start working on a larger contribution, you should get in touch first
24
+ through the issue tracker with your idea so that the project's developers can
25
+ help out and possibly guide you. Coordinating up front makes it much easier to
26
+ avoid frustration later on.
27
+
28
+ # Thank you
29
+
30
+ Each contribution is extremely helpful - thank you!
data/Gemfile CHANGED
@@ -1,11 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- group :development, :test do
6
- gem "rake"
7
- gem "rspec"
8
- gem "webrat"
9
- gem "rack-test"
10
- gem "cucumber"
11
- end
data/LICENSE.txt ADDED
@@ -0,0 +1,30 @@
1
+ Copyright (c) 2009-2012 Samuel Elliott
2
+ Copyright (c) 2012-2015 Nihad Abbasov
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ ---
26
+
27
+ Contains data from external sources:
28
+
29
+ depuracao/git-webby (https://github.com/depuracao/git-webby)
30
+ license: https://github.com/depuracao/git-webby/blob/master/LICENSE.txt
data/README.md CHANGED
@@ -1,149 +1,98 @@
1
1
  # Ginatra
2
- [![](http://stillmaintained.com/lenary/ginatra.png)](http://stillmaintained.com/lenary/ginatra)
3
2
 
4
- [![](http://travis-ci.org/lenary/ginatra.png)](http://travis-ci.org/lenary/ginatra)
3
+ [![Build Status](https://img.shields.io/travis/NARKOZ/ginatra/master.svg?style=flat)](https://travis-ci.org/NARKOZ/ginatra)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/NARKOZ/ginatra.svg?style=flat)](https://codeclimate.com/github/NARKOZ/ginatra)
5
+ [![Gem Version](https://img.shields.io/gem/v/ginatra.svg?style=flat)](https://rubygems.org/gems/ginatra)
6
+ [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/NARKOZ/ginatra/blob/master/LICENSE.txt)
5
7
 
8
+ **Ginatra** is a simple web-based git repository browser built on Ruby Sinatra.
6
9
 
7
- This project is to make a clone of gitweb in Ruby and Sinatra. It serves git
8
- repositories out of a set of specified directories using an array of glob-based
9
- paths. I have plans to make it function just as gitweb does, including leeching
10
- config files and suchlike.
10
+ [ [website](http://narkoz.github.io/ginatra) |
11
+ [screenshots](http://narkoz.github.io/ginatra/screenshots) ]
11
12
 
12
- Installation
13
- ------------
13
+ ## Features
14
14
 
15
- **NEW: You should be using Ruby 1.9.2: because it's awesome!**
15
+ + Hassle free installation
16
+ + Multiple repository support
17
+ + Multiple branch/tag support
18
+ + Commit history, diff, patch
19
+ + Feeds in Atom format
20
+ + Syntax highlighting
21
+ + Repository stats
22
+ + Smart HTTP support
23
+ + [and more](http://narkoz.github.io/ginatra#features)
16
24
 
17
- To install ginatra:
25
+ ## Installation
18
26
 
19
- $ gem install ginatra
20
- ...
21
- $ ginatra setup
22
- checked deps
23
- installed config
27
+ There are 2 ways to install Ginatra: as a packaged Ruby gem or as a Sinatra app.
28
+ It's recommended to install it as a ruby gem, unless you know what you're doing.
24
29
 
25
- If you get those two lines of output, you're sorted. anything else and something
26
- has gone wrong.
30
+ ### Ginatra gem
27
31
 
28
- ### External Dependencies
32
+ Run the following command to install Ginatra from RubyGems:
29
33
 
30
- You should be using Git 1.6.3 or later just to be sure that it all works:
34
+ ```sh
35
+ gem install ginatra -v 4.0.0
36
+ ```
31
37
 
32
- $ git --version
33
- git version 1.6.3
38
+ Create config file (see [Configuration](#configuration) section in README).
34
39
 
35
- The other dependency you need is pygments, an awesome python syntax highlighter.
36
- To check whether you have it, run:
40
+ Start the Ginatra server:
37
41
 
38
- $ which pygmentize
42
+ ```sh
43
+ ginatra run
44
+ ```
39
45
 
40
- If this returns a path pointing to a 'pygmentize' binary, then you're all set.
41
- If not you'll need to install pygments. Look at the last section of the
42
- [jekyll wiki "install" page](http://wiki.github.com/mojombo/jekyll/install)
43
- to see how to install it. Also make sure again that the `pygmentize` binary
44
- is on your path.
46
+ By default Ginatra will run on `localhost:9797`
45
47
 
46
- If you want to play around with the code, you can clone the repository. This also allows you
47
- to use a special rackup file to mount it where you wish. I am yet to sort out some of the
48
- details of running Ginatra from a gem with a rackup.ru file.
48
+ ### Ginatra app
49
49
 
50
- Usage
51
- -----
50
+ Run the following commands to install Ginatra from source:
52
51
 
53
- If you're just using it in development, use the following to start, check and stop Ginatra
54
- respectively:
52
+ ```sh
53
+ git clone git://github.com/NARKOZ/ginatra.git
54
+ cd ginatra/
55
+ bundle
56
+ ```
55
57
 
56
- $ ginatra server start
57
- $ ginatra server status
58
- $ ginatra server stop
58
+ Create config file or modify existing (see [Configuration](#configuration) section in README).
59
59
 
60
- Ginatra also runs on thin, with the approach outlined above.
60
+ Start the Ginatra server:
61
61
 
62
- **BEWARE:** There are issues running Ginatra on Passenger. We discourage Ginatra's use
63
- on Passenger until we can make it stable.
62
+ ```sh
63
+ ./bin/ginatra run
64
+ ```
64
65
 
65
- Ginatra can also start a git-daemon serving all the repositories that ginatra serves:
66
+ By default Ginatra will run on `localhost:9797`
66
67
 
67
- $ ginatra daemon start
68
- $ ginatra daemon status
69
- $ ginatra daemon stop
68
+ ## Configuration
70
69
 
71
- This runs on the default git daemon port.
70
+ Create `~/.ginatra/config.yml` file with your own settings. See
71
+ [`config.yml`](https://github.com/NARKOZ/ginatra/blob/master/config.yml) for a reference.
72
72
 
73
- You can add a glob specified list of git repositories for ginatra to serve using the
74
- following commands:
73
+ `git_dirs` - Ginatra will look into these folders for git repositories. It's
74
+ required to append `*` at the end of path. Example: `/home/Development/repos/*`
75
75
 
76
- $ ginatra directory add '~/Git/ginatra/*'
77
- $ ginatra directory list
78
- $ ginatra directory remove '~/Git/ginatra/*'
76
+ `ignored_files` - files to ignore in `git_dirs`
79
77
 
80
- These should be fairly self explanatory. Help is shown with either the --help option
81
- or by not specifying a sub-command like start, status, stop, add, list or remove.
78
+ `description` - description of web interface. Used in index page.
82
79
 
80
+ `port` - port that Ginatra server will run at.
83
81
 
84
- Attribution
85
- -----------
82
+ `host` - host that Ginatra server will run at.
86
83
 
87
- **Authors:**
84
+ `prefix` - prefix for the host serving Ginatra. Used when Ginatra is installed
85
+ in subdirectory.
88
86
 
89
- - Samuel Elliott (lenary)
90
- - Ryan Bigg (radar)
91
- - Jan Topiński (simcha)
87
+ `git_clone_enabled?` - enables smart HTTP support and allows to clone git
88
+ repopsitories.
92
89
 
93
- **Patches**
90
+ If you installed Ginatra as an app, you can change settings by editing
91
+ `config.yml` file in root folder.
94
92
 
95
- - James Tucker (raggi)
96
- - Elia Schito (elia)
97
- - Scott Wisely (Syd)
98
- - Jonathan Stott (namelessjon)
99
- - Michael James (umjames)
93
+ You need to restart web server after applying changes to config file.
100
94
 
101
- In a new spirit of openness, all those who submit a patch that gets applied will gain commit access to the main (lenary/ginatra) repository.
95
+ ## How to Contribute
102
96
 
103
- Screenshots
104
- -----------
105
-
106
- **Index**
107
-
108
- ![Ginatra Index](http://cloud.github.com/downloads/lenary/ginatra/o%20\(5\).png "Ginatra Index")
109
-
110
- **Log**
111
-
112
- ![Ginatra Log](http://cloud.github.com/downloads/lenary/ginatra/o%20\(3\).png "Ginatra Log")
113
-
114
- **Commit**
115
-
116
- ![Ginatra Commit](http://cloud.github.com/downloads/lenary/ginatra/o%20\(4\).png "Ginatra Commit")
117
-
118
- **Tree**
119
-
120
- ![Ginatra Tree](http://cloud.github.com/downloads/lenary/ginatra/o%20\(2\).png "Ginatra Tree")
121
-
122
- **Branch graph**
123
-
124
- ![Branch graph](http://cloud.github.com/downloads/simcha/ginatra/branch-graph.png "Branch Graph")
125
-
126
-
127
- Licence
128
- -------
129
-
130
- The MIT License
131
-
132
- Copyright (c) 2009 Samuel Elliott
133
-
134
- Permission is hereby granted, free of charge, to any person obtaining a copy of
135
- this software and associated documentation files (the "Software"), to deal in
136
- the Software without restriction, including without limitation the rights to
137
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
138
- the Software, and to permit persons to whom the Software is furnished to do so,
139
- subject to the following conditions:
140
-
141
- The above copyright notice and this permission notice shall be included in all
142
- copies or substantial portions of the Software.
143
-
144
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
145
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
146
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
147
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
148
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
149
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
97
+ Open issues are labeled per perceived difficulty. See [contributing
98
+ guidelines](https://github.com/NARKOZ/ginatra/blob/master/CONTRIBUTING.md).
data/Rakefile CHANGED
@@ -1,19 +1,17 @@
1
- require "bundler"
2
- Bundler.setup(:default, :development)
1
+ require 'bundler/gem_tasks'
3
2
  require 'rspec/core/rake_task'
4
3
 
5
- task :default => ['rake:spec']
6
-
7
- desc "Clones the Test Repository"
8
- task :repo do |t|
9
- FileUtils.cd(File.join(File.dirname(__FILE__), "repos")) do
4
+ desc "Clone test repository"
5
+ task :clone_repo do
6
+ repos_dir = File.expand_path('./repos')
7
+ FileUtils.cd(repos_dir) do
10
8
  puts `git clone git://github.com/atmos/hancock-client.git test`
11
- end
9
+ end unless Dir.exists?("#{repos_dir}/test")
12
10
  end
13
11
 
14
- desc "Runs the RSpec Test Suite"
15
- RSpec::Core::RakeTask.new(:spec) do |r|
16
- r.pattern = 'spec/*_spec.rb'
17
- r.rspec_opts = ['--color']
12
+ RSpec::Core::RakeTask.new(:spec) do |spec|
13
+ spec.pattern = FileList['spec/**/*_spec.rb']
14
+ spec.rspec_opts = ['--color']
18
15
  end
19
16
 
17
+ task default: ['clone_repo', 'spec']
data/bin/ginatra CHANGED
@@ -1,78 +1,94 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- module Ginatra
4
- module Executable
5
- HELP = <<-HELP
6
- Usage: ginatra [ setup |
7
- version |
8
- server <options> <command> |
9
- daemon <command> |
10
- directory <command> <globs> ]
11
-
12
- Ginatra Commands:
13
- setup - Checks Dependencies and Installs Configuration
14
- version - Pretty Self explanatory. Print version number and exit
15
-
16
- Ginatra Server Commands:
17
- start - Start the Ginatra HTTP Server.
18
- stop - Stop the Ginatra Server.
19
- status - How's your Ginatra Server holding up?
20
-
21
- Ginatra Daemon Commands:
22
- start - Starts the Git Daemon servimg Ginatra's Repositories
23
- stop - Stops the Git Daemon
24
- restart - Restarts the Git Daemon
25
- status - Is the Git Daemon on or off?
26
-
27
-
28
- Ginatra Directory Commands:
29
- add - Adds the <globs> to the array of dirs that Ginatra
30
- looks in for repositories.
31
- remove - Removes the <globs> from the aforementioned array.
32
- list - Lists the globs Ginatra looks in for repositories
33
-
34
- HELP
35
-
36
- def self.daemon
37
- path = File.expand_path(File.dirname(__FILE__))
38
- load "#{path}/ginatra-daemon"
39
- end
3
+ $:.unshift File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'ginatra'
6
+ require 'optparse'
7
+
8
+ options = {
9
+ port: Ginatra.config.port,
10
+ host: Ginatra.config.host
11
+ }
12
+
13
+ global_opts = OptionParser.new do |opts|
14
+ opts.banner = "Usage: ginatra <options> <command>"
15
+
16
+ opts.separator ""
17
+ opts.separator "Options:"
18
+
19
+ opts.on('-v', '--version', 'Print version and exit') do
20
+ require_relative '../lib/ginatra/version'
21
+ puts "Ginatra #{Ginatra::VERSION} #{Ginatra::RELEASE_NAME}"
22
+ exit
23
+ end
24
+
25
+ opts.on_tail('-h', '--help', 'Show this help message') do
26
+ puts opts
27
+ exit
28
+ end
29
+ end
30
+
31
+ server_opts = {
32
+ 'run' => OptionParser.new do |opts|
33
+ opts.banner = "Usage: ginatra run <options>"
40
34
 
41
- def self.directory
42
- path = File.expand_path(File.dirname(__FILE__))
43
- load "#{path}/ginatra-directory"
35
+ opts.separator ""
36
+ opts.separator "Options:"
37
+
38
+ opts.on('-p', '--port PORT', 'Port to bind to (defaults from config file)') do |port|
39
+ options[:port] = port.to_i
44
40
  end
45
41
 
46
- def self.server
47
- path = File.expand_path(File.dirname(__FILE__))
48
- load("#{path}/ginatra-server")
42
+ opts.on('-h', '--host HOST', 'Host address to bind to (defaults from config file)') do |host|
43
+ options[:host] = host
49
44
  end
50
45
 
51
- def self.setup
52
- path = File.expand_path(File.dirname(__FILE__))
53
- load("#{path}/ginatra-setup")
46
+ opts.on 'Start Ginatra web server' do
47
+ environment = ENV['RACK_ENV'] || 'production'
48
+ rack_config = File.expand_path("#{__FILE__}/../../config.ru")
49
+ pid_file = File.expand_path("#{__FILE__}/../../ginatra.pid")
50
+
51
+ system "rackup -D -E #{environment} -P #{pid_file} -p #{options[:port]} -o #{options[:host]} #{rack_config}"
52
+ puts "Ginatra runs on #{options[:host]}:#{options[:port]}"
54
53
  end
54
+ end,
55
+
56
+ 'stop' => OptionParser.new do |opts|
57
+ opts.banner = "Usage: ginatra stop"
55
58
 
56
- def self.execute(command, args)
57
- case command
58
- when "version"
59
- require "ginatra"
60
- puts Ginatra::VERSION
61
- when "setup"
62
- setup
63
- when "daemon"
64
- daemon
65
- when "directory"
66
- directory
67
- when "server"
68
- server
69
- else
70
- puts Ginatra::Executable::HELP
59
+ opts.on 'Stop Ginatra web server' do
60
+ pid_file = File.expand_path("#{__FILE__}/../../ginatra.pid")
61
+
62
+ if File.exist?(pid_file)
63
+ pid = File.read(pid_file)
64
+ Process.kill('INT', pid.to_i)
65
+ File.delete(pid_file)
66
+ puts "Stopped Ginatra web server"
71
67
  end
72
68
  end
69
+ end,
70
+
71
+ 'status' => OptionParser.new do |opts|
72
+ opts.banner = "Usage: ginatra status"
73
+
74
+ opts.on 'Get status of Ginatra web server' do
75
+ pid_file = File.expand_path("#{__FILE__}/../../ginatra.pid")
76
+ status = File.exist?(pid_file) ? "running.. (pid: #{File.read(pid_file).to_i})" : 'NOT running'
77
+ puts "Ginatra is #{status}"
78
+ end
73
79
  end
74
- end
80
+ }
75
81
 
76
- Ginatra::Executable.execute ARGV.shift, ARGV
82
+ if ARGV.size.zero?
83
+ puts global_opts
77
84
 
85
+ %w(run stop status).each do |cmd|
86
+ puts
87
+ puts server_opts[cmd]
88
+ end
89
+
90
+ exit 1
91
+ end
78
92
 
93
+ global_opts.order!
94
+ server_opts[ARGV.shift].order!