public
Created

canhaz

  • Download Gist
canhaz.rb
Ruby
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
# -*- encoding: utf-8 -*-
 
require 'thor'
require 'pathname'
 
module Canhaz
 
class Commands < Thor
desc "deploy","deploy"
def deploy
puts "deploying"
end
 
class Recipes < Thor
desc "apply", "apply"
def apply
puts "applying"
end
end
 
desc "recipes", "recipes"
subcommand :recipes, Recipes
end
 
end
 
Canhaz::Commands.start(ARGV)
 
# THIS IS WHAT I GET
 
# ./bin/canhaz -h
# Tasks:
# canhaz apply # apply
# canhaz deploy # deploy
# canhaz help [COMMAND] # Describe subcommands or one specific subcommand
# canhaz help [TASK] # Describe available tasks or one specific task
# canhaz recipes # recipes
 
# ./bin/canhaz recipes -h
# Tasks:
# canhaz apply # apply
# canhaz help [COMMAND] # Describe subcommands or one specific subcommand
 
# THIS IS WHAT I WANT
 
# ./bin/canhaz -h
# Tasks:
# canhaz deploy # deploy
# canhaz recipes # recipes
# canhaz recipes apply # apply
# canhaz help [COMMAND] # Describe subcommands or one specific subcommand
# canhaz help [TASK] # Describe available tasks or one specific task
 
# ./bin/canhaz recipes -h
# Tasks:
# canhaz recipes apply # apply
# canhaz recipes help [COMMAND] # Describe subcommands or one specific subcommand
patch.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
class Canhaz::Thor < ::Thor
 
class << self
 
attr_accessor :superthor, :superthor_name
def basename
superthor ? "#{superthor.basename} #{superthor_name}" : superthor
end
 
def subcommand(subcommand, subcommand_class)
self.subcommands << subcommand.to_s
subcommand_class.subcommand_help subcommand
subcommand_class.superthor = self
subcommand_class.superthor_name = subcommand
 
define_method(subcommand) { |*args| invoke subcommand_class, args }
end
 
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.