Sha256: 65c9098393657e27e75c4522f2ed515fa7942b47b56a7c2e3c952bd19d26767c

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 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(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

2 entries across 2 versions & 1 rubygems

Version Path
cpl-0.2.0 lib/command/open.rb
cpl-0.1.0 lib/command/open.rb