module App

Constants

CONFIG_FILE
GEM_NAME
SCHEMA_FILE
TEMPLATE_FILE

Public Class Methods

execute() click to toggle source
# File lib/blufin.rb, line 22
    def self.execute

        begin

            unless ARGV[0] == 'setup' || ARGV[0] == 'x'
                Blufin::Config::init(SCHEMA_FILE, TEMPLATE_FILE, App::CONFIG_FILE, App::GEM_NAME)
                Blufin::Projects::init(Blufin::Config::get, App::CONFIG_FILE)
            end

            Convoy::App.create do |app|

                # http://patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=Blufin
                app.version BLUFIN_VERSION
                app.summary <<TEMPLATE
 \x1B[48;5;20m\x1B[38;5;255m Blufin \x1B[0m\x1B[0m \x1B[38;5;32m\xe2\x80\x94 Command-Line Interface \xe2\x80\x94\x1B[38;5;248m 🐳 


    ██████╗ ██╗     ██╗   ██╗███████╗██╗███╗   ██╗
    ██╔══██╗██║     ██║   ██║██╔════╝██║████╗  ██║
    ██████╔╝██║     ██║   ██║█████╗  ██║██╔██╗ ██║
    ██╔══██╗██║     ██║   ██║██╔══╝  ██║██║╚██╗██║
    ██████╔╝███████╗╚██████╔╝██║     ██║██║ ╚████║
    ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝     ╚═╝╚═╝  ╚═══╝\x1B[0m
TEMPLATE
                app.description "The secret sauce that makes everything 'tick'..."

                # b - BUILD
                app.command :build, :aliases => [:b] do |build|
                    build.summary "Build #{Blufin::Terminal::format_highlight('project-specific')} java services #{Blufin::Terminal::format_invalid('@deprecated')}"
                    build.options do |opts|
                        opts.opt :skip_tests, 'Skip tests', :short => '-S', :long => '--skip', :type => :boolean
                    end
                    build.action do |opts, args|
                        AppCommand::Build.new(opts, args).execute
                    end
                end

                # c - CREATE
                app.command :create, :aliases => [:c] do |create|
                    create.summary 'Create skeleton project from archetype(s)'
                    # a - CREATE API
                    create.command :api, :aliases => [:a] do |create_api|
                        create_api.summary 'Create API skeleton'
                        create_api.action do |opts, args|
                            AppCommand::CreateApi.new(opts, args).execute
                        end
                    end
                    # u - CREATE UI
                    create.command :ui, :aliases => [:u] do |create_ui|
                        create_ui.summary 'Create UI skeleton'
                        create_ui.action do |opts, args|
                            AppCommand::CreateUI.new(opts, args).execute
                        end
                    end
                    # CREATE (Default)
                    create.action do
                        system("#{App::GEM_NAME} c -h")
                    end
                end

                # e - EXPORT
                app.command :export, :aliases => [:e] do |export|
                    export.summary 'Export internal data structures'
                    export.options do |opts|
                        opts.opt :maven_blufin, 'Maven BOM (Blufin)', :short => '-m', :long => '--maven-blufin', :type => :boolean
                        opts.opt :maven_app, 'Maven BOM (App)', :short => '-M', :long => '--maven-app', :type => :boolean
                    end
                    export.action do |opts, args|
                        AppCommand::Export.new(opts, args).execute
                    end
                end

                # g - GENERATE
                app.command :generate, :aliases => [:g] do |generate|
                    generate.summary "Generate #{Blufin::Terminal::format_highlight('code')} (and other things)"
                    # a - GENERATE API
                    generate.command :api, :aliases => [:a] do |generate_api|
                        generate_api.summary 'Generate boiler-plate API code (from YML files)'
                        generate_api.action do |opts, args|
                            AppCommand::GenerateApi.new(opts, args).execute
                        end
                    end
                    # l - GENERATE LAMBDA
                    generate.command :lambda, :aliases => [:l] do |generate_lambda|
                        generate_lambda.summary 'Generate boiler-plate AWS Lambda code'
                        generate_lambda.action do |opts, args|
                            AppCommand::GenerateLambda.new(opts, args).execute
                        end
                    end
                    # generate - GENERATE UI
                    generate.command :ui, :aliases => [:u] do |generate_ui|
                        generate_ui.summary 'Generate UI stuff'
                        # a - GENERATE UI LANDING PAGE
                        generate_ui.command :img_landing, :aliases => [:l] do |generate_ui_img_landing|
                            generate_ui_img_landing.summary 'Generate different landing page image sizes'
                            generate_ui_img_landing.options do |opts|
                                opts.opt :add_size, 'Add image size (in top-left corner)', :short => '-s', :long => '--add-size', :type => :boolean
                                opts.opt :quality, 'Quality of the image (default: 60)', :short => '-q', :long => '--quality', :type => :string, :default => '60'
                                opts.opt :skip_confirm, 'Skip confirmation', :short => '-y', :long => '--skip-confirm', :type => :boolean
                            end
                            generate_ui_img_landing.action do |opts, args|
                                AppCommand::GenerateUIImageLanding.new(opts, args).execute
                            end
                        end
                        # a - GENERATE UI FAVICON
                        generate_ui.command :img_favicon, :aliases => [:f] do |generate_ui_img_favicon|
                            generate_ui_img_favicon.summary 'Generate favicon.ico file'
                            generate_ui_img_favicon.action do |opts, args|
                                AppCommand::GenerateUIFavIcon.new(opts, args).execute
                            end
                        end
                        # GENERATE UI (Default)
                        generate_ui.action do
                            system("#{App::GEM_NAME} g ui -h")
                        end
                    end
                    # GENERATE (Default)
                    generate.action do
                        system("#{App::GEM_NAME} g -h")
                    end
                end

                # l - LINT
                app.command :lint, :aliases => [:l] do |lint|
                    lint.summary "Scans code for errors/anti-patterns #{Blufin::Terminal::format_invalid('@todo')}"
                    lint.action do |opts, args|
                        AppCommand::Lint.new(opts, args).execute
                    end
                end

                # M - MYSQL
                app.command :mysql, :aliases => [:M] do |mysql|
                    mysql.summary 'Manage development databases (and mock data)'
                    # r - MYSQL RESET
                    mysql.command :reset, :aliases => [:r] do |mysql_reset|
                        mysql_reset.summary 'Reset development databases to a standard configuration'
                        mysql_reset.options do |opts|
                            opts.opt :skip_confirm, 'Skip confirmation (a safety measure to prevent accidental reset)', :short => '-y', :long => '--skip-confirm', :type => :boolean
                            opts.opt :verbose, 'Verbose', :short => '-v', :long => '--verbose', :type => :boolean
                        end
                        mysql_reset.action do |opts, args|
                            AppCommand::MySQLReset.new(opts, args).execute
                        end
                    end
                    # MYSQL (Default)
                    mysql.action do
                        system("#{App::GEM_NAME} M -h")
                    end
                end

                # r - RUN
                app.command :run, :aliases => [:r] do |run|
                    run.summary "Run a project/service #{Blufin::Terminal::format_invalid('@todo')}"
                    run.action do |opts, args|
                        AppCommand::Run.new(opts, args).execute
                    end
                end

                # R - RELEASE
                # TODO - This might need to be behind some-kind of toggle so devs can't just release blufin, willy-nilly.
                app.command :release, :aliases => [:R] do |release|
                    release.summary 'Create & deploy new releases'
                    # b - RELEASE BLUFIN
                    release.command :blufin, :aliases => [:b] do |release_blufin|
                        release_blufin.summary 'Create and deploy the latest version of Blufin (along with all the gems, lambdas, etc.)'
                        release_blufin.action do |opts, args|
                            AppCommand::ReleaseBlufin.new(opts, args).execute
                        end
                    end
                    # RELEASE (Default)
                    release.action do
                        system("#{App::GEM_NAME} R -h")
                    end
                end

                # p - PROJECT
                app.command :project, :aliases => [:p] do |project|
                    project.summary 'Information about Projects'
                    # al - PROJECT API LIST
                    project.command :api_list, :aliases => [:al] do |project_api_list|
                        project_api_list.summary 'List all APIs'
                        project_api_list.action do |opts, args|
                            AppCommand::APIList.new(opts, args).execute
                        end
                    end
                    # am - PROJECT API META
                    project.command :api_meta, :aliases => [:am] do |project_api_meta|
                        project_api_meta.summary 'Display various meta-data about an API'
                        project_api_meta.options do |opts|
                            opts.opt :show_auto_increment, "Show #{Blufin::Terminal::format_highlight('AUTO_INCREMENT')} columns", :short => '-a', :long => '--show-auto-increment', :type => :boolean
                            opts.opt :show_enums, "Show all available #{Blufin::Terminal::format_highlight('ENUMs')} (and their values)", :short => '-e', :long => '--show-enums', :type => :boolean
                            opts.opt :show_resources, "Show #{Blufin::Terminal::format_highlight('RESOURCE')} structure #{Blufin::Terminal::format_invalid('@deprecated')}", :short => '-r', :long => '--show-resources', :type => :boolean
                            opts.opt :as_json, 'Return meta-data as JSON (might not work for all paths)', :short => '-J', :long => '--as-json', :type => :boolean
                        end
                        project_api_meta.action do |opts, args|
                            AppCommand::APIMeta.new(opts, args).execute
                        end
                    end
                    # PROJECT (Default)
                    project.action do
                        system("#{App::GEM_NAME} p -h")
                    end
                end

                # x - CONFIG
                app.command :config, :aliases => [:x] do |config|
                    config.summary 'Setup your configuration file'
                    config.action do
                        Blufin::Config::edit_config(App::CONFIG_FILE)
                    end
                end

                # BLUFIN (Default)
                app.action do
                    system("#{App::GEM_NAME} -h")
                end
            end

        rescue RuntimeError => e

            Blufin::Terminal::print_exception(e);
        end
    end