napa 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/README.md +11 -12
  4. data/Rakefile +4 -0
  5. data/docs/quickstart.md +2 -2
  6. data/lib/napa/authentication.rb +5 -2
  7. data/lib/napa/cli/base/console.rb +32 -0
  8. data/lib/napa/cli/base/deploy.rb +22 -0
  9. data/lib/napa/cli/base/new.rb +49 -0
  10. data/lib/napa/cli/base/server.rb +29 -0
  11. data/lib/napa/cli/base/version.rb +14 -0
  12. data/lib/napa/cli/base.rb +17 -0
  13. data/lib/napa/cli/generate/api.rb +42 -0
  14. data/lib/napa/cli/generate/readme.rb +50 -0
  15. data/lib/napa/cli/generate.rb +18 -0
  16. data/lib/napa/{generators/migration_generator.rb → cli/migration.rb} +3 -3
  17. data/lib/napa/{generators → cli}/templates/api/app/apis/%name_tableize%_api.rb.tt +0 -0
  18. data/lib/napa/{generators → cli}/templates/api/app/models/%name_underscore%.rb.tt +0 -0
  19. data/lib/napa/{generators → cli}/templates/api/app/representers/%name_underscore%_representer.rb.tt +0 -0
  20. data/lib/napa/{generators → cli}/templates/api/spec/apis/%name_tableize%_api_spec.rb.tt +0 -0
  21. data/lib/napa/{generators → cli}/templates/api/spec/models/%name_underscore%_spec.rb.tt +0 -0
  22. data/lib/napa/{generators → cli}/templates/create_table_migration/%migration_filename%.rb.tt +0 -0
  23. data/lib/napa/{generators → cli}/templates/migration/%migration_filename%.rb.tt +0 -0
  24. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/.env.test.tt +1 -1
  25. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/.env.tt +1 -1
  26. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/.gitignore.tt +0 -0
  27. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/.rubocop.yml +0 -0
  28. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/.ruby-gemset.tt +0 -0
  29. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/.ruby-version.tt +0 -0
  30. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/Gemfile.tt +2 -2
  31. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/README.md +0 -0
  32. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/Rakefile +0 -0
  33. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/app/apis/application_api.rb +0 -0
  34. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/app/apis/hello_api.rb.tt +0 -0
  35. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/app.rb +0 -0
  36. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/config/database.yml.tt +0 -0
  37. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/config/initializers/active_record.rb +0 -0
  38. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/config/middleware/honeybadger.rb +0 -0
  39. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/config.ru.tt +1 -2
  40. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/db/schema.rb +0 -0
  41. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/lib/.keep +0 -0
  42. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/log/.keep +0 -0
  43. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/spec/apis/hello_api_spec.rb.tt +0 -0
  44. data/lib/napa/{generators/templates/readme → cli/templates/new}/spec/docs/readme_spec.rb +0 -0
  45. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/spec/factories/.gitkeep +0 -0
  46. data/lib/napa/{generators/templates/scaffold → cli/templates/new}/spec/spec_helper.rb +0 -0
  47. data/lib/napa/{generators → cli}/templates/readme/README.md.tt +0 -0
  48. data/lib/napa/cli/templates/readme/spec/docs/readme_spec.rb +7 -0
  49. data/lib/napa/cli.rb +3 -89
  50. data/lib/napa/middleware/authentication.rb +16 -4
  51. data/lib/napa/param_sanitizer.rb +1 -1
  52. data/lib/napa/version.rb +1 -1
  53. data/spec/{generators/scaffold_generator_spec.rb → cli/base/new_spec.rb} +4 -3
  54. data/spec/{generators/api_generator_spec.rb → cli/generate/api_spec.rb} +5 -4
  55. data/spec/{generators/readme_generator_spec.rb → cli/generate/readme_spec.rb} +5 -4
  56. data/spec/{generators/migration_generator_spec.rb → cli/migration_spec.rb} +9 -9
  57. data/spec/middleware/authentication_spec.rb +95 -34
  58. data/spec/spec_helper.rb +14 -23
  59. data/tasks/spec.rake +9 -0
  60. metadata +54 -48
  61. data/lib/napa/generators/api_generator.rb +0 -30
  62. data/lib/napa/generators/readme_generator.rb +0 -47
  63. data/lib/napa/generators/scaffold_generator.rb +0 -29
  64. data/lib/napa/generators.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99dd7c64867542bf20e480334250d1e47c271df0
4
- data.tar.gz: 870471e9345f770dea420b9f0edf609dbf16cd25
3
+ metadata.gz: 411eb368134bee542c4fb51fa4a180c5b1a65ccc
4
+ data.tar.gz: d2ca60df98d4c3f260e5c0df9864087bbda48dcd
5
5
  SHA512:
6
- metadata.gz: ad6d3c13701b0536aaf9269e424b33ab91fb7e0cbd89b0d7e7e9b1cc8a080282fcd9a869e7161a6ebebe1f5839fe052c3087b34a9ca49444e42e832811380cc1
7
- data.tar.gz: f46a872779294f28648f2f041850d46535146b763def899ac6dfebaaa9332984d654c67fae599b6ab978a0da6ebe279b057943cb900d7ef6815a75a21c1fa2fa
6
+ metadata.gz: c950462ba0a5d7c8e8c249a4d23243e1d91e742ead2aef1ca760af45b2bf8412340e1474f433a5fa1c0280c9ac18bb74cef37ed471ec4c82a54abc49b5eb31d9
7
+ data.tar.gz: 56aa083725ab045cfcafd55ff579e0ad617fdadbd90aa5df16eee7db7efc1929b26ff30040cfaf50b708e5603d31d9ef74707bee01ad92bcbacf8b40341fd0d1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  master
2
2
  ===
3
+
4
+ 0.4.3
5
+ ===
6
+ * [Allow Napa::Authentication to receive multiple and accept multiple passwords](https://github.com/bellycard/napa/pull/190)
7
+ * [rename to silence_thor](https://github.com/bellycard/napa/pull/189)
8
+ * [Hey! Spec suite! Leave them streams alone!](https://github.com/bellycard/napa/pull/175)
9
+ * [Refactoring CLI](https://github.com/bellycard/napa/pull/186)
10
+
11
+ 0.4.2
12
+ ===
13
+ * [Explicitly require `filter_parameters.rb` instead of relying on `action_dispatch` autoload](https://github.com/bellycard/napa/pull/181)
14
+ * [Default rake task runs specs](https://github.com/bellycard/napa/pull/176)
15
+ * [Set Napa.env to the environment arg we pass in the console](https://github.com/bellycard/napa/pull/179)
16
+ * [Add thor command to start shotgun server](https://github.com/bellycard/napa/pull/177)
17
+ * [Lock honeybadger and roar in the meantime](https://github.com/bellycard/napa/pull/185)
18
+
19
+ 0.4.1
20
+ ===
3
21
  * Added a reasons object to error responses to represent active record validation errors for individual attributes
4
22
  * Added ability to filter sensitive data from logs.
5
23
 
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
+ ![napa-v2-01-cropped-resized](https://cloud.githubusercontent.com/assets/36847/6060268/d8cd3e00-ad00-11e4-96b9-64affc2cc802.png)
2
+
1
3
  [![Build Status](https://travis-ci.org/bellycard/napa.png?branch=master)](https://travis-ci.org/bellycard/napa)
2
4
  [![Dependency Status](https://gemnasium.com/bellycard/napa.png)](https://gemnasium.com/bellycard/napa)
3
5
  [![Code Climate](https://codeclimate.com/github/bellycard/napa/badges/gpa.svg)](https://codeclimate.com/github/bellycard/napa)
4
6
  [![Test Coverage](https://codeclimate.com/github/bellycard/napa/badges/coverage.svg)](https://codeclimate.com/github/bellycard/napa)
5
7
 
6
- # Napa
7
-
8
8
  Napa is a simple framework for building Rack based APIs using Grape, Roar and ActiveRecord. It's designed to make it easy to quickly create and deploy new API services by providing **generators**, **middlewares** and a **console** similar to what you would expect from a Rails app.
9
9
 
10
10
  ## Installation
@@ -37,14 +37,13 @@ Run `napa` terminal prompt to see available features:
37
37
 
38
38
  ```
39
39
  Commands:
40
- napa console [environment] # Start the Napa console
41
- napa generate api <api_name> # Create a Grape API, Model and Representer
42
- napa generate migration <migration_name> [field[:type][:index] field[:type][:index]] # Create a Database Migration
43
- napa generate readme # Create a formatted README
44
- napa deploy <environment> # Deploy to <environment> by setting a git tag
45
- napa help [COMMAND] # Describe available commands or one specific command
46
- napa new <app_name> [app_path] # Create a scaffold for a new Napa service
47
- napa version # Shows the Napa version number
40
+ napa console [ENVIRONMENT] # Start the Napa console
41
+ napa deploy [TARGET] # Deploys A Service to a given target (i.e. production, staging, etc.)
42
+ napa generate [COMMAND] # Generate new code
43
+ napa help [COMMAND] # Describe available commands or one specific command
44
+ napa new <NAME> [PATH] # Create a new Napa application
45
+ napa server # Start the Napa server
46
+ napa version # Shows the Napa version number
48
47
  ```
49
48
 
50
49
 
@@ -91,9 +90,9 @@ rake routes # display all routes for Grape
91
90
  Napa includes a number of Rack middlewares that can be enabled to add functionality to your project.
92
91
 
93
92
  ### Authentication
94
- The Authentication middleware will add a simple header based authentication layer to all requests. This is just looking for a header of `'Password' = 'Your Password'`. The passwords are defined in the `.env` file. You can allow multiple passwords by supplying a comma separated list. For example:
93
+ The Authentication middleware will add a simple header based authentication layer to all requests. This is just looking for a header of `'Passwords' = 'Your Password'`. The passwords are defined in the `.env` file. You can allow multiple passwords by supplying a comma separated list. For example:
95
94
 
96
- `HEADER_PASSWORDS='password1,password2'`
95
+ `ALLOWED_HEADER_PASSWORDS='password1,password2'`
97
96
 
98
97
  If your application doesn't require authentication, you can simply remove the middleware.
99
98
 
data/Rakefile CHANGED
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env rake
2
+ $LOAD_PATH.unshift 'lib', __dir__
3
+
2
4
  Dir.glob('./tasks/*.rake').each { |r| import r }
3
5
  require 'bundler/gem_tasks'
4
6
  require 'napa/active_record_extensions/stats.rb'
5
7
  require 'napa/active_record_extensions/seeder.rb'
8
+
9
+ task default: :spec
data/docs/quickstart.md CHANGED
@@ -187,10 +187,10 @@ Now that the code is in place, let's start up the app and send it some requests.
187
187
 
188
188
  Napa runs on Rack, so any rack based webserver will work. Shotgun is nice to use in development because it will reload your app on each request and you don't need to restart the server when there are changes.
189
189
 
190
- Start the server on port 9393 by running:
190
+ Start the shotgun server on port 9393 by running:
191
191
 
192
192
  ```
193
- shotgun
193
+ napa server
194
194
  ```
195
195
 
196
196
  ### POST /people
@@ -1,8 +1,11 @@
1
1
  module Napa
2
2
  class Authentication
3
3
  def self.password_header
4
- raise 'header_password_not_configured' unless ENV['HEADER_PASSWORD']
5
- { 'Password' => ENV['HEADER_PASSWORD'] }
4
+ password_hash = {}
5
+ password_hash['Password'] = ENV['HEADER_PASSWORD'] if ENV['HEADER_PASSWORD']
6
+ password_hash['Passwords'] = ENV['SENT_HEADER_PASSWORDS'] if ENV['SENT_HEADER_PASSWORDS']
7
+ raise 'header_password_not_configured' if password_hash.keys.blank?
8
+ password_hash
6
9
  end
7
10
  end
8
11
  end
@@ -0,0 +1,32 @@
1
+ module Napa
2
+ module CLI
3
+ class Base < Thor
4
+
5
+ desc 'console [ENVIRONMENT]', 'Start the Napa console'
6
+ options aliases: 'c'
7
+ def console(environment = nil)
8
+ Napa.env = environment || 'development'
9
+
10
+ require 'racksh/init'
11
+
12
+ begin
13
+ require "pry"
14
+ interpreter = Pry
15
+ rescue LoadError
16
+ require "irb"
17
+ require "irb/completion"
18
+ interpreter = IRB
19
+ # IRB uses ARGV and does not expect these arguments.
20
+ ARGV.delete('console')
21
+ ARGV.delete(environment) if environment
22
+ end
23
+
24
+ Rack::Shell.init
25
+
26
+ $0 = "#{$0} console"
27
+ interpreter.start
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ require 'napa/deploy'
2
+
3
+ module Napa
4
+ module CLI
5
+ class Base < Thor
6
+
7
+ desc 'deploy [TARGET]', 'Deploys A Service to a given target (i.e. production, staging, etc.)'
8
+ method_options :force => :boolean, :revision => :string, :confirm => :boolean
9
+ def deploy(environment)
10
+ if options[:confirm] || yes?('Are you sure you want to deploy this service?', Thor::Shell::Color::YELLOW)
11
+ deploy = Napa::Deploy.new(environment, force: options[:force], revision: options[:revision])
12
+ if deploy.deployable?
13
+ say(deploy.deploy!, Thor::Shell::Color::GREEN)
14
+ else
15
+ say("Deploy Failed:\n#{deploy.errors.join("\n")}", Thor::Shell::Color::RED)
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ require 'thor'
2
+ require 'active_support/core_ext/string'
3
+
4
+ module Napa
5
+ module CLI
6
+ class Base < Thor
7
+
8
+ include Thor::Actions
9
+
10
+ source_root File.expand_path("../../templates/new", __FILE__)
11
+
12
+ option :database, default: 'mysql', aliases: '-d', desc: 'Preconfigure for selected database (options: mysql/postgres/pg)'
13
+
14
+ desc "new <NAME> [PATH]", "Create a new Napa application"
15
+ def new(name, path = nil)
16
+ say 'Generating scaffold...'
17
+
18
+ @name = name
19
+ @path = path
20
+
21
+ @database_gem = postgres? ? 'pg' : 'mysql2'
22
+ @database_adapter = postgres? ? 'postgresql' : 'mysql2'
23
+ @database_encoding = postgres? ? 'unicode' : 'utf8'
24
+ @database_user = postgres? ? '' : 'root'
25
+
26
+ directory ".", (path || name)
27
+
28
+ say 'Done!', :green
29
+ end
30
+
31
+ no_commands do
32
+
33
+ def app_name
34
+ @name
35
+ end
36
+
37
+ def app_path
38
+ @path
39
+ end
40
+
41
+ def postgres?
42
+ %w[pg postgres].include?(options[:database])
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ module Napa
2
+ module CLI
3
+ class Base < Thor
4
+
5
+ desc 'server', "Start the Napa server"
6
+ options aliases: 's'
7
+ def server
8
+ puts "Napa server starting..."
9
+
10
+ require 'pty'
11
+ exit = "... Napa server exited!"
12
+
13
+ begin
14
+ PTY.spawn('shotgun') do |stdout, stdin, pid|
15
+ begin
16
+ Signal.trap('INT') { Process.kill('INT', pid) }
17
+ stdout.each { |line| puts line }
18
+ rescue Errno::EIO
19
+ puts exit
20
+ end
21
+ end
22
+ rescue PTY::ChildExited
23
+ puts exit
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ require "napa/version"
2
+
3
+ module Napa
4
+ module CLI
5
+ class Base < Thor
6
+
7
+ desc "version", "Shows the Napa version number"
8
+ def version
9
+ say Napa::VERSION
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require "napa/cli/base/console"
2
+ require "napa/cli/base/deploy"
3
+ require "napa/cli/base/new"
4
+ require "napa/cli/base/server"
5
+ require "napa/cli/base/version"
6
+ require "napa/cli/generate"
7
+
8
+ module Napa
9
+ module CLI
10
+ class Base < Thor
11
+
12
+ desc "generate [COMMAND]", "Generate new code"
13
+ subcommand "generate", Napa::CLI::Generate
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ require 'thor'
2
+ require 'active_support/all'
3
+
4
+ module Napa
5
+ module CLI
6
+ class Generate < Thor
7
+
8
+ include Thor::Actions
9
+
10
+ desc "api <NAME>", "Create a Grape API, Model and Entity"
11
+ def api(name)
12
+ @name = name
13
+
14
+ self.class.source_root File.expand_path("../../templates/api", __FILE__)
15
+ say 'Generating api...'
16
+ directory '.', output_directory
17
+ say 'Done!', :green
18
+ end
19
+
20
+ no_commands do
21
+
22
+ def name
23
+ @name
24
+ end
25
+
26
+ def name_underscore
27
+ name.underscore
28
+ end
29
+
30
+ def name_tableize
31
+ name.tableize
32
+ end
33
+
34
+ def output_directory
35
+ '.'
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ require 'thor'
2
+ require 'active_support/all'
3
+ require 'napa/setup'
4
+ require 'napa/identity'
5
+ require 'dotenv'
6
+
7
+ module Napa
8
+ module CLI
9
+ class Generate < Thor
10
+
11
+ include Thor::Actions
12
+
13
+ desc "readme", "Create a formatted README"
14
+ def readme
15
+ self.class.source_root File.expand_path("../../templates/readme", __FILE__)
16
+ say 'Generating README...'
17
+ directory '.', output_directory
18
+ say 'Done!', :green
19
+ end
20
+
21
+ no_commands do
22
+
23
+ def service_name
24
+ Napa::Identity.name
25
+ end
26
+
27
+ def output_directory
28
+ '.'
29
+ end
30
+
31
+ def routes
32
+ routes = ""
33
+
34
+ if defined? ApplicationApi
35
+ ApplicationApi.routes.each do |api|
36
+ method = api.route_method.ljust(10)
37
+ path = api.route_path.ljust(40)
38
+ description = api.route_description
39
+ routes += " #{method} #{path} # #{description}"
40
+ end
41
+ end
42
+
43
+ routes
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ require "napa/cli/generate/api"
2
+ require "napa/cli/generate/readme"
3
+ require "napa/cli/migration"
4
+
5
+ module Napa
6
+ module CLI
7
+ class Generate < Thor
8
+
9
+ register(
10
+ Migration,
11
+ 'migration',
12
+ 'migration <NAME> [field[:type][:index] field[:type][:index]]',
13
+ 'Create a Database Migration'
14
+ )
15
+
16
+ end
17
+ end
18
+ end
@@ -2,8 +2,8 @@ require 'thor'
2
2
  require 'active_support/all'
3
3
 
4
4
  module Napa
5
- module Generators
6
- class MigrationGenerator < Thor::Group
5
+ module CLI
6
+ class Migration < Thor::Group
7
7
  include Thor::Actions
8
8
  # largely ported over, with a few differences, from
9
9
  # https://github.com/rails/rails/blob/76883f92374c6395f13c16628e1d87d40b6d2399/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb
@@ -212,7 +212,7 @@ module Napa
212
212
  end
213
213
 
214
214
  def password_digest?
215
- name == 'password' && type == :digest
215
+ name == 'password' && type == :digest
216
216
  end
217
217
 
218
218
  def inject_options
@@ -1,5 +1,5 @@
1
1
  # Uncomment when using Napa::Middleware::Authentication
2
- # HEADER_PASSWORD=''
2
+ # ALLOWED_HEADER_PASSWORDS=''
3
3
 
4
4
  SERVICE_NAME=<%= app_name %>
5
5
  RACK_ENV=test
@@ -1,5 +1,5 @@
1
1
  # Uncomment when using Napa::Middleware::Authentication
2
- # HEADER_PASSWORD=''
2
+ # ALLOWED_HEADER_PASSWORDS=''
3
3
 
4
4
  SERVICE_NAME=<%= app_name %>
5
5
 
@@ -4,10 +4,10 @@ ruby "2.0.0"
4
4
  gem 'rack-cors'
5
5
  gem '<%= @database_gem %>'
6
6
  gem 'activerecord', '~> 4.0.0', :require => 'active_record'
7
- gem 'honeybadger'
7
+ gem 'honeybadger', '~> 1.16.7'
8
8
  gem 'json'
9
9
  gem 'napa'
10
- gem 'roar'
10
+ gem 'roar', '~> 0.12.0'
11
11
  gem 'grape-swagger'
12
12
 
13
13
  group :development,:test do
@@ -14,9 +14,8 @@ require './app'
14
14
  # use Napa::Middleware::Logger
15
15
 
16
16
  use Napa::Middleware::AppMonitor
17
- # Uncomment to require header passwords for all requestss
17
+ # Uncomment to require header passwords for all requests
18
18
  # use Napa::Middleware::Authentication
19
19
  use ActiveRecord::ConnectionAdapters::ConnectionManagement
20
20
 
21
21
  run ApplicationApi
22
-
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'README' do
4
+ it 'has been filled out' do
5
+ pending 'Please fill out the sections that have a :bow:'
6
+ end
7
+ end
data/lib/napa/cli.rb CHANGED
@@ -1,96 +1,10 @@
1
1
  require 'thor'
2
- require 'napa/generators'
3
- require 'napa/deploy'
4
- require 'napa/version'
2
+ require "napa/cli/base"
3
+ require 'napa/cli/generate'
5
4
 
6
5
  Napa.load_environment if defined?(Dotenv)
7
6
 
8
7
  module Napa
9
- class CLI
10
- class Generate < Thor
11
- register(
12
- Generators::ApiGenerator,
13
- 'api',
14
- 'api <api_name>',
15
- 'Create a Grape API, Model and Entity'
16
- )
17
-
18
- register(
19
- Generators::MigrationGenerator,
20
- 'migration',
21
- 'migration <migration_name> [field[:type][:index] field[:type][:index]]',
22
- 'Create a Database Migration'
23
- )
24
-
25
- register(
26
- Generators::ReadmeGenerator,
27
- 'readme',
28
- 'readme',
29
- 'Create a formatted README'
30
- )
31
- end
32
- end
33
-
34
- class CLI
35
- class Base < Thor
36
- desc "version", "Shows the Napa version number"
37
- def version
38
- say Napa::VERSION
39
- end
40
-
41
- desc 'console [environment]', 'Start the Napa console'
42
- options aliases: 'c'
43
- def console(environment = nil)
44
- ENV['RACK_ENV'] = environment || 'development'
45
-
46
- require 'racksh/init'
47
-
48
- begin
49
- require "pry"
50
- interpreter = Pry
51
- rescue LoadError
52
- require "irb"
53
- require "irb/completion"
54
- interpreter = IRB
55
- # IRB uses ARGV and does not expect these arguments.
56
- ARGV.delete('console')
57
- ARGV.delete(environment) if environment
58
- end
59
-
60
- Rack::Shell.init
61
-
62
- $0 = "#{$0} console"
63
- interpreter.start
64
- end
65
-
66
- desc 'deploy [target]', 'Deploys A Service to a given target (i.e. production, staging, etc.)'
67
- method_options :force => :boolean, :revision => :string, :confirm => :boolean
68
- def deploy(environment)
69
- if options[:confirm] || yes?('Are you sure you want to deploy this service?', Thor::Shell::Color::YELLOW)
70
- deploy = Napa::Deploy.new(environment, force: options[:force], revision: options[:revision])
71
- if deploy.deployable?
72
- say(deploy.deploy!, Thor::Shell::Color::GREEN)
73
- else
74
- say("Deploy Failed:\n#{deploy.errors.join("\n")}", Thor::Shell::Color::RED)
75
- end
76
- end
77
- end
78
-
79
- register(
80
- Generators::ScaffoldGenerator,
81
- 'new',
82
- 'new <app_name> [app_path]',
83
- 'Create a scaffold for a new Napa service'
84
- )
85
-
86
- desc "generate api <api_name>", "Create a Grape API, Model and Representer"
87
- subcommand "generate api", Napa::CLI::Generate
88
-
89
- desc "generate migration <migration_name> [field[:type][:index] field[:type][:index]]", "Create a Database Migration"
90
- subcommand "generate", Napa::CLI::Generate
91
-
92
- desc "generate readme", "Create a formatted README"
93
- subcommand "generate readme", Napa::CLI::Generate
94
- end
8
+ module CLI
95
9
  end
96
10
  end