vimget 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,6 @@
1
+ = VimGet
2
+ == A vim script management tool
3
+
4
+
5
+
6
+ Author:: Eddy Xu (mailto:eddyxu@gmail.com)
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # @file command.rb
3
+ # =Base class for command object.
4
+ # Parse options and invoke inherited execute function
4
5
  #
5
- # @breif parser and manager commands
6
+ # Author:: Eddy Xu (mailto:eddyxu@gmail.com)
7
+ # License:: Distributed under BSD License
8
+ # Copyright:: Copyright 2008 (c) Quarkare.com (http://www.quarkware.com)
6
9
  #
7
- # @author Eddy Xu <eddyxu@gmail.com>
8
- #
9
- # Copyright 2008 by xulei.org
10
- #
11
- # $Id: command.rb 5 2008-04-11 18:33:39Z eddyxu $
10
+ # $Id: command.rb 8 2008-04-12 12:47:35Z eddyxu $
12
11
  #
13
12
 
14
13
  require 'optparse'
@@ -16,7 +15,7 @@ require "vimget/configure"
16
15
 
17
16
  module VimGet
18
17
 
19
- # base class for all commands
18
+ # base class for all commands, providing fundamental functions for command
20
19
  class BaseCommand
21
20
  PROGRAM = "vim-get"
22
21
  # the name of command
@@ -25,6 +24,7 @@ module VimGet
25
24
  # the options for this command
26
25
  attr_reader :options
27
26
 
27
+ # divide options into named groups
28
28
  attr_reader :options_group
29
29
 
30
30
  # the default options for the command
@@ -53,6 +53,7 @@ module VimGet
53
53
  puts @parser
54
54
  end
55
55
 
56
+ # return a argument string
56
57
  def arguments
57
58
  ""
58
59
  end
@@ -66,6 +67,7 @@ module VimGet
66
67
  end
67
68
  end
68
69
 
70
+ # interface for all sub class, must implement this function!
69
71
  def execute
70
72
  raise 'Command without define execute function'
71
73
  end
@@ -83,9 +85,9 @@ module VimGet
83
85
  end
84
86
  end
85
87
 
86
- def pop_one_argument
87
- return nil if @rest.empty?
88
- return @rest.shift
88
+ # fetch one argument from argument list
89
+ def fetch_one_argu
90
+ @rest.shift
89
91
  end
90
92
 
91
93
  private
@@ -93,8 +95,12 @@ module VimGet
93
95
  def handle_options(args)
94
96
  @rest = parser.parse(*args)
95
97
  @options[:args] = args
98
+
99
+ # remove the operation name
100
+ @rest.shift if @rest.first == @program_name
96
101
  end
97
102
 
103
+ # singleton entry for OptionParser
98
104
  def parser
99
105
  create_parser if @parser.nil?
100
106
  @parser
@@ -2,25 +2,26 @@
2
2
  #
3
3
  # Command Manager
4
4
  #
5
- # Eddy Xu <eddyxu@gmail.com>
5
+ # Author:: Eddy Xu (mailto:eddyxu@gmail.com)
6
+ # Licence:: Distributed under BSD Licences
7
+ # Copyright:: Copyright (c) 2008 Quarkware.com
6
8
  #
7
- # 2008 (c) Quarkware.com
8
- #
9
- # $Id: command_manager.rb 5 2008-04-11 18:33:39Z eddyxu $
9
+ # $Id: command_manager.rb 8 2008-04-12 12:47:35Z eddyxu $
10
10
 
11
11
  require "vimget/exceptions"
12
12
  require "vimget/configure"
13
13
 
14
14
  module VimGet
15
15
 
16
+ # This class will find property command and invoke it
16
17
  class CommandManager
18
+ # singleton entry
17
19
  def self.instance
18
20
  @command_manager ||= CommandManager.new
19
21
  end
20
22
 
21
- def initialize
22
- end
23
-
23
+ # run the command manager with args
24
+ # * args is a argument array
24
25
  def run(args)
25
26
  process_args(args)
26
27
  rescue StandardError => ex
@@ -31,7 +32,7 @@ module VimGet
31
32
  exit 1
32
33
  end
33
34
 
34
-
35
+ # handle arguments for special command
35
36
  def process_args(args)
36
37
  if ARGV.empty?
37
38
  usage
@@ -52,7 +53,7 @@ module VimGet
52
53
  cmd_obj.invoke(ARGV.dup)
53
54
  end
54
55
 
55
-
56
+ # display general usage
56
57
  def usage
57
58
  puts <<-USAGE
58
59
  vim-get: the vim script management tool
@@ -86,6 +87,7 @@ module VimGet
86
87
  USAGE
87
88
  end
88
89
 
90
+ # display special help informations for command
89
91
  def help(cmd="")
90
92
  if cmd.empty?
91
93
  usage
@@ -99,6 +101,7 @@ module VimGet
99
101
  exit 1
100
102
  end
101
103
 
104
+ # puts version and runtime info
102
105
  def version
103
106
  puts "vim-get: vim script management tool #{VIMGET_VERSION}"
104
107
  puts
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # list command
4
4
  #
5
- # $Id: list_command.rb 5 2008-04-11 18:33:39Z eddyxu $
5
+ # $Id: list_command.rb 7 2008-04-11 22:48:50Z eddyxu $
6
6
 
7
7
  require "vimget/command"
8
8
  require "vimget/db.rb"
@@ -28,22 +28,16 @@ module VimGet
28
28
 
29
29
  if @options[:outdated]
30
30
  puts "List outdated scripts"
31
+ scripts = VimGet.db.outdated_scripts
31
32
  elsif @options[:installed]
32
33
  puts "List installed scripts"
34
+ scripts = VimGet.db.installed_scripts
33
35
  else
34
36
  puts "List scripts"
37
+ scripts = VimGet.db.search
35
38
  end
36
-
37
- scripts = VimGet.db.search()
38
-
39
- # Todo: decouple it to output module
39
+
40
40
  scripts.each do |s|
41
- if @options[:outdated] && !s.outdated?
42
- next
43
- elsif @options[:installed] && !s.installed?
44
- next
45
- end
46
-
47
41
  if @options[:format] == "plain"
48
42
  puts "[#{s.name}]"
49
43
  puts "id: #{s.sid}"
@@ -63,7 +57,7 @@ module VimGet
63
57
  def add_customer_options
64
58
  #add_option(:list, '--xml', 'Display in XML Format') { |v,opts| opts[:format] = "xml" }
65
59
  add_option(:list, '-o', '--outdated', 'List all outdated scripts') {|v,opts| opts[:outdated] = v}
66
- add_option(:list, '-i', '--installed', 'List all installed scripts') {|v, opts| opts[:installed] = v}
60
+ add_option(:list, '-i', '--installed', 'List all installed scripts') {|v,opts| opts[:installed] = v}
67
61
  end
68
62
  end
69
63
 
@@ -8,7 +8,7 @@
8
8
  #
9
9
  # Copyright: 2008 (c) Quarkware.com
10
10
  #
11
- # $Id: upgrade_command.rb 6 2008-04-11 19:01:26Z eddyxu $
11
+ # $Id: upgrade_command.rb 7 2008-04-11 22:48:50Z eddyxu $
12
12
  #
13
13
 
14
14
  require "vimget/command"
@@ -24,7 +24,7 @@ module VimGet
24
24
  end
25
25
 
26
26
  def execute
27
- outdated_scripts = VimGet.db.get_outdated_scripts
27
+ outdated_scripts = VimGet.db.outdated_scripts
28
28
 
29
29
  if outdated_scripts.empty?
30
30
  puts "There is no script outdated."
data/lib/vimget/db.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # manage local script index database
4
4
  #
5
- # $Id: db.rb 5 2008-04-11 18:33:39Z eddyxu $
5
+ # $Id: db.rb 7 2008-04-11 22:48:50Z eddyxu $
6
6
 
7
7
  require "vimget/configure"
8
8
  require "vimget/script"
@@ -27,8 +27,7 @@ module VimGet
27
27
  end
28
28
 
29
29
  def add(script)
30
- file_path = File.join(@db_path, script.name + @@EXT)
31
- file_path = File.expand_path(file_path)
30
+ file_path = db_file(script)
32
31
  File.open(file_path, 'w') do |f|
33
32
  f.truncate(0)
34
33
 
@@ -53,7 +52,7 @@ manifest {
53
52
 
54
53
  def update(script)
55
54
  if script.manifest.empty?
56
- filepath = File.join(@db_path, script.name + @@EXT)
55
+ filepath = db_file(script)
57
56
  s = parse_script(filepath)
58
57
  script.manifest = s.manifest if s
59
58
  end
@@ -62,8 +61,7 @@ manifest {
62
61
  end
63
62
 
64
63
  def remove(script)
65
- file_path = File.join(@db_path, script.name + @@EXT)
66
- file_path = File.expand_path(file_path)
64
+ file_path = db_file(script)
67
65
  File.delete(file_path)
68
66
  end
69
67
 
@@ -75,30 +73,35 @@ manifest {
75
73
  file_list = Dir.glob(glob_pattern)
76
74
 
77
75
  ret = Array.new
78
- closure = ""
76
+
79
77
  file_list.each do |f|
80
- ret << parse_script(f)
78
+ script = parse_script(f)
79
+
80
+ if block_given?
81
+ ret << script if yield(script)
82
+ else
83
+ ret << script
84
+ end
81
85
  end
86
+
82
87
  ret
83
88
  end
84
89
 
85
90
  def find_with_id(sid)
86
- search.each { |s| return s if s.sid == sid }
87
- return nil
91
+ s = search { |script| script.sid == sid }
92
+ s.first
88
93
  end
89
94
 
90
95
  def find(name)
91
- # find a script by using name, if not one finded, return nil
92
- search.each { |s| return s if s.name == name }
93
- return nil
96
+ search(name).first
94
97
  end
95
98
 
96
- def get_outdated_scripts
97
- scripts = search()
98
-
99
- ret_array = Array.new
100
- scripts.each { |s| ret_array << s if s.outdated? }
101
- return ret_array
99
+ def outdated_scripts
100
+ search { |s| s.outdated? }
101
+ end
102
+
103
+ def installed_scripts
104
+ search { |s| !s.installed.empty? }
102
105
  end
103
106
 
104
107
  private
@@ -134,6 +137,10 @@ manifest {
134
137
  s.author = ctn["author"]
135
138
  return s
136
139
  end
140
+
141
+ def db_file(script)
142
+ File.expand_path(File.join(@db_path, script.name + @@EXT))
143
+ end
137
144
  end
138
145
 
139
146
  end
@@ -22,7 +22,8 @@ module VimGet
22
22
  # Manage the installing progress and uninstall/upgrading etc
23
23
  def initialize(opts = {})
24
24
  @options = opts
25
- #@dist_path = VimGet.configure.distfiles_dir
25
+ @dist_path = File.expand_path(VimGet.configure.distfiles_dir)
26
+ FileUtils.mkdir_p(@dist_path) if not File.exist? @dist_path
26
27
  end
27
28
 
28
29
  def install(script)
data/lib/vimget.rb CHANGED
@@ -1,18 +1,22 @@
1
- #!/usr/bin/env ruby -wKU
1
+ #!/usr/bin/env ruby
2
2
  #
3
3
  # Main file for vim-get application
4
4
  #
5
- # Copyright GPLv2
5
+ # Author:: Eddy Xu (mailto:eddyxu@gmail.com)
6
+ # License:: Distributed under BSD License
7
+ # Copyright:: Copyright (c) 2008 Quarkware.com
6
8
  #
7
- # $Id: vimget.rb 5 2008-04-11 18:33:39Z eddyxu $
9
+ # $Id: vimget.rb 8 2008-04-12 12:47:35Z eddyxu $
8
10
 
11
+ require 'fileutils'
9
12
  require "vimget/command_manager"
13
+ require "vimget/configure"
10
14
 
11
- VIMGET_VERSION = "0.1.0"
15
+ VIMGET_VERSION = "0.1.1"
12
16
 
13
17
  module VimGet
14
18
 
15
- # Singleton access point
19
+ # Singleton access point for main application
16
20
  class << self
17
21
  def application
18
22
  @application ||= VimGet::Application.new
@@ -27,11 +31,12 @@ module VimGet
27
31
  # VimGet application class
28
32
  class Application
29
33
  def initialize
30
-
34
+ vimget_path = File.expand_path(VimGet.configure.base_dir)
35
+ FileUtils.mkdir_p vimget_path if not File.exist? vimget_path
31
36
  end
32
37
 
33
38
  def run
34
39
  CommandManager.instance.run(ARGV)
35
40
  end
36
41
  end
37
- end
42
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # test case for command.rb
4
+ #
5
+ # author: Eddy Xu <eddyxu@gmail.com>
6
+ #
7
+ # $Id: tc_command.rb 8 2008-04-12 12:47:35Z eddyxu $
8
+
9
+ require 'test/unit'
10
+ require 'vimget/command'
11
+
12
+ class CommandTest < Test::Unit::TestCase
13
+ def setup
14
+ end
15
+
16
+ def teardown
17
+
18
+ end
19
+
20
+ def test_parse_option
21
+ end
22
+ end
data/test/tc_db.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # test case for db.rb
4
4
  #
5
- # $Id: tc_db.rb 4 2008-04-07 19:16:34Z eddyxu $
5
+ # $Id: tc_db.rb 7 2008-04-11 22:48:50Z eddyxu $
6
6
 
7
7
  require 'test/unit'
8
8
  require "vimget/db"
@@ -12,10 +12,20 @@ require "tmpdir"
12
12
  class TestDB < Test::Unit::TestCase
13
13
  def setup
14
14
  @basedir = Dir.tmpdir
15
+
16
+ @s1 = VimGet::Script.new("123", "test_1", "Eddy Xu", "4.23", "4.23",
17
+ "download?from=somewhere",
18
+ ["plugin/taglist.vim", "doc/taglist.txt"])
19
+
20
+ # outdated one
21
+ @s2 = VimGet::Script.new("321", "test_outdated", "EdX", "3.24", "3.23",
22
+ "download str", [])
23
+
24
+ @db = VimGet::PathDB.new(@basedir)
15
25
  end
16
26
 
17
27
  def teardown
18
- nil
28
+ Dir.glob(db_file("*")) { |filename| File.delete(filename) }
19
29
  end
20
30
 
21
31
  def test_find
@@ -23,23 +33,57 @@ class TestDB < Test::Unit::TestCase
23
33
  end
24
34
 
25
35
  def test_add
26
- s = VimGet::Script.new("123", "test")
36
+ s = VimGet::Script.new(123, "test")
27
37
  s.author = "Eddy Xu"
28
38
  s.installed = "4.23"
29
39
  s.version = "5.23"
30
40
  s.download = "download?from=somewhere"
31
41
  s.manifest = ["plugin/taglist.vim", "doc/taglist.txt"]
32
42
 
33
- db = VimGet::PathDB.new(@basedir)
34
-
35
- db.add(s)
43
+ @db.add(s)
36
44
 
37
45
  expected_filepath = File.join(@basedir, "db", "test.manifest")
38
46
  assert(File.exist?(expected_filepath), "Failed to create script manifest.")
39
47
 
48
+ s1 = @db.find("test")
49
+ assert_not_nil(s1, "VimGet::db find nothing")
50
+ assert_equal(s.sid, s1.sid)
51
+ assert_equal("4.23", s1.installed, "Wrong installed version")
52
+ assert_equal(s.manifest, s1.manifest)
53
+ assert_equal(s.outdated?, s1.outdated?)
54
+
40
55
  end
41
56
 
42
57
  def test_update
43
- s = VimGet::Script.new("123", "test")
58
+ db = db_file(@s1.name)
59
+ assert_equal(false, File.exist?(db))
60
+ @db.add(@s1)
61
+ assert_equal(true, File.exist?(db), "Failed to create script manifest.")
62
+ @s1.author = "Meg Ryan"
63
+ @s1.installed = "23.2"
64
+ @s1.version = "2.32"
65
+ @s1.manifest << "ftplugin/taglist.a"
66
+
67
+ @db.update(@s1)
68
+
69
+ s = @db.find(@s1.name)
70
+ assert_equal("Meg Ryan", s.author)
71
+ assert_equal(@s1.manifest, s.manifest)
72
+
73
+ # Todo: is it right to ignore the manifest empty?
74
+ empty_s = VimGet::Script.new(@s1.sid, @s1.name)
75
+ empty_s.author, empty_s.installed, empty_s.version = @s1.author, @s1.installed, @s1.version
76
+ empty_s.manifest = []
77
+
78
+ @db.update(empty_s)
79
+
80
+ s = @db.find(empty_s.name)
81
+ assert_equal(@s1.manifest, s.manifest)
82
+ end
83
+
84
+ private
85
+
86
+ def db_file(name)
87
+ File.join(@basedir, "db", name + ".manifest")
44
88
  end
45
89
  end
data/test/ts_vimget.rb CHANGED
@@ -2,10 +2,11 @@
2
2
  #
3
3
  # Test suite for vimget
4
4
  #
5
- # $Id: ts_vimget.rb 5 2008-04-11 18:33:39Z eddyxu $
5
+ # $Id: ts_vimget.rb 8 2008-04-12 12:47:35Z eddyxu $
6
6
 
7
7
  $: << "#{File.dirname(__FILE__)}/../lib"
8
8
 
9
9
  require 'tc_db'
10
+ require 'tc_command'
10
11
  require 'tc_installer'
11
12
  require 'tc_script'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vimget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddy Xu
@@ -28,10 +28,11 @@ executables:
28
28
  - vim-get
29
29
  extensions: []
30
30
 
31
- extra_rdoc_files: []
32
-
31
+ extra_rdoc_files:
32
+ - README
33
33
  files:
34
34
  - bin/vim-get
35
+ - test/tc_command.rb
35
36
  - test/tc_db.rb
36
37
  - test/tc_installer.rb
37
38
  - test/tc_script.rb
@@ -55,6 +56,7 @@ files:
55
56
  - lib/vimget/script.rb
56
57
  - lib/vimget/webparser.rb
57
58
  - lib/vimget.rb
59
+ - README
58
60
  has_rdoc: true
59
61
  homepage: http://www.xulei.org/projects/vimget
60
62
  post_install_message: