Sha256: 92eae2afc5c17dc1aeedb864e00120a0f914a75511bccb14a198e86f3d62142d

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

module Sct
    class CLIToolsDistributor
        class << self 
            def take_off
                require 'sct'

                tool_name = ARGV.first ? ARGV.first.downcase : nil

                if tool_name && Sct::TOOLS.include?(tool_name.to_sym)
                    # Triggering a specific tool
          
                    require tool_name
                    begin
                      # First, remove the tool's name from the arguments
                      # Since it will be parsed by the `commander` at a later point
                      # and it must not contain the binary name
                      ARGV.shift
          
                      # Import the CommandsGenerator class, which is used to parse
                      # the user input
                      require File.join(tool_name, "commands_generator")
          
                      # Call the tool's CommandsGenerator class and let it do its thing
                      commands_generator = Object.const_get(tool_name.sct_module)::CommandsGenerator
                    rescue LoadError
                      # This will only happen if the tool we call here, doesn't provide
                      # a CommandsGenerator class yet
                      # When we launch this feature, this should never be the case
                      abort("#{tool_name} can't be called via `sct #{tool_name}`, run '#{tool_name}' directly instead".red)
                    end
          
                    # Some of the tools might use other actions so need to load all
                    # actions before we start the tool generator here in the future
                    Sct.load_actions
                    
                    # trigger start on tool
                    commands_generator.start

                else 
                    require "sct/commands_generator"
                    Sct::CommandsGenerator.start
                end
            end
        end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sct-0.1.20 sct/lib/sct/cli_tools_distributor.rb
sct-0.1.19 sct/lib/sct/cli_tools_distributor.rb