Sha256: 1aeeb3514288008c62dfb34926c4446312ce9f06a06e417eb7e04340b4aefcb0

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

require 'thor'
require 'modulesync/cli'

module ModuleSync
  module CLI
    # Workaround some, still unfixed, Thor behaviors
    #
    # This class extends ::Thor class to
    # - exit with status code sets to `1` on Thor failure (e.g. missing required option)
    # - exit with status code sets to `1` when user calls `msync` (or a subcommand) without required arguments
    # - show subcommands help using `msync subcommand --help`
    class Thor < ::Thor
      def self.start(*args)
        if (Thor::HELP_MAPPINGS & ARGV).any? && subcommands.none? { |command| command.start_with?(ARGV[0]) }
          Thor::HELP_MAPPINGS.each do |cmd|
            if (match = ARGV.delete(cmd))
              ARGV.unshift match
            end
          end
        end
        super
      end

      desc '_invalid_command_call', 'Invalid command', hide: true
      def _invalid_command_call
        self.class.new.help
        exit 1
      end
      default_task :_invalid_command_call

      def self.exit_on_failure?
        true
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
modulesync-3.2.0 lib/modulesync/cli/thor.rb
modulesync-3.1.0 lib/modulesync/cli/thor.rb
modulesync-2.7.0 lib/modulesync/cli/thor.rb
modulesync-2.6.0 lib/modulesync/cli/thor.rb
modulesync-2.5.0 lib/modulesync/cli/thor.rb
modulesync-2.4.0 lib/modulesync/cli/thor.rb
modulesync-2.3.1 lib/modulesync/cli/thor.rb
modulesync-2.3.0 lib/modulesync/cli/thor.rb