Class: Tap::Exe
Constant Summary
collapse
- GLOBAL_CONFIG_FILE =
The global config file path
File.join(Gem.user_home, ".tap.yml")
Constants inherited
from Env
Tap::Env::DEFAULT_CONFIG_FILE, Tap::Env::TEMPLATES
Instance Attribute Summary
Attributes inherited from Env
#logger, #root
#config
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Env
#activate, #active?, #count, #deactivate, #each, #env_path, #envs, #envs=, gemspecs, #initialize, #inspect, instance, instances, #log, manifest, pathify, #push, #reconfigure, #recursive_each, #recursive_inspect, #reverse_each, #search_path, #summarize, #unshift
#minimap, #minimatch
included, #initialize_copy, #reconfigure
Constructor Details
This class inherits a constructor from Tap::Env
Class Method Details
.instance_for(path) ⇒ Object
27
28
29
30
|
# File 'lib/tap/exe.rb', line 27
def instance_for(path)
path = pathify(path)
instances.has_key?(path) ? instances[path] : Env.instantiate(path)
end
|
.instantiate(path = Dir.pwd, logger = Tap::App::DEFAULT_LOGGER, &block) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/tap/exe.rb', line 9
def instantiate(path=Dir.pwd, logger=Tap::App::DEFAULT_LOGGER, &block)
app = Tap::App.instance = Tap::App.new({:root => path}, logger)
exe = super(app, load_config(GLOBAL_CONFIG_FILE), app.logger, &block)
if !File.exists?(Tap::Env::DEFAULT_CONFIG_FILE)
exe.gems = gemspecs(false)
end
tap = instance_for("#{File.dirname(__FILE__)}/../..")
exe.push(tap)
exe
end
|
Instance Method Details
Alias for root (Exe should have a Tap::App as root)
41
42
43
|
# File 'lib/tap/exe.rb', line 41
def app
root
end
|
#build(argv = ARGV) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/tap/exe.rb', line 76
def build(argv=ARGV)
schema = argv.kind_of?(Support::Schema) ? argv : Support::Schema.parse(argv)
schema.compact.build(app) do |args|
task = args.shift
const = tasks.search(task)
task_class = case
when const then const.constantize
when block_given?
args.unshift(task)
yield(args)
else nil
end
task_class or raise ArgumentError, "unknown task: #{task}"
task_class.parse(args, app) do |help|
puts help
exit
end
end
end
|
#execute(argv = ARGV) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/tap/exe.rb', line 55
def execute(argv=ARGV)
command = argv.shift.to_s
if aliases && aliases.has_key?(command)
aliases[command].reverse_each {|arg| argv.unshift(arg)}
command = argv.shift
end
case command
when '', '--help'
yield
else
if path = commands.search(command)
load path else
puts "Unknown command: '#{command}'"
puts "Type 'tap help' for usage information."
end
end
end
|
#handle_error(err) ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'lib/tap/exe.rb', line 45
def handle_error(err)
case
when $DEBUG
puts err.message
puts
puts err.backtrace
else puts err.message
end
end
|
#run(queues) ⇒ Object
135
136
137
138
139
140
|
# File 'lib/tap/exe.rb', line 135
def run(queues)
queues.each_with_index do |queue, i|
app.queue.concat(queue)
app.run
end
end
|
#set_signals ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/tap/exe.rb', line 98
def set_signals
signals = Signal.list.keys
if signals.include?("INFO")
Signal.trap("INFO") do
puts app.info
end
end
if signals.include?("INT")
Signal.trap("INT") do
puts " interrupted!"
while true
print "stop, terminate, exit, or resume? (s/t/e/r):"
case gets.strip
when /s(top)?/i
app.stop
break
when /t(erminate)?/i
app.terminate
break
when /e(xit)?/i
exit
when /r(esume)?/i
break
else
puts "unexpected response..."
end
end
end
end
end
|