lib/meroku/cli/session.rb in meroku-2.0.8 vs lib/meroku/cli/session.rb in meroku-2.0.9
- old
+ new
@@ -1,65 +1,46 @@
-
-
module Meroku
module CLI
+ # A session is what is created when user executes the meroku command
class Session
include Meroku::CLI
- include Meroku::Infrastructure
+ include Meroku::CLI::Help
- attr_accessor :ec2_client, :token
+ def initialize(args)
+ processed = process_user_login_command(args.join(' ')) ||
+ process_user_other_command(args.join(' ')) ||
+ process_admin_command(args.join(' '))
+ puts "Unknown command #{args.join(' ')}\n\n#{help}" unless processed
+ exit 1 unless processed
+ end
- def initialize(*args)
- case args.join(" ")
- when "signup"
+ def process_user_login_command(arguments)
+ case arguments
+ when /\Asignup/
signup
- when "create"
- Meroku::CLI::User.load_secrets(self) || exit
- create
- when "keys:add"
- Meroku::CLI::User.load_secrets(self) || exit
- keys_add(self)
- when "infrastructure spawn"
- Meroku::CLI::AdminUser.load_secrets(self) || exit
- spawn(self)
- when "infrastructure despawn"
- Meroku::CLI::AdminUser.load_secrets(self) || exit
- despawn
- else
- puts "Unknown command #{args.join(" ")}\n\n"
- puts help
+ when 'logout'
+ logout
+ when 'login'
+ login
end
-
-
- #case args.join(" ")
- # when "infrastructure spawn"
- # load_secrets || exit
- # node = Meroku::Infrastructure::Node.new.associate_address.install_packages.install_frontend_app
- # puts "spawned #{node.instance.try(:instance_id)}"
- # when "infrastructure despawn"
- # load_secrets || exit
- # Meroku::Infrastructure.despawn
- # when "signup"
- # signup
- # when "keys:add"
- # token_check || exit
- # keys_add
- # when "create"
- # token_check || exit
- # create
- # else
- # puts HELP
- #end
end
- def ec2_client
- @ec2_client ||= ::Aws::EC2::Client.new(
- region: 'us-east-1',
- credentials: ::Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET'])
- )
- @ec2_client
+ def process_user_other_command(arguments)
+ case arguments
+ when 'create'
+ create
+ when 'keys:add'
+ keys_add
+ end
end
+ def process_admin_command(arguments)
+ case arguments
+ when 'infrastructure spawn'
+ spawn
+ when 'infrastructure despawn'
+ despawn
+ end
+ end
end
end
end
-