diff --git a/Gemfile b/Gemfile index 13147f9..aeff478 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 712007e..170a047 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -35,6 +38,7 @@ PLATFORMS DEPENDENCIES fakefs (~> 0.2.1) + json (~> 1.5.1) parka rake rcov (~> 0.9.8) diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index 19ccf86..2893088 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -36,8 +36,9 @@ class Foreman::CLI < Thor 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 diff --git a/lib/foreman/export.rb b/lib/foreman/export.rb index 1ab1146..ea49dfa 100644 --- a/lib/foreman/export.rb +++ b/lib/foreman/export.rb @@ -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" diff --git a/lib/foreman/export/json.rb b/lib/foreman/export/json.rb new file mode 100644 index 0000000..afaf466 --- /dev/null +++ b/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 diff --git a/man/foreman.1.ronn b/man/foreman.1.ronn index 4fa79cf..52ef54c 100644 --- a/man/foreman.1.ronn +++ b/man/foreman.1.ronn @@ -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: