lib/alf/shell/support.rb in alf-shell-0.14.0 vs lib/alf/shell/support.rb in alf-shell-0.15.0
- old
+ new
@@ -1,28 +1,36 @@
module Alf
module Shell
module Support
+ AlfFile = ->(arg){
+ path = Path(arg)
+ path.file? and path.ext =~ /^\.?alf$/
+ }
+
def connection
requester && requester.connection
end
- def compiler
- @compiler ||= (connection && connection.compiler) || Engine::Compiler.new(nil)
- end
-
- def operands(argv, size = nil)
- operands = [ stdin_operand ] + Array(argv)
- operands = operands[(operands.size - size)..-1] if size
- operands = operands.map{|arg|
- arg = connection.relvar(arg) if arg.is_a?(String)
+ def operand(arg)
+ case arg
+ when AlfFile then operand(Path(arg).read)
+ when String then connection.relvar(arg)
+ when Array then operand(arg.first)
+ else
Algebra::Operand.coerce(arg)
- }
- operands
+ end
end
- def stdin_operand
- requester.stdin_operand rescue $stdin
+ def show_help(who)
+ who = "alf-#{who}" if /explain|metadata|show/ =~ who
+ if p = Path.backfind("doc/man/#{who}.man")
+ exit if system("man #{p}")
+ puts Path.backfind("doc/txt/#{who}.txt").read
+ else
+ puts "Unknown command/operator `#{who}`"
+ end
+ exit
end
end # module Support
end # module Shell
end # module Alf