-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli
executable file
·73 lines (63 loc) · 1.52 KB
/
cli
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env ruby
require "thor"
require 'active_support/concern'
module MyCli
class SubThor < Thor
def self.banner(command, namespace = nil, subcommand = false)
sans_help = ARGV[0] == "help" ? ARGV[1] : ARGV[0]
"#{basename} #{sans_help} #{command.usage}"
end
end
$modules = []
CLASS_REGEX = /class\s(\w+)\s+\<\s+\SubThor/
begin
# load shared libraries
Dir.glob('./lib/*.rb').each do |file|
require file
end
# load module code
Dir.glob('./concerns/*.rb').each do |file|
require file
end
# load modules
Dir.glob('./modules/*.rb').each do |mod_file|
require mod_file
$modules << open(mod_file) do |file|
file.grep(CLASS_REGEX) do |line|
class_name = line.match(CLASS_REGEX)[1]
self.const_get(class_name)
end
end
end
rescue StandardError => e
puts "Unable to load module: #{e.message}"
end
class MyFoo < Thor
desc "foo", "puts foo"
def foo
test
puts 'foo'
end
desc "mofoo", "puts mofoo"
def mofoo
puts 'mofoo'
end
no_commands do
def test
puts '1'
end
end
# load in the subcommands
$modules.each do |mod_array|
mod_array.each do |klass|
begin
desc "#{klass::SUBCOMMAND} SUBCOMMAND", klass::DESCRIPTION
subcommand klass::SUBCOMMAND, klass
rescue StandardError => e
puts "Unable to load subcommand: #{e.message}"
end
end
end
end
end
MyCli::MyFoo.start(ARGV)