@@ -24,6 +24,10 @@ def code
2424 @code ||= File . read ( path )
2525 end
2626
27+ def commands
28+ actions . values . select ( &:help )
29+ end
30+
2731 def eval_code
2832 return if evaluated?
2933
@@ -39,6 +43,18 @@ def full_name
3943 id . join ' '
4044 end
4145
46+ def guests
47+ @guests ||= begin
48+ result = imports . map do |glob , context |
49+ Dir . glob ( "#{ glob } .runfile" ) . sort . map do |guest_path |
50+ Userfile . new guest_path , context : context , host : self
51+ end
52+ end
53+
54+ result . flatten
55+ end
56+ end
57+
4258 def id
4359 if host
4460 ( host . id + [ name ] ) . compact
@@ -61,32 +77,23 @@ def rootfile?
6177
6278 def run ( argv = [ ] )
6379 eval_code
80+ argv = transform_argv argv if argv . any?
81+
6482 found_guest = find_guest argv
83+
6584 if found_guest
6685 found_guest . run argv
6786 else
6887 run_local argv
6988 end
7089 end
7190
72- def commands
73- actions . values . select ( &:help )
74- end
75-
76- def guests
77- @guests ||= begin
78- result = imports . map do |glob , context |
79- Dir . glob ( "#{ glob } .runfile" ) . sort . map do |guest_path |
80- Userfile . new guest_path , context : context , host : self
81- end
82- end
91+ private
8392
84- result . flatten
85- end
93+ def docopt
94+ @docopt ||= render 'userfile' , context : self
8695 end
8796
88- private
89-
9097 def find_action ( args )
9198 acts = actions . values
9299 acts . find { |a | args [ a . name ] } ||
@@ -121,8 +128,12 @@ def run_local(argv)
121128 exit_code if exit_code . is_a? Integer
122129 end
123130
124- def docopt
125- @docopt ||= render 'userfile' , context : self
131+ def transform_argv ( argv )
132+ transforms . each do |from , to |
133+ return Shellwords . split ( to ) + argv [ 1 ..] if from == argv [ 0 ]
134+ end
135+
136+ argv
126137 end
127138 end
128139end
0 commit comments