Sha256: 9a6c57cd2d51030cc08807b7d2fe7ef3dd80ff824d3aa97a9caaf21cb5a4752b

Contents?: true

Size: 1.26 KB

Versions: 4

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

4 entries across 4 versions & 1 rubygems

Version Path
neptuno-1.0.10 lib/neptuno/cli/base.rb
neptuno-1.0.9 lib/neptuno/cli/base.rb
neptuno-1.0.8 lib/neptuno/cli/base.rb
neptuno-1.0.7 lib/neptuno/cli/base.rb