Skip to content

Commit

Permalink
add json export
Browse files Browse the repository at this point in the history
  • Loading branch information
ddollar committed Jan 28, 2011
1 parent 2804316 commit 977c80f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -13,5 +13,6 @@ group :test do
gem 'rspec', '~> 2.0.0'
end

gem 'json', '~> 1.5.1'
gem 'term-ansicolor', '~> 1.0.5'
gem 'thor', '~> 0.13.6'
18 changes: 11 additions & 7 deletions Gemfile.lock
Expand Up @@ -4,6 +4,7 @@ GEM
diff-lcs (1.1.2)
fakefs (0.2.1)
hpricot (0.8.2)
json (1.5.1)
mime-types (1.16)
mustache (0.11.2)
parka (0.3.1)
Expand All @@ -19,14 +20,16 @@ GEM
mustache (>= 0.7.0)
rdiscount (>= 1.5.8)
rr (1.0.2)
rspec (2.0.0.beta.19)
rspec-core (= 2.0.0.beta.19)
rspec-expectations (= 2.0.0.beta.19)
rspec-mocks (= 2.0.0.beta.19)
rspec-core (2.0.0.beta.19)
rspec-expectations (2.0.0.beta.19)
rspec (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
rspec-mocks (~> 2.0.1)
rspec-core (2.0.1)
rspec-expectations (2.0.1)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.19)
rspec-mocks (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
term-ansicolor (1.0.5)
thor (0.13.8)

Expand All @@ -35,6 +38,7 @@ PLATFORMS

DEPENDENCIES
fakefs (~> 0.2.1)
json (~> 1.5.1)
parka
rake
rcov (~> 0.9.8)
Expand Down
3 changes: 2 additions & 1 deletion lib/foreman/cli.rb
Expand Up @@ -36,8 +36,9 @@ def export(format, location=nil)
check_procfile!

formatter = case format
when "upstart" then Foreman::Export::Upstart
when "json" then Foreman::Export::JSON
when "inittab" then Foreman::Export::Inittab
when "upstart" then Foreman::Export::Upstart
else error "Unknown export format: #{format}."
end

Expand Down
3 changes: 2 additions & 1 deletion lib/foreman/export.rb
Expand Up @@ -4,5 +4,6 @@ module Foreman::Export
class Exception < ::Exception; end
end

require "foreman/export/upstart"
require "foreman/export/json"
require "foreman/export/inittab"
require "foreman/export/upstart"
13 changes: 13 additions & 0 deletions lib/foreman/export/json.rb
@@ -0,0 +1,13 @@
require "foreman/export/base"
require "json"

class Foreman::Export::JSON < Foreman::Export::Base

def export(fname=nil, options={})
processes = engine.processes.values.inject({}) do |hash, process|
hash.update(process.name => { "command" => process.command })
end
puts processes.to_json
end

end
8 changes: 8 additions & 0 deletions man/foreman.1.ronn
Expand Up @@ -75,10 +75,18 @@ These options control all modes of foreman's operation.

foreman currently supports the following output formats:

* json

* inittab

* upstart

## JSON EXPORT

Will export your processes as JSON:

{ "web": { "command": "bundle exec thin start" } }

## INITTAB EXPORT

Will export a chunk of inittab-compatible configuration:
Expand Down

0 comments on commit 977c80f

Please sign in to comment.