Sha256: 446c1b392f99d1ec54d7db7ca2d8adf534e734b1aa4ad8f06a7b76f07f95ca96

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

require 'ultra_command_line/commands/validation'
require 'ultra_command_line/commands/command_line_parser'
require 'ultra_command_line/commands/main_command'
require 'ultra_command_line/commands/option_definition'
require 'ultra_command_line/commands/help_formatter'
require 'ultra_command_line/commands/factory'

module UltraCommandLine
  module Commands

    class SubCommand

      include UltraCommandLine::Utils::ErrorPropagation

      extend UltraCommandLine::Commands::Factory

      include UltraCommandLine::Commands::Validation
      include UltraCommandLine::Commands::HelpFormatter
      include UltraCommandLine::Commands::CommandLineParser


      attr_reader :name, :manager, :options, :aliases
      attr_accessor :banner

      def initialize(manager,
                     name = '',
                     banner = UltraCommandLine::Commands::Factory::DEFAULT_BANNER,
                     options: [])
        @manager = manager
        @name = name
        if name.empty?
          class << self; include UltraCommandLine::Commands::MainCommand; end
        end
        self.banner = banner
        @options = options
        @aliases = [self.name]
      end

      def root_command?
        singleton_class.ancestors.include? UltraCommandLine::Commands::MainCommand
      end

      def cmd_line_args
        self_view_of_manager_cmd_line_args
      end

      private

      attr_writer :manager

      def self_view_of_manager_cmd_line_args
        manager.cmd_line_args_for_command self
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ultra_command_line-0.4.8 lib/ultra_command_line/commands/sub_command.rb
ultra_command_line-0.4.7 lib/ultra_command_line/commands/sub_command.rb