Sha256: 7bbc38ea843c06de3da17afe5daf5e3f97aeb60a57af6e2385edc0709c82f76f

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 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.to_a.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.to_a.empty? ? nil : services_as_args
        chosen_services ||= [service] if in_service?
        chosen_services ||= configured_services.to_a.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.5.0 lib/neptuno/cli/base.rb
neptuno-1.4.10 lib/neptuno/cli/base.rb
neptuno-1.2.1 lib/neptuno/cli/base.rb
neptuno-1.2.0 lib/neptuno/cli/base.rb