Sha256: eafd9207adffa1a8badb578c50bd5fcc6ab8d5294a567d170de15a3ca3d89848

Contents?: true

Size: 904 Bytes

Versions: 4

Compression:

Stored size: 904 Bytes

Contents

# frozen_string_literal: true

module Command
  class Open < Base
    NAME = "open"
    OPTIONS = [
      app_option(required: true),
      workload_option
    ].freeze
    DESCRIPTION = "Opens the app endpoint URL in the default browser"
    LONG_DESCRIPTION = <<~HEREDOC
      - Opens the app endpoint URL in the default browser
    HEREDOC
    EXAMPLES = <<~HEREDOC
      ```sh
      # Opens the endpoint of the default workload (`one_off_workload`).
      cpl open -a $APP_NAME

      # Opens the endpoint of a specific workload.
      cpl open -a $APP_NAME -w $WORKLOAD_NAME
      ```
    HEREDOC

    def call
      workload = config.options[:workload] || config[:one_off_workload]
      data = cp.workload_get_and_ensure(workload)
      url = data["status"]["endpoint"]
      opener = `which xdg-open open`.split("\n").grep_v("not found").first

      exec %(#{opener} "#{url}")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cpl-0.3.3 lib/command/open.rb
cpl-0.3.2 lib/command/open.rb
cpl-0.3.1 lib/command/open.rb
cpl-0.3.0 lib/command/open.rb