Sha256: 55b8a819c9947a1c0e9f8c43b778032a6aa0d467ba1f413ff3684b0a0f9517ce

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Command
  class Config < Base
    NAME = "config"
    OPTIONS = [
      app_option
    ].freeze
    DESCRIPTION = "Displays config for each app or a specific app"
    LONG_DESCRIPTION = <<~DESC
      - Displays config for each app or a specific app
    DESC
    EXAMPLES = <<~EX
      ```sh
      # Shows the config for each app.
      cpl config

      # Shows the config for a specific app.
      cpl config -a $APP_NAME
      ```
    EX

    def call # rubocop:disable Metrics/MethodLength
      if config.org_comes_from_env
        puts Shell.color("Org comes from CPLN_ORG env var", :yellow)
        puts
      end

      if config.app
        puts "#{Shell.color("Current config (app '#{config.app}')", :blue)}:"
        puts pretty_print(config.current)
        puts
      else
        config.apps.each do |app_name, app_options|
          puts "#{Shell.color("Config for app '#{app_name}'", :blue)}:"
          puts pretty_print(app_options)
          puts
        end
      end
    end

    private

    def pretty_print(hash)
      hash.transform_keys(&:to_s)
          .to_yaml(indentation: 2)[4..]
          # Adds an indentation of 2 to the beginning of each line
          .gsub(/^(\s*)/, "  \\1")
          # Adds an indentation of 2 before the '-' in array items
          .gsub(/^(\s*)-\s/, "\\1  - ")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cpl-1.1.2 lib/command/config.rb