Project

enel

0.0
No commit activity in last 3 years
No release in over 3 years
Remove duplicate logic in thor commad.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 10.0
~> 3.2

Runtime

~> 0.19
 Project Readme

⚡👼 Enel

Remove duplicate logic that use thor.

Gem Version Build Status

🎶 Images

🐤 Before


1 🐢🐰🐉(1)
2 🐢🐰🐉(2)
3 🐢🐰🐉(3)
4 🐢🐰🐉(4)

🐔 After

⚡👼
1
2
3
4
✨✨

☁️⬇️ Installation

Add this line to your application's Gemfile:

gem 'enel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install enel

📜 Usage

🐭 Sample Case

🐤 Before use

  • hoge.rb
require 'thor'
require_relative './commands/hoges'

class Hoge < Thor
  desc 'hoge1', 'hoge1'
  def hoge1
    puts Commands::Hoge1.run
  end

  desc 'hoge2', 'hoge2'
  def hoge2(args1)
    puts Commands::Hoge2.run(args1)
  end

  desc 'hoge3', 'hoge3'
  def hoge3(args1, *options)
    puts Commands::Hoge3.run(args1, *options)
  end

  # hoge4, hoge5... more!
end

Hoge.start(ARGV)
  • ./commands/hoges.rb
module Commands
  class Hoge1
    def run
      "hoge1"
    end
  end

  class Hoge2
    def run(args1)
      args1
    end
  end

  class Hoge3
    def run(args1, *options)
      [args1, *options]
    end
  end

  # hoge4, hoge5... more!
end
  • result
$ ruby hoge.rb hoge1
hoge1
$ ruby hoge.rb hoge2 a
a
$ ruby hoge.rb hoge3 a b c
a
b
c

🐔 After use

require 'thor'
require 'active_support/inflector'
require 'enel'
require_relative 'commands/hoges'

class Hoge < ::Thor
  extend Enel

  desc 'hoge1', 'hoge1'
  def hoge1
  end

  desc 'hoge2', 'hoge2'
  def hoge2(args1)
  end

  desc 'hoge3', 'hoge3'
  def hoge3(args1, *options)
  end

  # hoge4, hoge5... more!

  define_call_command(proc { |*args|
    command = args.first.to_s.camelize
    params = args[1..-1]
    puts Object.const_get("Commands::#{command}").new.run(*params)
  })
end

Hoge.start(ARGV)
  • result
$ ruby hoge.rb hoge1
hoge1
$ ruby hoge.rb hoge2 a
a
$ ruby hoge.rb hoge3 a b c
a
b
c

👬 Contributing 👭

  1. Fork it ( https://github.com/tbpgr/enel/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request