lib/napa/cli.rb in napa-0.3.0 vs lib/napa/cli.rb in napa-0.4.0

- old
+ new

@@ -1,9 +1,12 @@ require 'thor' require 'napa/generators' +require 'napa/deploy' require 'napa/version' +Napa.load_environment if defined?(Dotenv) + module Napa class CLI class Generate < Thor register( Generators::ApiGenerator, @@ -13,13 +16,20 @@ ) register( Generators::MigrationGenerator, 'migration', - 'migration <migration_name>', + 'migration <migration_name> [field[:type][:index] field[:type][:index]]', 'Create a Database Migration' ) + + register( + Generators::ReadmeGenerator, + 'readme', + 'readme', + 'Create a formatted README' + ) end end class CLI class Base < Thor @@ -51,20 +61,36 @@ $0 = "#{$0} console" interpreter.start end + desc 'deploy [target]', 'Deploys A Service to a given target (i.e. production, staging, etc.)' + method_options :force => :boolean, :revision => :string, :confirm => :boolean + def deploy(environment) + if options[:confirm] || yes?('Are you sure you want to deploy this service?', Thor::Shell::Color::YELLOW) + deploy = Napa::Deploy.new(environment, force: options[:force], revision: options[:revision]) + if deploy.deployable? + say(deploy.deploy!, Thor::Shell::Color::GREEN) + else + say("Deploy Failed:\n#{deploy.errors.join("\n")}", Thor::Shell::Color::RED) + end + end + end + register( Generators::ScaffoldGenerator, 'new', 'new <app_name> [app_path]', 'Create a scaffold for a new Napa service' ) desc "generate api <api_name>", "Create a Grape API, Model and Representer" subcommand "generate api", Napa::CLI::Generate - desc "generate migration <migration_name>", "Create a Database Migration" + desc "generate migration <migration_name> [field[:type][:index] field[:type][:index]]", "Create a Database Migration" subcommand "generate", Napa::CLI::Generate + + desc "generate readme", "Create a formatted README" + subcommand "generate readme", Napa::CLI::Generate end end end