db2c 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +6 -6
- data/bin/db2c +22 -3
- data/lib/db2c.rb +6 -1
- data/lib/db2c/command.rb +44 -19
- data/lib/db2c/editor.rb +33 -0
- data/lib/db2c/run.rb +21 -7
- data/man/db2c.1 +70 -11
- data/man/db2c.1.html +34 -11
- data/man/db2c.1.ronn +39 -10
- data/rlwrap/filters/RlwrapFilter.pm +816 -0
- data/rlwrap/filters/pipes +74 -0
- data/spec/db2c/command_spec.rb +46 -14
- data/spec/db2c/run_spec.rb +5 -8
- metadata +8 -4
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env perl
|
2
|
+
|
3
|
+
# this is maybe the most practical of the filter examples. Is is also a test for rlwraps signal handling.
|
4
|
+
# At present, a CTRL-C in a pager will also kill rlwrap (bad)
|
5
|
+
|
6
|
+
use lib ($ENV{RLWRAP_FILTERDIR} or ".");
|
7
|
+
use RlwrapFilter;
|
8
|
+
use POSIX qw(:signal_h);
|
9
|
+
use strict;
|
10
|
+
|
11
|
+
# we want any piped pager to receive SIGWINCH.
|
12
|
+
# SIGWINCH is not in POSIX, which means that POSIX.pm doesn't
|
13
|
+
# know about it. We use 'kill -l' to find it
|
14
|
+
|
15
|
+
my $raw_input;
|
16
|
+
|
17
|
+
my @signals = split /\s+/, `kill -l`; # yuck!
|
18
|
+
for (my $signo = 1; $signals[$signo-1]; $signo++) {
|
19
|
+
if ($signals[$signo-1] eq 'WINCH') {
|
20
|
+
my $sigset_unblock = POSIX::SigSet->new($signo);
|
21
|
+
unless (defined sigprocmask(SIG_UNBLOCK, $sigset_unblock)) {
|
22
|
+
die "Could not unblock signals: $!\n";
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
my $filter = new RlwrapFilter;
|
28
|
+
my $name = $filter -> name;
|
29
|
+
|
30
|
+
$filter -> help_text("Usage: rlwrap -z $name <command>\n".
|
31
|
+
"Allow piping of <command> output through pagers or other shell commands\n" .
|
32
|
+
"When input of the form \"| shell pipeline\" is seen, <command>'s following output is sent through the pipeline\n");
|
33
|
+
|
34
|
+
my $pipeline;
|
35
|
+
my $prompt;
|
36
|
+
my $out_chunkno = 0;
|
37
|
+
my $wait_text = "wait ...";
|
38
|
+
|
39
|
+
$filter -> prompts_are_never_empty(1);
|
40
|
+
$filter -> input_handler(\&input);
|
41
|
+
$filter -> output_handler(\&output);
|
42
|
+
$filter -> prompt_handler(\&prompt);
|
43
|
+
$filter -> echo_handler(sub {$raw_input});
|
44
|
+
|
45
|
+
$filter -> run;
|
46
|
+
|
47
|
+
sub input {
|
48
|
+
my $input;
|
49
|
+
$raw_input = $_;
|
50
|
+
($input, undef, $pipeline) = /([^|]*)(\|([^|]+.*))?/;
|
51
|
+
if ($pipeline eq '') {
|
52
|
+
$input = $raw_input
|
53
|
+
}
|
54
|
+
return $input;
|
55
|
+
}
|
56
|
+
|
57
|
+
sub output {
|
58
|
+
return ($pipeline ? ($out_chunkno++ == 0 ? $wait_text : "") : $_); # replace first chunk by $wait_text
|
59
|
+
}
|
60
|
+
|
61
|
+
sub prompt {
|
62
|
+
my ($prompt) = @_;
|
63
|
+
$out_chunkno = 0;
|
64
|
+
if ($pipeline) {
|
65
|
+
$filter -> send_output_oob ("\x08" x length($wait_text). "\n"); # erase $wait_text and go to new line
|
66
|
+
local $SIG{PIPE} = 'IGNORE'; # we don't want to die if the pipeline quits
|
67
|
+
open PIPELINE, "| $pipeline";
|
68
|
+
print PIPELINE $filter->cumulative_output;;
|
69
|
+
close PIPELINE; # this waits until pipeline has finished
|
70
|
+
undef $pipeline;
|
71
|
+
$filter ->send_output_oob("\n"); # start prompt on new line
|
72
|
+
}
|
73
|
+
return $prompt;
|
74
|
+
}
|
data/spec/db2c/command_spec.rb
CHANGED
@@ -1,30 +1,62 @@
|
|
1
1
|
require 'db2c'
|
2
2
|
|
3
3
|
describe Db2c::Command do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Db2c::Command.new('use somedb').to_s.should == 'connect to somedb'
|
10
|
-
end
|
11
|
-
it 'supports describe tablei_name' do
|
12
|
-
Db2c::Command.new('describe schema.table').to_s.should == 'describe table schema.table'
|
13
|
-
end
|
14
|
-
it 'supports \d tale_name' do
|
15
|
-
Db2c::Command.new('\d schema.table').to_s.should == 'describe table schema.table'
|
4
|
+
|
5
|
+
include Db2c::CONSTANTS
|
6
|
+
|
7
|
+
def command_check(command, translation)
|
8
|
+
Db2c::Command.new(command).to_s.should == translation
|
16
9
|
end
|
10
|
+
|
17
11
|
it 'supports \q' do
|
18
12
|
Db2c::Command.new('\q').should be_quit
|
19
13
|
Db2c::Command.new('\quit').should be_quit
|
20
14
|
end
|
21
15
|
it 'supports history commands' do
|
22
|
-
Db2c::Command.new('history').should be_history
|
23
16
|
Db2c::Command.new('\hist').should be_history
|
24
17
|
end
|
25
18
|
it 'supports help command' do
|
26
|
-
Db2c::Command.new('help').should be_help
|
27
19
|
Db2c::Command.new('\help').should be_help
|
28
20
|
Db2c::Command.new('\h').should be_help
|
29
21
|
end
|
22
|
+
it 'strips db2 if any' do
|
23
|
+
command_check('db2 do something', 'do something')
|
24
|
+
Db2c::Command.new('db2 do something').should be_valid
|
25
|
+
end
|
26
|
+
it 'supports use *' do
|
27
|
+
command_check 'use somedb', 'connect to somedb'
|
28
|
+
end
|
29
|
+
it 'supports describe tablei_name' do
|
30
|
+
command_check 'describe schema.table', 'describe table schema.table'
|
31
|
+
end
|
32
|
+
it 'supports \d tale_name' do
|
33
|
+
command_check '\d schema.table', 'describe table schema.table'
|
34
|
+
end
|
35
|
+
it 'supports \l' do
|
36
|
+
command_check '\l', 'list database directory'
|
37
|
+
end
|
38
|
+
it 'supports \lt' do
|
39
|
+
command_check '\lt', 'list tables'
|
40
|
+
end
|
41
|
+
it 'supports \lt all' do
|
42
|
+
command_check '\lt all', 'list tables for all'
|
43
|
+
end
|
44
|
+
it 'supports \lt schema' do
|
45
|
+
command_check '\lt hr', 'list tables for schema hr'
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "\d[a|s|t|v]" do
|
49
|
+
it "returns a list of tables for all schemas without any arguments" do
|
50
|
+
command_check '\dt', "#{DTSELECT} where type = 'T' #{DTORDER}"
|
51
|
+
end
|
52
|
+
it "returns a list of views for all schemas without any arguments" do
|
53
|
+
command_check '\dv', "#{DTSELECT} where type = 'V' #{DTORDER}"
|
54
|
+
end
|
55
|
+
it "returns a list of tables for a specific schema" do
|
56
|
+
command_check '\dt hr', "#{DTSELECT} where type = 'T' and tabschema = 'HR' #{DTORDER}"
|
57
|
+
end
|
58
|
+
it "returns a list of aliases for a specific schema" do
|
59
|
+
command_check '\da hr', "#{DTSELECT} where type = 'A' and tabschema = 'HR' #{DTORDER}"
|
60
|
+
end
|
61
|
+
end
|
30
62
|
end
|
data/spec/db2c/run_spec.rb
CHANGED
@@ -9,24 +9,21 @@ describe Db2c::Run do
|
|
9
9
|
Db2c::Run.new("").should_not be_version
|
10
10
|
Db2c::Run.new("").should_not be_debug
|
11
11
|
Db2c::Run.new("").should_not be_help
|
12
|
-
Db2c::Run.new("").
|
12
|
+
Db2c::Run.new("").should_not be_nowrap
|
13
|
+
Db2c::Run.new("").should_not be_multiline
|
13
14
|
|
14
15
|
Db2c::Run.new("-v").should be_version
|
15
16
|
Db2c::Run.new("-d").should be_debug
|
16
17
|
Db2c::Run.new("-h").should be_help
|
17
|
-
Db2c::Run.new("--now").
|
18
|
+
Db2c::Run.new("--now").should be_nowrap
|
19
|
+
Db2c::Run.new("-t").should be_multiline
|
18
20
|
|
19
21
|
Db2c::Run.new("version").should be_version
|
20
22
|
Db2c::Run.new("debug").should be_debug
|
21
23
|
Db2c::Run.new("help").should be_help
|
22
|
-
Db2c::Run.new("--no-rlwrap").
|
24
|
+
Db2c::Run.new("--no-rlwrap").should be_nowrap
|
23
25
|
|
24
26
|
end
|
25
|
-
it "sets command debug flag" do
|
26
|
-
Db2c::Command.should_not be_debug
|
27
|
-
Db2c::Run.new("debug")
|
28
|
-
Db2c::Command.should be_debug
|
29
|
-
end
|
30
27
|
it "outputs version" do
|
31
28
|
Db2c::Run.any_instance.should_receive(:die).with("version #{Db2c::VERSION}")
|
32
29
|
Db2c::Run.new("--version")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db2c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &11592580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11592580
|
25
25
|
description: a db2 console with with history and autocomplete support, and few other
|
26
26
|
goodies
|
27
27
|
email: samer@on-siteNOSPAM.com
|
@@ -40,10 +40,13 @@ files:
|
|
40
40
|
- lib/autocomplete
|
41
41
|
- lib/db2c.rb
|
42
42
|
- lib/db2c/command.rb
|
43
|
+
- lib/db2c/editor.rb
|
43
44
|
- lib/db2c/run.rb
|
44
45
|
- man/db2c.1
|
45
46
|
- man/db2c.1.html
|
46
47
|
- man/db2c.1.ronn
|
48
|
+
- rlwrap/filters/RlwrapFilter.pm
|
49
|
+
- rlwrap/filters/pipes
|
47
50
|
- spec/db2c/command_spec.rb
|
48
51
|
- spec/db2c/run_spec.rb
|
49
52
|
homepage: http://github.com/on-site/db2c
|
@@ -71,3 +74,4 @@ signing_key:
|
|
71
74
|
specification_version: 3
|
72
75
|
summary: a smarter db2 console
|
73
76
|
test_files: []
|
77
|
+
has_rdoc:
|