File: execution.rb

package info (click to toggle)
ruby-clamp 1.1.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 312 kB
  • sloc: ruby: 2,359; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 899 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Clamp
  module Subcommand

    module Execution

      # override default Command behaviour

      def execute
        # delegate to subcommand
        subcommand = instantiate_subcommand(subcommand_name)
        subcommand.run(subcommand_arguments)
      end

      private

      def instantiate_subcommand(name)
        subcommand_class = find_subcommand_class(name)
        subcommand = subcommand_class.new("#{invocation_path} #{name}", context)
        self.class.inheritable_attributes.each do |attribute|
          next unless attribute.of(self).defined?
          attribute.of(subcommand).set(attribute.of(self).get)
        end
        subcommand
      end

      def find_subcommand_class(name)
        subcommand_def = self.class.find_subcommand(name)
        return subcommand_def.subcommand_class if subcommand_def
        subcommand_missing(name)
      end

    end

  end
end