alf-shell 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +35 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +13 -0
- data/README.md +11 -0
- data/Rakefile +11 -0
- data/bin/alf +17 -0
- data/lib/alf-shell.rb +1 -0
- data/lib/alf/shell.rb +48 -0
- data/lib/alf/shell/command.rb +21 -0
- data/lib/alf/shell/command/exec.rb +16 -0
- data/lib/alf/shell/command/help.rb +30 -0
- data/lib/alf/shell/command/main.rb +175 -0
- data/lib/alf/shell/command/show.rb +49 -0
- data/lib/alf/shell/doc_manager.rb +83 -0
- data/lib/alf/shell/ext/signature.rb +45 -0
- data/lib/alf/shell/from_argv.rb +78 -0
- data/lib/alf/shell/loader.rb +2 -0
- data/lib/alf/shell/operator.rb +63 -0
- data/lib/alf/shell/support.rb +28 -0
- data/lib/alf/shell/version.rb +16 -0
- data/spec/integration/__database__/group.alf +3 -0
- data/spec/integration/__database__/parts.rash +6 -0
- data/spec/integration/__database__/suppliers.rash +5 -0
- data/spec/integration/__database__/suppliers_csv.csv +6 -0
- data/spec/integration/__database__/supplies.rash +12 -0
- data/spec/integration/alf/alf.db +0 -0
- data/spec/integration/alf/alf_db.cmd +1 -0
- data/spec/integration/alf/alf_db.stdout +5 -0
- data/spec/integration/alf/alf_e.cmd +1 -0
- data/spec/integration/alf/alf_e.stdout +4 -0
- data/spec/integration/alf/alf_help.cmd +1 -0
- data/spec/integration/alf/alf_help.stdout +72 -0
- data/spec/integration/alf/alf_json.cmd +1 -0
- data/spec/integration/alf/alf_json.stdout +1 -0
- data/spec/integration/alf/alf_r.cmd +1 -0
- data/spec/integration/alf/alf_r.stdout +5 -0
- data/spec/integration/alf/alf_version.cmd +1 -0
- data/spec/integration/alf/alf_version.stdout +2 -0
- data/spec/integration/alf/alf_yaml.cmd +1 -0
- data/spec/integration/alf/alf_yaml.stdout +22 -0
- data/spec/integration/alf/rel.rash +1 -0
- data/spec/integration/autonum/autonum_0.cmd +1 -0
- data/spec/integration/autonum/autonum_0.stdout +9 -0
- data/spec/integration/autonum/autonum_1.cmd +1 -0
- data/spec/integration/autonum/autonum_1.stdout +9 -0
- data/spec/integration/clip/clip_0.cmd +1 -0
- data/spec/integration/clip/clip_0.stdout +9 -0
- data/spec/integration/clip/clip_1.cmd +1 -0
- data/spec/integration/clip/clip_1.stdout +9 -0
- data/spec/integration/coerce/coerce_1.cmd +1 -0
- data/spec/integration/coerce/coerce_1.stdout +5 -0
- data/spec/integration/compact/compact_0.cmd +1 -0
- data/spec/integration/compact/compact_0.stdout +9 -0
- data/spec/integration/defaults/defaults_0.cmd +1 -0
- data/spec/integration/defaults/defaults_0.stdout +9 -0
- data/spec/integration/defaults/defaults_1.cmd +1 -0
- data/spec/integration/defaults/defaults_1.stdout +9 -0
- data/spec/integration/defaults/defaults_2.cmd +1 -0
- data/spec/integration/defaults/defaults_2.stdout +9 -0
- data/spec/integration/extend/extend_0.cmd +1 -0
- data/spec/integration/extend/extend_0.stdout +16 -0
- data/spec/integration/generator/generator_1.cmd +1 -0
- data/spec/integration/generator/generator_1.stdout +10 -0
- data/spec/integration/generator/generator_2.cmd +1 -0
- data/spec/integration/generator/generator_2.stdout +5 -0
- data/spec/integration/generator/generator_3.cmd +1 -0
- data/spec/integration/generator/generator_3.stdout +5 -0
- data/spec/integration/group/group_0.cmd +1 -0
- data/spec/integration/group/group_0.stdout +32 -0
- data/spec/integration/group/group_1.cmd +1 -0
- data/spec/integration/group/group_1.stdout +32 -0
- data/spec/integration/help/help_1.cmd +1 -0
- data/spec/integration/help/help_1.stdout +25 -0
- data/spec/integration/intersect/intersect_0.cmd +1 -0
- data/spec/integration/intersect/intersect_0.stdout +9 -0
- data/spec/integration/join/join_0.cmd +1 -0
- data/spec/integration/join/join_0.stdout +16 -0
- data/spec/integration/matching/matching_0.cmd +1 -0
- data/spec/integration/matching/matching_0.stdout +8 -0
- data/spec/integration/minus/minus_0.cmd +1 -0
- data/spec/integration/minus/minus_0.stdout +4 -0
- data/spec/integration/not-matching/not-matching_0.cmd +1 -0
- data/spec/integration/not-matching/not-matching_0.stdout +5 -0
- data/spec/integration/project/project_0.cmd +1 -0
- data/spec/integration/project/project_0.stdout +9 -0
- data/spec/integration/project/project_1.cmd +1 -0
- data/spec/integration/project/project_1.stdout +9 -0
- data/spec/integration/quota/quota_0.cmd +1 -0
- data/spec/integration/quota/quota_0.stdout +16 -0
- data/spec/integration/rank/rank_1.cmd +1 -0
- data/spec/integration/rank/rank_1.stdout +10 -0
- data/spec/integration/rank/rank_2.cmd +1 -0
- data/spec/integration/rank/rank_2.stdout +10 -0
- data/spec/integration/rank/rank_3.cmd +1 -0
- data/spec/integration/rank/rank_3.stdout +10 -0
- data/spec/integration/rank/rank_4.cmd +1 -0
- data/spec/integration/rank/rank_4.stdout +6 -0
- data/spec/integration/rank/rank_5.cmd +1 -0
- data/spec/integration/rank/rank_5.stdout +6 -0
- data/spec/integration/rename/rename_0.cmd +1 -0
- data/spec/integration/rename/rename_0.stdout +9 -0
- data/spec/integration/restrict/restrict_0.cmd +1 -0
- data/spec/integration/restrict/restrict_0.stdout +6 -0
- data/spec/integration/restrict/restrict_1.cmd +1 -0
- data/spec/integration/restrict/restrict_1.stdout +6 -0
- data/spec/integration/show/show_base.cmd +1 -0
- data/spec/integration/show/show_base.stdout +5 -0
- data/spec/integration/show/show_base_sort_1.cmd +1 -0
- data/spec/integration/show/show_base_sort_1.stdout +9 -0
- data/spec/integration/show/show_base_sort_2.cmd +1 -0
- data/spec/integration/show/show_base_sort_2.stdout +9 -0
- data/spec/integration/show/show_conflictual.cmd +1 -0
- data/spec/integration/show/show_conflictual.stdout +5 -0
- data/spec/integration/show/show_ff.cmd +1 -0
- data/spec/integration/show/show_ff.stdout +10 -0
- data/spec/integration/show/show_rash.cmd +1 -0
- data/spec/integration/show/show_rash.stdout +5 -0
- data/spec/integration/show/show_rash_pretty.cmd +1 -0
- data/spec/integration/show/show_rash_pretty.stdout +30 -0
- data/spec/integration/show/show_yaml.cmd +1 -0
- data/spec/integration/show/show_yaml.stdout +22 -0
- data/spec/integration/sort/sort_0.cmd +1 -0
- data/spec/integration/sort/sort_0.stdout +9 -0
- data/spec/integration/sort/sort_1.cmd +1 -0
- data/spec/integration/sort/sort_1.stdout +9 -0
- data/spec/integration/sort/sort_2.cmd +1 -0
- data/spec/integration/sort/sort_2.stdout +9 -0
- data/spec/integration/sort/sort_3.cmd +1 -0
- data/spec/integration/sort/sort_3.stdout +9 -0
- data/spec/integration/summarize/summarize_0.cmd +1 -0
- data/spec/integration/summarize/summarize_0.stdout +8 -0
- data/spec/integration/test_shell.rb +56 -0
- data/spec/integration/union/union_0.cmd +1 -0
- data/spec/integration/union/union_0.stdout +9 -0
- data/spec/integration/unwrap/unwrap_0.cmd +1 -0
- data/spec/integration/unwrap/unwrap_0.stdout +9 -0
- data/spec/integration/wrap/wrap_0.cmd +1 -0
- data/spec/integration/wrap/wrap_0.stdout +9 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/test_shell.rb +10 -0
- data/spec/unit/doc_manager/dynamic.md +1 -0
- data/spec/unit/doc_manager/example.md +1 -0
- data/spec/unit/doc_manager/example_1.txt +11 -0
- data/spec/unit/doc_manager/static.md +1 -0
- data/spec/unit/doc_manager/test_call.rb +43 -0
- data/spec/unit/ext/signature/test_argv2args.rb +82 -0
- data/spec/unit/ext/signature/test_to_shell.rb +103 -0
- data/spec/unit/from_argv/test_to_attr_list.rb +30 -0
- data/spec/unit/from_argv/test_to_attr_name.rb +27 -0
- data/spec/unit/from_argv/test_to_boolean.rb +32 -0
- data/spec/unit/from_argv/test_to_heading.rb +37 -0
- data/spec/unit/from_argv/test_to_ordering.rb +28 -0
- data/spec/unit/from_argv/test_to_predicate.rb +26 -0
- data/spec/unit/from_argv/test_to_renaming.rb +23 -0
- data/spec/unit/from_argv/test_to_size.rb +32 -0
- data/spec/unit/from_argv/test_to_summarization.rb +19 -0
- data/spec/unit/from_argv/test_to_tuple_computation.rb +18 -0
- data/spec/unit/from_argv/test_to_tuple_expression.rb +38 -0
- data/spec/unit/main/test_class_methods.rb +44 -0
- data/spec/unit/operator/test_autonum.rb +28 -0
- data/spec/unit/operator/test_clip.rb +29 -0
- data/spec/unit/operator/test_coerce.rb +22 -0
- data/spec/unit/operator/test_compact.rb +16 -0
- data/spec/unit/operator/test_defaults.rb +29 -0
- data/spec/unit/operator/test_extend.rb +21 -0
- data/spec/unit/operator/test_generator.rb +37 -0
- data/spec/unit/operator/test_group.rb +32 -0
- data/spec/unit/operator/test_infer_heading.rb +16 -0
- data/spec/unit/operator/test_intersect.rb +18 -0
- data/spec/unit/operator/test_join.rb +18 -0
- data/spec/unit/operator/test_matching.rb +18 -0
- data/spec/unit/operator/test_minus.rb +18 -0
- data/spec/unit/operator/test_not_matching.rb +18 -0
- data/spec/unit/operator/test_project.rb +38 -0
- data/spec/unit/operator/test_quota.rb +23 -0
- data/spec/unit/operator/test_rank.rb +30 -0
- data/spec/unit/operator/test_rename.rb +21 -0
- data/spec/unit/operator/test_restrict.rb +36 -0
- data/spec/unit/operator/test_sort.rb +49 -0
- data/spec/unit/operator/test_summarize.rb +30 -0
- data/spec/unit/operator/test_ungroup.rb +28 -0
- data/spec/unit/operator/test_union.rb +18 -0
- data/spec/unit/operator/test_unwrap.rb +28 -0
- data/spec/unit/operator/test_wrap.rb +30 -0
- data/tasks/gem.rake +8 -0
- data/tasks/test.rake +6 -0
- metadata +317 -0
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
group :runtime do
|
4
|
+
#gem "alf-core", :git => "git://github.com/alf-tool/alf-core.git"
|
5
|
+
#gem "alf-core", :path => "../alf-core"
|
6
|
+
gem "alf-core", "~> 0.13.0"
|
7
|
+
gem "quickl", "~> 0.4.3"
|
8
|
+
end
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem "rake", "~> 10.1"
|
12
|
+
gem "rspec", "~> 2.14"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :extra do
|
16
|
+
gem "highline", "~> 1.6"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
alf-core (0.13.0)
|
5
|
+
domain (~> 1.0)
|
6
|
+
myrrha (~> 3.0)
|
7
|
+
path (~> 1.3)
|
8
|
+
sexpr (~> 0.5.1)
|
9
|
+
diff-lcs (1.2.4)
|
10
|
+
domain (1.0.0)
|
11
|
+
highline (1.6.19)
|
12
|
+
myrrha (3.0.0)
|
13
|
+
domain (~> 1.0)
|
14
|
+
path (1.3.1)
|
15
|
+
quickl (0.4.3)
|
16
|
+
rake (10.1.0)
|
17
|
+
rspec (2.14.1)
|
18
|
+
rspec-core (~> 2.14.0)
|
19
|
+
rspec-expectations (~> 2.14.0)
|
20
|
+
rspec-mocks (~> 2.14.0)
|
21
|
+
rspec-core (2.14.4)
|
22
|
+
rspec-expectations (2.14.0)
|
23
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
24
|
+
rspec-mocks (2.14.1)
|
25
|
+
sexpr (0.5.1)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
alf-core (~> 0.13.0)
|
32
|
+
highline (~> 1.6)
|
33
|
+
quickl (~> 0.4.3)
|
34
|
+
rake (~> 10.1)
|
35
|
+
rspec (~> 2.14)
|
data/LICENCE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# The MIT Licence
|
2
|
+
|
3
|
+
Copyright (c) 2013 - Bernard Lambeau
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Alf::Shell
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/blambeau/alf-shell.png)](http://travis-ci.org/blambeau/alf-shell)
|
4
|
+
[![Dependency Status](https://gemnasium.com/blambeau/alf-shell.png)](https://gemnasium.com/blambeau/alf-shell)
|
5
|
+
|
6
|
+
Bring Alf's relational algebra to the shell
|
7
|
+
|
8
|
+
## Links
|
9
|
+
|
10
|
+
http://github.com/blambeau/alf-shell
|
11
|
+
http://github.com/blambeau/alf
|
data/Rakefile
ADDED
data/bin/alf
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
module AlfLauncher
|
3
|
+
|
4
|
+
def self.load
|
5
|
+
require "alf-shell"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.start(argv)
|
9
|
+
load
|
10
|
+
if ENV["ALF_OPTS"]
|
11
|
+
argv = Quickl.parse_commandline_args(ENV["ALF_OPTS"]) + argv
|
12
|
+
end
|
13
|
+
Alf::Shell::Main.run(argv, __FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
end # module AlfLaucher
|
17
|
+
AlfLauncher.start(ARGV)
|
data/lib/alf-shell.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "alf/shell"
|
data/lib/alf/shell.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative 'shell/version'
|
2
|
+
require_relative 'shell/loader'
|
3
|
+
require_relative 'shell/ext/signature'
|
4
|
+
require_relative 'shell/doc_manager'
|
5
|
+
module Alf
|
6
|
+
module Shell
|
7
|
+
|
8
|
+
# This is the main documentation extractor
|
9
|
+
DOC_EXTRACTOR = DocManager.new
|
10
|
+
|
11
|
+
# Delegator command factory
|
12
|
+
def self.Delegator()
|
13
|
+
Quickl::Delegator(){|builder|
|
14
|
+
builder.doc_extractor = DOC_EXTRACTOR
|
15
|
+
builder.class_module Command::ClassMethods
|
16
|
+
yield(builder) if block_given?
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Command factory
|
21
|
+
def self.Command()
|
22
|
+
Quickl::Command(){|builder|
|
23
|
+
builder.command_parent = Alf::Shell::Main
|
24
|
+
builder.doc_extractor = DOC_EXTRACTOR
|
25
|
+
builder.class_module Command::ClassMethods
|
26
|
+
builder.instance_module Shell::Support
|
27
|
+
yield(builder) if block_given?
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# Operator factory
|
32
|
+
def self.Operator()
|
33
|
+
Quickl::Command(){|builder|
|
34
|
+
builder.command_parent = Alf::Shell::Main
|
35
|
+
builder.doc_extractor = DOC_EXTRACTOR
|
36
|
+
builder.class_module Operator::ClassMethods
|
37
|
+
builder.instance_module Shell::Support
|
38
|
+
builder.instance_module Operator::InstanceMethods
|
39
|
+
yield(builder) if block_given?
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
end # module Shell
|
44
|
+
end # module Alf
|
45
|
+
require_relative 'shell/from_argv'
|
46
|
+
require_relative 'shell/support'
|
47
|
+
require_relative 'shell/command'
|
48
|
+
require_relative 'shell/operator'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Alf
|
2
|
+
module Command
|
3
|
+
module ClassMethods
|
4
|
+
|
5
|
+
# @return true
|
6
|
+
def command?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return false
|
11
|
+
def operator?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
end # module ClassMethods
|
16
|
+
end # module Command
|
17
|
+
end # module Alf
|
18
|
+
require_relative 'command/main'
|
19
|
+
require_relative 'command/exec'
|
20
|
+
require_relative 'command/help'
|
21
|
+
require_relative 'command/show'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Alf
|
2
|
+
module Shell
|
3
|
+
class Help < Shell::Command()
|
4
|
+
|
5
|
+
# Let NoSuchCommandError be passed to higher stage
|
6
|
+
no_react_to Quickl::NoSuchCommand
|
7
|
+
|
8
|
+
options do |opt|
|
9
|
+
@dialect = :shell
|
10
|
+
opt.on('--lispy',
|
11
|
+
'Display operator signatures in lispy DSL') do
|
12
|
+
@dialect = :lispy
|
13
|
+
end
|
14
|
+
opt.on('--shell',
|
15
|
+
'Display operator signatures in shell DSL') do
|
16
|
+
@dialect = :shell
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Command execution
|
21
|
+
def execute(args)
|
22
|
+
sup = Quickl.super_command(self)
|
23
|
+
sub = (args.size != 1) ? sup : Quickl.sub_command!(sup, args.first)
|
24
|
+
doc = sub.documentation(:method => @dialect)
|
25
|
+
puts doc
|
26
|
+
end
|
27
|
+
|
28
|
+
end # class Help
|
29
|
+
end # module Shell
|
30
|
+
end # module Alf
|
@@ -0,0 +1,175 @@
|
|
1
|
+
module Alf
|
2
|
+
module Shell
|
3
|
+
class Main < Shell::Delegator()
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def relational_operators(sort_by_name = true)
|
8
|
+
ops = subcommands.select{|cmd|
|
9
|
+
cmd.operator? and cmd.relational? and !cmd.experimental?
|
10
|
+
}
|
11
|
+
sort_operators(ops, sort_by_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def experimental_operators(sort_by_name = true)
|
15
|
+
ops = subcommands.select{|cmd|
|
16
|
+
cmd.operator? and cmd.relational? and cmd.experimental?
|
17
|
+
}
|
18
|
+
sort_operators(ops, sort_by_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def non_relational_operators(sort_by_name = true)
|
22
|
+
ops = subcommands.select{|cmd|
|
23
|
+
cmd.operator? and !cmd.relational?
|
24
|
+
}
|
25
|
+
sort_operators(ops, sort_by_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
def other_non_relational_commands(sort_by_name = true)
|
29
|
+
ops = subcommands.select{|cmd|
|
30
|
+
cmd.command?
|
31
|
+
}
|
32
|
+
sort_operators(ops, sort_by_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def sort_operators(ops, sort_by_name)
|
38
|
+
sort_by_name ? ops.sort{|op1,op2|
|
39
|
+
op1.command_name.to_s <=> op2.command_name.to_s
|
40
|
+
} : ops
|
41
|
+
end
|
42
|
+
|
43
|
+
end # class << self
|
44
|
+
|
45
|
+
# Connection instance to use to get base relations
|
46
|
+
attr_accessor :database
|
47
|
+
|
48
|
+
# The reader to use when stdin is used as operand
|
49
|
+
attr_accessor :stdin_operand
|
50
|
+
|
51
|
+
# Output renderer
|
52
|
+
attr_accessor :renderer_class
|
53
|
+
|
54
|
+
# Rendering options
|
55
|
+
attr_reader :rendering_options
|
56
|
+
|
57
|
+
# Creates a command instance
|
58
|
+
def initialize(db = Alf.connect(Path.pwd))
|
59
|
+
@database = db
|
60
|
+
@rendering_options = {}
|
61
|
+
end
|
62
|
+
|
63
|
+
# Install options
|
64
|
+
options do |opt|
|
65
|
+
@execute = false
|
66
|
+
opt.on("-e", "--execute", "Execute one line of script (Lispy API)") do
|
67
|
+
@execute = true
|
68
|
+
end
|
69
|
+
|
70
|
+
@renderer_class = nil
|
71
|
+
Renderer.each do |name,descr,clazz|
|
72
|
+
opt.on("--#{name}", "Render output #{descr}"){
|
73
|
+
@renderer_class = clazz
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
opt.on('--examples', "Use the example database for database") do
|
78
|
+
@database = Alf.examples
|
79
|
+
end
|
80
|
+
|
81
|
+
opt.on('--db=DB',
|
82
|
+
"Set the database to use") do |value|
|
83
|
+
@database = Alf.connect(value)
|
84
|
+
end
|
85
|
+
|
86
|
+
@input_reader = :rash
|
87
|
+
readers = Reader.all.map{|r| r.first}
|
88
|
+
opt.on('--input-reader=READER', readers,
|
89
|
+
"Specify the kind of reader when reading on $stdin "\
|
90
|
+
"(#{readers.join(',')})") do |value|
|
91
|
+
@input_reader = value.to_sym
|
92
|
+
end
|
93
|
+
|
94
|
+
opt.on("-Idirectory",
|
95
|
+
"Specify $LOAD_PATH directory (may be used more than once)") do |val|
|
96
|
+
$LOAD_PATH.unshift val
|
97
|
+
end
|
98
|
+
|
99
|
+
opt.on('-rlibrary',
|
100
|
+
"Require the library, before executing alf") do |value|
|
101
|
+
require(value)
|
102
|
+
end
|
103
|
+
|
104
|
+
opt.on("--[no-]pretty",
|
105
|
+
"Enable/disable pretty print best effort") do |val|
|
106
|
+
self.pretty = val
|
107
|
+
end
|
108
|
+
|
109
|
+
opt.on_tail('-h', "--help", "Show help") do
|
110
|
+
raise Quickl::Help
|
111
|
+
end
|
112
|
+
|
113
|
+
opt.on_tail('-v', "--version", "Show version") do
|
114
|
+
raise Quickl::Exit, "alf #{Alf::Core::VERSION}"\
|
115
|
+
" (c) 2011-2013, Bernard Lambeau"
|
116
|
+
end
|
117
|
+
end # Alf's options
|
118
|
+
|
119
|
+
def stdin_operand
|
120
|
+
@stdin_operand || Reader.send(@input_reader, $stdin)
|
121
|
+
end
|
122
|
+
|
123
|
+
def execute(argv)
|
124
|
+
# special case where a .alf file is provided
|
125
|
+
if argv.empty? or (argv.size == 1 && Path(argv.first).exist?)
|
126
|
+
argv.unshift("exec")
|
127
|
+
end
|
128
|
+
|
129
|
+
# compile the operator, render and returns it
|
130
|
+
compile(argv){ super }.tap do |op|
|
131
|
+
render(op.to_cog) if op && requester
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def pretty=(val)
|
136
|
+
@rendering_options[:pretty] = val
|
137
|
+
if val && (hl = highline)
|
138
|
+
@rendering_options[:trim_at] = hl.output_cols
|
139
|
+
@rendering_options[:page_at] = hl.output_rows
|
140
|
+
end
|
141
|
+
val
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
def compile(argv)
|
147
|
+
if @execute
|
148
|
+
database.query(argv.first)
|
149
|
+
else
|
150
|
+
op = yield
|
151
|
+
op = op.bind(database) if op
|
152
|
+
op
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def render(operator, out = $stdout)
|
157
|
+
renderer_class = self.renderer_class || default_renderer_class
|
158
|
+
renderer = renderer_class.new(operator, rendering_options)
|
159
|
+
renderer.execute(out)
|
160
|
+
end
|
161
|
+
|
162
|
+
def highline
|
163
|
+
require 'highline'
|
164
|
+
HighLine.new($stdin, $stdout)
|
165
|
+
rescue LoadError => ex
|
166
|
+
nil
|
167
|
+
end
|
168
|
+
|
169
|
+
def default_renderer_class
|
170
|
+
$stdout.tty? ? Renderer::Text : Renderer::Rash
|
171
|
+
end
|
172
|
+
|
173
|
+
end # class Main
|
174
|
+
end # module Shell
|
175
|
+
end # module Alf
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Alf
|
2
|
+
module Shell
|
3
|
+
class Show < Shell::Command()
|
4
|
+
|
5
|
+
options do |opt|
|
6
|
+
@renderer_class = nil
|
7
|
+
Renderer.each do |name,descr,clazz|
|
8
|
+
opt.on("--#{name}", "Render output #{descr}"){
|
9
|
+
@renderer_class = clazz
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
@pretty = nil
|
14
|
+
opt.on("--[no-]pretty",
|
15
|
+
"Enable/disable pretty print best effort") do |val|
|
16
|
+
@pretty = val
|
17
|
+
end
|
18
|
+
|
19
|
+
@ff = nil
|
20
|
+
opt.on("--ff=FORMAT",
|
21
|
+
"Specify the floating point format") do |val|
|
22
|
+
@ff = val
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def run(argv, requester)
|
27
|
+
# set requester and parse options
|
28
|
+
@requester = requester
|
29
|
+
argv = parse_options(argv, :split)
|
30
|
+
|
31
|
+
# Set options on the requester
|
32
|
+
requester.pretty = @pretty unless @pretty.nil?
|
33
|
+
requester.rendering_options[:float_format] = @ff unless @ff.nil?
|
34
|
+
requester.renderer_class = (@renderer_class || requester.renderer_class)
|
35
|
+
|
36
|
+
compile(argv)
|
37
|
+
end
|
38
|
+
|
39
|
+
def compile(argv)
|
40
|
+
operand = operands(argv.shift, 1).last
|
41
|
+
unless argv.empty?
|
42
|
+
operand = Algebra::Sort.new([operand], Shell.from_argv(argv.first, Ordering))
|
43
|
+
end
|
44
|
+
operand
|
45
|
+
end
|
46
|
+
|
47
|
+
end # class Show
|
48
|
+
end # module Shell
|
49
|
+
end # module Alf
|