# File lib/rhc/commands/app.rb, line 27
    def create(name, cartridges)
      cartridge = check_cartridges(cartridges).first

      options.default \
        :dns => true,
        :git => true

      paragraph do
        header "Application Options"
        table({"Namespace:" => options.namespace,
               "Cartridge:" => cartridge,
               "Gear Size:" => options.gear_size || "default",
               "Scaling:" => options.scaling ? "yes" : "no",
              }
             ).each { |s| say "  #{s}" }
      end

      raise ArgumentError, "You have named both your main application and your Jenkins application '#{name}'. In order to continue you'll need to specify a different name with --enable-jenkins or choose a different application name." if jenkins_app_name == name && enable_jenkins?

      rest_app, rest_domain = nil
      raise RHC::DomainNotFoundException.new("No domains found. Please create a domain with 'rhc domain create <namespace>' before creating applications.") if rest_client.domains.empty?
      rest_domain = rest_client.find_domain(options.namespace)

      messages = []

      paragraph do
        say "Creating application '#{name}' ... "


        # create the main app
        rest_app = create_app(name, cartridge, rest_domain,
                              options.gear_size, options.scaling)

        messages.concat(rest_app.messages)

        success "done"
      end

      build_app_exists = rest_app.building_app

      if enable_jenkins?
        unless build_app_exists
          paragraph do
            say "Setting up a Jenkins application ... "

            begin
              build_app_exists = add_jenkins_app(rest_domain)

              success "done"
              messages.concat(build_app_exists.messages)

            rescue Exception => e
              warn "not complete"
              add_issue("Jenkins failed to install - #{e}",
                        "Installing jenkins and jenkins-client",
                        "rhc app create jenkins",
                        "rhc cartridge add jenkins-client -a #{rest_app.name}")
            end
          end
        end

        paragraph do
          add_jenkins_client_to(rest_app, messages)
        end if build_app_exists
      end

      if options.dns
        paragraph do
          say "Waiting for your DNS name to be available ... "
          if dns_propagated? rest_app.host
            success "done"
          else
            warn "failure"
            add_issue("We were unable to lookup your hostname (#{rest_app.host}) in a reasonable amount of time and can not clone your application.",
                      "Clone your git repo",
                      "rhc git-clone #{rest_app.name}")

            output_issues(rest_app)
            return 0
          end
        end

        if options.git
          paragraph do
            debug "Checking SSH keys through the wizard"
            check_sshkeys! unless options.noprompt

            say "Downloading the application Git repository ..."
            paragraph do
              begin
                git_clone_application(rest_app)
              rescue RHC::GitException => e
                warn "#{e}"
                unless RHC::Helpers.windows? and windows_nslookup_bug?(rest_app)
                  add_issue("We were unable to clone your application's git repo - #{e}",
                            "Clone your git repo",
                            "rhc git-clone #{rest_app.name}")
                end
              end
            end
          end
        end
      end

      display_app(rest_app, rest_app.cartridges)

      if issues?
        output_issues(rest_app)
      else
        results{ messages.each { |msg| success msg } }.blank? and "Application created"
      end

      0
    end