Sha256: 2a77eeb427ba917646ca4aef5278576e052ea1174ce718b7a012e0150d47774c

Contents?: true

Size: 910 Bytes

Versions: 4

Compression:

Stored size: 910 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`).
      cpflow open -a $APP_NAME

      # Opens the endpoint of a specific workload.
      cpflow 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
cpflow-4.0.1 lib/command/open.rb
cpflow-4.0.0 lib/command/open.rb
cpflow-3.0.1 lib/command/open.rb
cpflow-3.0.0 lib/command/open.rb