Module: App

Defined in:
lib/awx.rb

Class Method Summary collapse

Class Method Details

.executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/awx.rb', line 16

def self.execute

    begin

        unless !ARGV.any? || ARGV[0] == 'setup' || ARGV[0] == 'x'
            App::Config.initialize
        end

        Convoy::App.create do |my|

            #  COLOR OF TITLE TEXT
            title_color = 255

            my.version VERSION
            my.summary "\x1B[38;5;198mMY-CLI\x1B[0m \x1B[38;5;240m\xe2\x80\x94 BETA\x1B[0m"
            my.description "\x1B[38;5;#{title_color}mA command line utility for myself.\nDesigned to work from anywhere on my mac.\n\nUse #{Blufin::Terminal::format_command('my')}\x1B[38;5;#{title_color}m to run.\x1B[0m"

            # Checks whether a AWS 'blufin-cli' profile exists within ~/.aws ...
            unless App::AWSConfig::get_credentials(App::AWSConfig::AWS_PROFILE_ALBERT_CLI).nil?
                # a - AWS
                my.command :aws, :aliases => [:a] do |aws|
                    aws.summary 'AWS related functionality'
                    # cf - AWS CLOUD FORMATION
                    aws.command :cloudformation, :aliases => [:c] do |aws_cloudformation|
                        aws_cloudformation.summary 'Create, list and delete cloud-formation stacks'
                        # c - AWS CLOUD FORMATION CREATE
                        aws_cloudformation.command :create, :aliases => [:c] do |aws_cloudformation_create|
                            aws_cloudformation_create.summary 'Create stack'
                            aws_cloudformation_create.options do |opts|
                                opts.opt :test, 'Run through test-template.', :short => '-t', :long => '--test', :type => :boolean
                            end
                            aws_cloudformation_create.action do |opts, args|
                                AppCommand::AWSCloudFormationCreate.new(opts, args).execute
                            end
                        end
                        # d - AWS CLOUD FORMATION DETECT-DRIFT
                        aws_cloudformation.command :detect_drift, :aliases => [:d] do |aws_cloudformation_detect_drift|
                            aws_cloudformation_detect_drift.summary 'Detect drift (for stack)'
                            aws_cloudformation_detect_drift.action do |opts, args|
                                AppCommand::AWSCloudFormationDetectDrift.new(opts, args).execute
                            end
                        end
                        # D - AWS CLOUD FORMATION DELETE
                        aws_cloudformation.command :delete, :aliases => [:D] do |aws_cloudformation_delete|
                            aws_cloudformation_delete.summary 'Delete stack'
                            aws_cloudformation_delete.action do |opts, args|
                                AppCommand::AWSCloudFormationDelete.new(opts, args).execute
                            end
                        end
                        aws_cloudformation.action do
                            system("#{ConfigUnique::GEM_NAME} a c -h")
                        end
                    end
                    # l - AWS LIST
                    aws.command :list, :aliases => [:l] do |aws_list|
                        aws_list.summary 'List AWS instances/resources'
                        aws_list.options do |opts|
                            opts.opt :json, 'Return data as JSON', :short => '-j', :long => '--json', :type => :boolean
                            opts.opt :json_prompt, 'Return data as JSON (for Terminal::prompt)', :short => '-J', :long => '--json-prompt', :type => :boolean
                            opts.opt :yaml, 'Return data as Yaml', :short => '-y', :long => '--yaml', :type => :boolean
                            opts.opt :resource, "Specify a resource. For all resources type: #{Blufin::Terminal::format_command('all')}", :short => '-r', :long => '--resource', :type => :string
                            opts.opt :verbose, 'Output the original response from AWS (with all fields).', :short => '-v', :long => '--verbose', :type => :boolean
                            opts.opt :metadata, 'Output the YML definition file metadata.', :short => '-m', :long => '--metadata', :type => :boolean
                            # TODO - Implement Region + Project filtering (possibly more).
                            opts.opt :region, 'Specify a region', :short => '-R', :long => '--region', :type => :string
                            opts.opt :project, 'Specify a project (Tag: project)', :short => '-p', :long => '--project', :type => :string
                        end
                        aws_list.action do |opts, args|
                            AppCommand::AWSList.new(opts, args).execute
                        end
                    end
                    # L - AWS LAMBDA
                    aws.command :lambda, :aliases => [:L] do |aws_lambda|
                        aws_lambda.summary 'Quickly invoke a Lambda function locally (without the need to deploy)'
                        aws_lambda.options do |opts|
                            opts.opt :headers_file, 'The path to a JSON containing HTTP Headers you want to send', :short => '-H', :long => '--headers-file', :type => :string
                            opts.opt :payload_file, 'The path to a JSON payload you want to send', :short => '-p', :long => '--pay-load-file', :type => :string
                        end
                        aws_lambda.action do |opts, args|
                            AppCommand::AWSLambda.new(opts, args).execute
                        end
                    end
                    aws.action do |opts, args|
                        system("#{ConfigUnique::GEM_NAME} a -h")
                    end
                end
            end

            # x - SETUP
            my.command :setup, :aliases => [:x] do |setup|
                setup.summary 'Setup your configuration file'
                setup.action do |opts, args|
                    AppCommand::Setup.new(opts, args).execute
                end
            end

            # MY (DEFAULT)
            my.action do
                system("#{ConfigUnique::GEM_NAME} -h")
            end

        end

    rescue RuntimeError => e

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