Sha256: 1524da2742a18bf9955bf6cc03c573da368c70efc51bef3b7aad8990b95ff9e6

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 = <<~DESC
      - Opens the app endpoint URL in the default browser
    DESC
    EXAMPLES = <<~EX
      ```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
      ```
    EX

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

      Kernel.exec(opener, url)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cpl-2.2.4 lib/command/open.rb
cpl-2.2.2 lib/command/open.rb
cpl-2.2.1 lib/command/open.rb
cpl-2.2.0 lib/command/open.rb