jugyo-chlr 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/README.markdown +62 -0
- data/Rakefile +43 -0
- data/bin/chlr +5 -0
- data/lib/chlr.rb +8 -0
- data/lib/chlr/client.rb +42 -0
- data/lib/chlr/command.rb +29 -0
- data/lib/chlr/log.rb +6 -0
- data/lib/chlr/standard_commands.rb +43 -0
- data/lib/chlr/version.rb +3 -0
- data/scripts/console +11 -0
- data/spec/client_spec.rb +47 -0
- data/spec/command_spec.rb +31 -0
- data/spec/spec_helper.rb +2 -0
- metadata +84 -0
data/History.txt
ADDED
File without changes
|
data/README.markdown
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
Chlr
|
2
|
+
========
|
3
|
+
|
4
|
+
[http://github.com/jugyo/chlr/tree/master](http://github.com/jugyo/chlr/tree/master)
|
5
|
+
|
6
|
+
Description
|
7
|
+
--------
|
8
|
+
|
9
|
+
Chlr is a Terminal based ChangeLoging tool.
|
10
|
+
|
11
|
+
Install
|
12
|
+
--------
|
13
|
+
|
14
|
+
gem source -a http://gems.github.com
|
15
|
+
sudo gem install chlr
|
16
|
+
|
17
|
+
Synopsis
|
18
|
+
--------
|
19
|
+
|
20
|
+
### Start:
|
21
|
+
|
22
|
+
% chlr
|
23
|
+
|
24
|
+
Chlr uses '~/chlr.db' as a default database.
|
25
|
+
The database is a file of sqlite3.
|
26
|
+
|
27
|
+
### To specify a database file:
|
28
|
+
|
29
|
+
% chlr ~/memo.db
|
30
|
+
|
31
|
+
Requirements
|
32
|
+
--------
|
33
|
+
|
34
|
+
* sqlite3
|
35
|
+
* Sequel
|
36
|
+
* TermColor
|
37
|
+
|
38
|
+
License
|
39
|
+
--------
|
40
|
+
|
41
|
+
(The MIT License)
|
42
|
+
|
43
|
+
Copyright (c) 2008-2009 jugyo
|
44
|
+
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
+
a copy of this software and associated documentation files (the
|
47
|
+
'Software'), to deal in the Software without restriction, including
|
48
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
+
permit persons to whom the Software is furnished to do so, subject to
|
51
|
+
the following conditions:
|
52
|
+
|
53
|
+
The above copyright notice and this permission notice shall be
|
54
|
+
included in all copies or substantial portions of the Software.
|
55
|
+
|
56
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + '/lib/'
|
2
|
+
require 'chlr'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
desc 'run all specs'
|
6
|
+
Spec::Rake::SpecTask.new do |t|
|
7
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
8
|
+
t.spec_opts = ['-c']
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Generate gemspec'
|
12
|
+
task :gemspec do |t|
|
13
|
+
open('chlr.gemspec', "wb" ) do |file|
|
14
|
+
file << <<-EOS
|
15
|
+
Gem::Specification.new do |s|
|
16
|
+
s.name = 'chlr'
|
17
|
+
s.version = '#{Chlr::VERSION}'
|
18
|
+
s.summary = "Chlr is a Terminal based ChangeLoging tool."
|
19
|
+
s.description = "Chlr is a Terminal based ChangeLoging tool."
|
20
|
+
s.files = %w( #{Dir['lib/**/*.rb'].join(' ')}
|
21
|
+
#{Dir['spec/**/*.rb'].join(' ')}
|
22
|
+
#{Dir['scripts/*'].join(' ')}
|
23
|
+
README.markdown
|
24
|
+
History.txt
|
25
|
+
Rakefile )
|
26
|
+
s.executables = ["chlr"]
|
27
|
+
s.add_dependency("sequel", ">= 2.12.0")
|
28
|
+
s.add_dependency("termcolor", ">= 1.0.0")
|
29
|
+
s.author = 'jugyo'
|
30
|
+
s.email = 'jugyo.org@gmail.com'
|
31
|
+
s.homepage = 'http://github.com/jugyo/chlr'
|
32
|
+
s.rubyforge_project = 'chlr'
|
33
|
+
s.has_rdoc = false
|
34
|
+
end
|
35
|
+
EOS
|
36
|
+
end
|
37
|
+
puts "Generate gemspec"
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Generate gem'
|
41
|
+
task :gem => :gemspec do |t|
|
42
|
+
system 'gem', 'build', 'chlr.gemspec'
|
43
|
+
end
|
data/bin/chlr
ADDED
data/lib/chlr.rb
ADDED
data/lib/chlr/client.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Chlgr
|
4
|
+
class Client
|
5
|
+
def self.setup(path)
|
6
|
+
@@db = Sequel.sqlite(File.expand_path(path))
|
7
|
+
unless @@db.table_exists?(:logs)
|
8
|
+
@@db.create_table :logs do
|
9
|
+
primary_key :id
|
10
|
+
Text :text
|
11
|
+
DateTime :created_at
|
12
|
+
end
|
13
|
+
end
|
14
|
+
require 'chlr/log'
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.db
|
19
|
+
@@db
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.start
|
23
|
+
self.new.start
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
|
28
|
+
Readline.completion_proc = lambda do |text|
|
29
|
+
Command.search(text)
|
30
|
+
end
|
31
|
+
|
32
|
+
while buf = Readline.readline('> ', true)
|
33
|
+
call_command(buf)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def call_command(text)
|
38
|
+
cmd, *args = text.split(/\s/)
|
39
|
+
Command.get(cmd).call(*args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/chlr/command.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Chlgr
|
4
|
+
class Command
|
5
|
+
@@commands = {}
|
6
|
+
class << self
|
7
|
+
def add(name, &block)
|
8
|
+
@@commands[name.to_sym] = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(name)
|
12
|
+
@@commands[name.to_sym]
|
13
|
+
end
|
14
|
+
|
15
|
+
def search(text)
|
16
|
+
return [] if text.nil? || text.empty?
|
17
|
+
@@commands.keys.map{|i|i.to_s}.grep(/^#{Regexp.quote(text)}/).map{|i|i.to_sym}
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_all
|
21
|
+
@@commands
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear
|
25
|
+
@@commands.clear
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/chlr/log.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
module Chlgr
|
6
|
+
class Command
|
7
|
+
add :list do |*args|
|
8
|
+
output Log.reverse_order(:created_at)
|
9
|
+
end
|
10
|
+
|
11
|
+
add :add do
|
12
|
+
file = Tempfile.new('chlr')
|
13
|
+
system ENV['EDITOR'] || 'vi', file.path
|
14
|
+
text = open(file.path).read
|
15
|
+
Log << {:text => text, :created_at => Time.now}
|
16
|
+
end
|
17
|
+
|
18
|
+
add :search do |*args|
|
19
|
+
query = args.first
|
20
|
+
output Log.filter(:text.like("%#{query}%")) do |text|
|
21
|
+
text = TermColor.escape(text)
|
22
|
+
TermColor.parse(text.gsub(query, '<on_yellow><black>\0</black></on_yellow>'))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
add :delete do |*args|
|
27
|
+
output Log.filter(:text.like("%#{args.first}%"))
|
28
|
+
end
|
29
|
+
|
30
|
+
add :exit do
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.output(dataset, &block)
|
35
|
+
puts dataset.limit(10).reverse.map {|log|
|
36
|
+
time = log.created_at.strftime("%Y-%m-%d %X")
|
37
|
+
header = TermColor.parse("<90>-- [##{log.id}] #{time} --</90>")
|
38
|
+
text = block ? block.call(log.text) : log.text
|
39
|
+
"#{header}\n#{text}"
|
40
|
+
}.join("\n")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/chlr/version.rb
ADDED
data/scripts/console
ADDED
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
module Chlgr
|
6
|
+
describe Client do
|
7
|
+
DB_PATH = '/tmp/chlr.db'
|
8
|
+
before do
|
9
|
+
File.delete(DB_PATH) if File.exists?(DB_PATH)
|
10
|
+
end
|
11
|
+
describe 'initialize db' do
|
12
|
+
before do
|
13
|
+
@client = Client.setup(DB_PATH).new
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should create db file' do
|
17
|
+
File.exists?(DB_PATH).should == true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'chould create logs table' do
|
21
|
+
Client.db.table_exists?(:logs).should == true
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'add commands' do
|
25
|
+
before do
|
26
|
+
Command.clear
|
27
|
+
Command.add(:foo) {|arg|}
|
28
|
+
Command.add(:bar) {|a,b|}
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should call command "foo"' do
|
32
|
+
command = Command.get('foo')
|
33
|
+
Command.should_receive(:get).with('foo').and_return(command)
|
34
|
+
command.should_receive(:call).with('test')
|
35
|
+
@client.call_command('foo test')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should call command "bar"' do
|
39
|
+
command = Command.get('bar')
|
40
|
+
Command.should_receive(:get).with('bar').and_return(command)
|
41
|
+
command.should_receive(:call).with('a', 'b')
|
42
|
+
@client.call_command('bar a b')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
module Chlgr
|
6
|
+
describe Command do
|
7
|
+
it 'adds command' do
|
8
|
+
Command.clear
|
9
|
+
Command.add(:foo){}
|
10
|
+
Command.get('foo').class.should == Proc
|
11
|
+
Command.get('bar').should be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'add 3 commands' do
|
15
|
+
before(:each) do
|
16
|
+
Command.clear
|
17
|
+
Command.add(:foo1){}
|
18
|
+
Command.add(:foo2){}
|
19
|
+
Command.add(:bar){}
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'search command' do
|
23
|
+
commands = Command.search('foo')
|
24
|
+
commands.size.should == 2
|
25
|
+
commands.include?(:foo1).should == true
|
26
|
+
commands.include?(:foo2).should == true
|
27
|
+
commands.include?(:bar).should == false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jugyo-chlr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jugyo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sequel
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.12.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: termcolor
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
version:
|
35
|
+
description: Chlr is a Terminal based ChangeLoging tool.
|
36
|
+
email: jugyo.org@gmail.com
|
37
|
+
executables:
|
38
|
+
- chlr
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/chlr/client.rb
|
45
|
+
- lib/chlr/command.rb
|
46
|
+
- lib/chlr/log.rb
|
47
|
+
- lib/chlr/standard_commands.rb
|
48
|
+
- lib/chlr/version.rb
|
49
|
+
- lib/chlr.rb
|
50
|
+
- spec/client_spec.rb
|
51
|
+
- spec/command_spec.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
- scripts/console
|
54
|
+
- README.markdown
|
55
|
+
- History.txt
|
56
|
+
- Rakefile
|
57
|
+
has_rdoc: false
|
58
|
+
homepage: http://github.com/jugyo/chlr
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project: chlr
|
79
|
+
rubygems_version: 1.2.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 2
|
82
|
+
summary: Chlr is a Terminal based ChangeLoging tool.
|
83
|
+
test_files: []
|
84
|
+
|