<commit_before>require 'clamp/subcommand/execution'

module Clamp
  class Subcommand

    module Parsing

      protected

      def parse_subcommand
        return false unless self.class.has_subcommands?
        subcommand_name = parse_subcommand_name
        @subcommand = instatiate_subcommand(subcommand_name)
        self.extend(Subcommand::Execution)
      end

      private

      def parse_subcommand_name
        remaining_arguments.shift || self.class.default_subcommand || request_help
      end

      def find_subcommand(name)
        self.class.find_subcommand(name) ||
        signal_usage_error("No such sub-command '#{name}'")
      end

      def instatiate_subcommand(name)
        subcommand_class = find_subcommand(name).subcommand_class
        subcommand = subcommand_class.new("#{invocation_path} #{name}", context)
        self.class.recognised_options.each do |option|
          if instance_variable_defined?(option.ivar_name)
            subcommand.instance_variable_set(option.ivar_name, instance_variable_get(option.ivar_name))
          end
        end
        subcommand
      end

    end

  end
end<commit_msg>Be more careful when passing option values into subcommands.<commit_after>require 'clamp/subcommand/execution'

module Clamp
  class Subcommand

    module Parsing

      protected

      def parse_subcommand
        return false unless self.class.has_subcommands?
        subcommand_name = parse_subcommand_name
        @subcommand = instatiate_subcommand(subcommand_name)
        self.extend(Subcommand::Execution)
      end

      private

      def parse_subcommand_name
        remaining_arguments.shift || self.class.default_subcommand || request_help
      end

      def find_subcommand(name)
        self.class.find_subcommand(name) ||
        signal_usage_error("No such sub-command '#{name}'")
      end

      def instatiate_subcommand(name)
        subcommand_class = find_subcommand(name).subcommand_class
        subcommand = subcommand_class.new("#{invocation_path} #{name}", context)
        shared_options = self.class.recognised_options & subcommand_class.recognised_options
        shared_options.each do |option|
          if instance_variable_defined?(option.ivar_name)
            subcommand.instance_variable_set(option.ivar_name, instance_variable_get(option.ivar_name))
          end
        end
        subcommand
      end

    end

  end
end
{'fraction_non_alphanumeric': 0.06873706004140787, 'fraction_numerical': 0.0, 'mean_word_length': 2.947712418300654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2952382', 'n_tokens_mistral': 687, 'n_tokens_neox': 670, 'n_words': 126}