Module: Belt::CLI

Defined in:
lib/belt/cli.rb,
lib/belt/cli/new_command.rb,
lib/belt/cli/env_resolver.rb,
lib/belt/cli/app_detection.rb,
lib/belt/cli/setup_command.rb,
lib/belt/cli/views_command.rb,
lib/belt/cli/tables_command.rb,
lib/belt/cli/bucket_security.rb,
lib/belt/cli/frontend_command.rb,
lib/belt/cli/generate_command.rb,
lib/belt/cli/terraform_command.rb,
lib/belt/cli/environment_command.rb,
lib/belt/cli/frontend_setup_command.rb,
lib/belt/cli/frontend_deploy_command.rb

Defined Under Namespace

Modules: AppDetection, BucketSecurity, EnvResolver Classes: EnvironmentCommand, FrontendCommand, FrontendDeployCommand, FrontendSetupCommand, GenerateCommand, NewCommand, SetupCommand, TablesCommand, TerraformCommand, ViewsCommand

Constant Summary collapse

COMMANDS =
{
  'new' => Belt::CLI::NewCommand,
  'generate' => Belt::CLI::GenerateCommand,
  'g' => Belt::CLI::GenerateCommand,
  'setup' => Belt::CLI::SetupCommand,
  'deploy' => lambda { |args|
    subcommand = args.shift
    if subcommand == 'frontend'
      Belt::CLI::FrontendDeployCommand.run(args)
    else
      puts 'Usage: belt deploy frontend <environment>'
      exit 1
    end
  },
  '--version' => ->(_args) { puts "Belt #{Belt::VERSION}" },
  '-v' => ->(_args) { puts "Belt #{Belt::VERSION}" }
}.freeze
TERRAFORM_ACTIONS =
Belt::CLI::TerraformCommand::ACTIONS

Class Method Summary collapse

Class Method Details

.start(args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/belt/cli.rb', line 36

def self.start(args)
  command = args.shift

  if command.nil?
    puts usage
    exit 1
  end

  # Terraform shorthand: belt init wups, belt plan wups, belt apply wups
  return Belt::CLI::TerraformCommand.run(command, args) if TERRAFORM_ACTIONS.include?(command)

  handler = COMMANDS[command]

  if handler.nil?
    puts "Unknown command: #{command}\n\n#{usage}"
    exit 1
  end

  if handler.is_a?(Proc)
    handler.call(args)
  else
    handler.run(args)
  end
end

.usageObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/belt/cli.rb', line 61

def self.usage
  <<~USAGE
    Usage: belt <command> [options]

    Commands:
      new <app_name> [--frontend react]           Create a new Belt application
      generate <resource|model|controller> <name> Generate components
      generate frontend <react|vue|svelte>        Scaffold a frontend app
      generate views <resource> [fields...]       Generate React pages for REST actions
      generate environment <name>                 Create a new environment
      setup state                                 Create/select S3 state bucket
      setup tables <env>                          Generate DynamoDB tables from schema
      setup frontend <env>                        Generate S3 + CloudFront infrastructure
      deploy frontend <env>                       Build and deploy frontend to AWS
      init <env>                                  terraform init for environment
      plan <env>                                  terraform plan for environment
      apply <env>                                 terraform apply for environment
      destroy <env>                               terraform destroy for environment
      output <env>                                terraform output for environment
      --version                                   Show Belt version

    Environment:
      Set BELT_ENV to skip the <env> argument:
        export BELT_ENV=wups
        belt apply                  # uses BELT_ENV
        belt apply dev01            # explicit arg wins

    Examples:
      belt new blog --frontend react
      belt generate resource post title:string content:text status:string
      belt generate frontend react
      belt setup frontend wups
      belt deploy frontend wups
      belt apply wups
  USAGE
end