Sha256: cc2b25ada940352e1ef56c4a8bf17f1381cd1be887be64e015cd77cfb62d282b

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Neptuno
  module CLI
    # Base cli class for Neptuno
    class Base < Dry::CLI::Command
      include Neptuno::TTY::Config
      include TTY::Prompt
      include TTY::File
      include Neptuno::TTY::Command

      ABORT_MESSAGE = 'fatal: not a Neptuno repository (or any of the parent directories)'

      def initialize
        abort ABORT_MESSAGE if neptuno_path == ''
        config.append_path(neptuno_path)
        config.read
      end

      def command_service_to(request, service_as_args: '')
        chosen_service ||= service_as_args&.empty? ? nil : service_as_args
        chosen_service ||= service if in_service?
        chosen_service ||= prompt.select("Command service to #{request}:", services)
        yield chosen_service, project
      end

      def command_services_to(request, all: nil, services_as_args: [])
        chosen_services = services if all
        chosen_services ||= services_as_args&.empty? ? nil : services_as_args
        chosen_services ||= [service] if in_service?
        chosen_services ||= configured_services.empty? ? nil : configured_services
        chosen_services ||= prompt.multi_select("Command services to #{request}:", services)
        yield chosen_services, project
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
neptuno-1.0.6 lib/neptuno/cli/base.rb
neptuno-1.0.5 lib/neptuno/cli/base.rb
neptuno-1.0.3 lib/neptuno/cli/base.rb
neptuno-1.0.2 lib/neptuno/cli/base.rb
neptuno-1.0.1 lib/neptuno/cli/base.rb
neptuno-1.0.0 lib/neptuno/cli/base.rb