Sha256: 4a41b4695506496e9e99641caf72188bea561ff12febad3e267dd30f18a38055

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 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, :type, :manager, :options, :aliases
      attr_accessor :banner

      def initialize(manager,
                     name = '',
                     type = UltraCommandLine::Commands::Factory::DEFAULT_COMMAND_TYPE,
                     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
        register_options(options)
        @aliases = [self.name]
        @type = type
      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 register_options(options)
        options.each { |option| option.sub_command = self }
        @options = options
      end

      def self_view_of_manager_cmd_line_args
        manager.cmd_line_args_for_command self
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ultra_command_line-0.4.16 lib/ultra_command_line/commands/sub_command.rb
ultra_command_line-0.4.15 lib/ultra_command_line/commands/sub_command.rb
ultra_command_line-0.4.14 lib/ultra_command_line/commands/sub_command.rb
ultra_command_line-0.4.13 lib/ultra_command_line/commands/sub_command.rb
ultra_command_line-0.4.12 lib/ultra_command_line/commands/sub_command.rb