vimget 0.1.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/bin/vim-get +15 -0
- data/lib/vimget/command.rb +157 -0
- data/lib/vimget/command_manager.rb +126 -0
- data/lib/vimget/commands/clean_command.rb +35 -0
- data/lib/vimget/commands/install_command.rb +75 -0
- data/lib/vimget/commands/installed_command.rb +34 -0
- data/lib/vimget/commands/list_command.rb +71 -0
- data/lib/vimget/commands/outdated_command.rb +34 -0
- data/lib/vimget/commands/sync_command.rb +39 -0
- data/lib/vimget/commands/uninstall_command.rb +59 -0
- data/lib/vimget/commands/upgrade_command.rb +41 -0
- data/lib/vimget/configure.rb +33 -0
- data/lib/vimget/db.rb +139 -0
- data/lib/vimget/exceptions.rb +24 -0
- data/lib/vimget/installer.rb +158 -0
- data/lib/vimget/script.rb +56 -0
- data/lib/vimget/webparser.rb +33 -0
- data/lib/vimget.rb +37 -0
- data/test/tc_db.rb +45 -0
- data/test/tc_installer.rb +23 -0
- data/test/tc_script.rb +57 -0
- data/test/ts_vimget.rb +11 -0
- metadata +85 -0
data/bin/vim-get
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# vim-get: a vim script manager
|
4
|
+
#
|
5
|
+
# $Id: vim-get 8 2008-03-26 17:32:26Z eddyxu $
|
6
|
+
|
7
|
+
begin
|
8
|
+
$: << "#{File.dirname(__FILE__)}/../lib"
|
9
|
+
require 'vimget'
|
10
|
+
rescue LoadError
|
11
|
+
require 'rubygems'
|
12
|
+
require 'vimget'
|
13
|
+
end
|
14
|
+
|
15
|
+
VimGet::application.run
|
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# @file command.rb
|
4
|
+
#
|
5
|
+
# @breif parser and manager commands
|
6
|
+
#
|
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 $
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'optparse'
|
15
|
+
require "vimget/configure"
|
16
|
+
|
17
|
+
module VimGet
|
18
|
+
|
19
|
+
# base class for all commands
|
20
|
+
class BaseCommand
|
21
|
+
PROGRAM = "vim-get"
|
22
|
+
# the name of command
|
23
|
+
attr_reader :command
|
24
|
+
|
25
|
+
# the options for this command
|
26
|
+
attr_reader :options
|
27
|
+
|
28
|
+
attr_reader :options_group
|
29
|
+
|
30
|
+
# the default options for the command
|
31
|
+
attr_accessor :defaults
|
32
|
+
|
33
|
+
# the name of the command for command-line invocation
|
34
|
+
attr_accessor :program_name
|
35
|
+
|
36
|
+
# A short description of the command
|
37
|
+
attr_accessor :summary
|
38
|
+
|
39
|
+
def initialize(command, summary = nil, defaults = {})
|
40
|
+
@command, @summary, @defaults = command, summary, defaults
|
41
|
+
@program_name = "#{PROGRAM} #{command}"
|
42
|
+
@options = defaults.dup
|
43
|
+
@parser = nil
|
44
|
+
@option_groups = Hash.new { |h,k| h[k] = [] }
|
45
|
+
end
|
46
|
+
|
47
|
+
def usage
|
48
|
+
@program_name
|
49
|
+
end
|
50
|
+
|
51
|
+
def show_help
|
52
|
+
parser.program_name = usage
|
53
|
+
puts @parser
|
54
|
+
end
|
55
|
+
|
56
|
+
def arguments
|
57
|
+
""
|
58
|
+
end
|
59
|
+
|
60
|
+
def invoke(*args)
|
61
|
+
handle_options(args)
|
62
|
+
if @options[:help]
|
63
|
+
show_help
|
64
|
+
else
|
65
|
+
execute
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def execute
|
70
|
+
raise 'Command without define execute function'
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
def add_option(*opts, &handler)
|
76
|
+
group_name = Symbol === opts.first ? opts.shift : :options
|
77
|
+
@option_groups[group_name] << [opts, handler]
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_option(name)
|
81
|
+
@option_groups.each do |_, option_list|
|
82
|
+
option_list.reject! { |args, _| args.any? { |x| x =~ /^#{name}/ } }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def pop_one_argument
|
87
|
+
return nil if @rest.empty?
|
88
|
+
return @rest.shift
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def handle_options(args)
|
94
|
+
@rest = parser.parse(*args)
|
95
|
+
@options[:args] = args
|
96
|
+
end
|
97
|
+
|
98
|
+
def parser
|
99
|
+
create_parser if @parser.nil?
|
100
|
+
@parser
|
101
|
+
end
|
102
|
+
|
103
|
+
def create_parser
|
104
|
+
@parser = OptionParser.new
|
105
|
+
|
106
|
+
if @summary
|
107
|
+
@parser.separator ""
|
108
|
+
@parser.separator " Summary:"
|
109
|
+
wrap(@summary, 80-4).split("\n").each do |l|
|
110
|
+
@parser.separator " #{l.strip}"
|
111
|
+
end
|
112
|
+
@parser.separator ""
|
113
|
+
end
|
114
|
+
|
115
|
+
unless arguments.empty?
|
116
|
+
@parser.separator(" Arguments:")
|
117
|
+
arguments.split(/\n/).each do |arg_desc|
|
118
|
+
@parser.separator(" #{arg_desc}")
|
119
|
+
end
|
120
|
+
@parser.separator("")
|
121
|
+
end
|
122
|
+
|
123
|
+
add_option(:common, '-h', '--help', 'display this help') {|v, opts| @options[:help] = true }
|
124
|
+
add_option(:common, '--debug', 'print debug informations') {|v, opts| VimGet.configure.debug = true }
|
125
|
+
add_option(:common, '--verbose', 'set verbose mode') {|v, opts| @options[:verbose] = true }
|
126
|
+
|
127
|
+
@option_groups.each do |grp, opts|
|
128
|
+
configure_options(grp, opts)
|
129
|
+
end
|
130
|
+
|
131
|
+
@parser.separator " Further information"
|
132
|
+
@parser.separator " http://vimget.rubyforge.org"
|
133
|
+
end
|
134
|
+
|
135
|
+
def configure_options(header, option_list)
|
136
|
+
return if option_list.nil? or option_list.empty?
|
137
|
+
|
138
|
+
header = header.to_s.empty? ? '' : "#{header} "
|
139
|
+
@parser.separator " #{header.capitalize}options:"
|
140
|
+
|
141
|
+
option_list.each do |args, handler|
|
142
|
+
dashes = args.select { |arg| arg =~ /^-/ }
|
143
|
+
@parser.on(*args) do |value|
|
144
|
+
handler.call(value, @options)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
@parser.separator ''
|
149
|
+
end
|
150
|
+
|
151
|
+
def wrap(text, width)
|
152
|
+
text.gsub(/(.{1,#{width}})( +|$\n?)|(.{1,#{width}})/, "\\1\\3\n")
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Command Manager
|
4
|
+
#
|
5
|
+
# Eddy Xu <eddyxu@gmail.com>
|
6
|
+
#
|
7
|
+
# 2008 (c) Quarkware.com
|
8
|
+
#
|
9
|
+
# $Id: command_manager.rb 5 2008-04-11 18:33:39Z eddyxu $
|
10
|
+
|
11
|
+
require "vimget/exceptions"
|
12
|
+
require "vimget/configure"
|
13
|
+
|
14
|
+
module VimGet
|
15
|
+
|
16
|
+
class CommandManager
|
17
|
+
def self.instance
|
18
|
+
@command_manager ||= CommandManager.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
end
|
23
|
+
|
24
|
+
def run(args)
|
25
|
+
process_args(args)
|
26
|
+
rescue StandardError => ex
|
27
|
+
puts "While execute vim-get...(#{ex.class})\n #{ex.to_s}"
|
28
|
+
puts ex.backtrace if VimGet.configure.debug
|
29
|
+
rescue Interrupt
|
30
|
+
puts "Interrupt"
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def process_args(args)
|
36
|
+
if ARGV.empty?
|
37
|
+
usage
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
case ARGV[0]
|
42
|
+
when '-h', '--help'
|
43
|
+
usage
|
44
|
+
exit 1
|
45
|
+
when '-v', '--version', 'version'
|
46
|
+
version
|
47
|
+
when 'help'
|
48
|
+
ARGV[1] ? help(ARGV[1]) : help
|
49
|
+
end
|
50
|
+
|
51
|
+
cmd_obj = find_command(ARGV[0])
|
52
|
+
cmd_obj.invoke(ARGV.dup)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def usage
|
57
|
+
puts <<-USAGE
|
58
|
+
vim-get: the vim script management tool
|
59
|
+
|
60
|
+
Usage:
|
61
|
+
vim-get -h/--help
|
62
|
+
vim-get -v/--version
|
63
|
+
vim-get command [options] [arg1 argu2 ...]
|
64
|
+
|
65
|
+
Common options:
|
66
|
+
--debug display debug infomation
|
67
|
+
--verbose set verbose
|
68
|
+
|
69
|
+
Supported commands:
|
70
|
+
help provide help for special commands
|
71
|
+
version display version and runtime informations
|
72
|
+
|
73
|
+
install install a script
|
74
|
+
uninstall uninstall a script
|
75
|
+
upgrade upgrade outdated script
|
76
|
+
sync sync local script version database
|
77
|
+
clean clean all distributed files
|
78
|
+
|
79
|
+
list list local scripts
|
80
|
+
outdated list all outdated scripts
|
81
|
+
installed list all installed scripts
|
82
|
+
|
83
|
+
Further Infomation:
|
84
|
+
https://rubyforge.org/projects/vimget/
|
85
|
+
|
86
|
+
USAGE
|
87
|
+
end
|
88
|
+
|
89
|
+
def help(cmd="")
|
90
|
+
if cmd.empty?
|
91
|
+
usage
|
92
|
+
elsif cmd == "help"
|
93
|
+
nil
|
94
|
+
else
|
95
|
+
command_obj = find_command(cmd)
|
96
|
+
command_obj.show_help
|
97
|
+
end
|
98
|
+
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
|
102
|
+
def version
|
103
|
+
puts "vim-get: vim script management tool #{VIMGET_VERSION}"
|
104
|
+
puts
|
105
|
+
puts "Runtime:"
|
106
|
+
puts " vim-get base dir: #{VimGet.configure.base_dir}"
|
107
|
+
puts " vim dir: #{VimGet.configure.vim_dir}"
|
108
|
+
exit 1
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def find_command(cmd_str)
|
114
|
+
cmd_str = cmd_str.to_s
|
115
|
+
|
116
|
+
begin
|
117
|
+
const_name = cmd_str.capitalize.gsub(/_(.)/) {$1.upcase}
|
118
|
+
require "vimget/commands/#{cmd_str}_command"
|
119
|
+
VimGet::Commands.const_get("#{const_name}Command").new
|
120
|
+
rescue LoadError => ex
|
121
|
+
raise VimGet::CommandLineError, "Unknown command #{cmd_str}"
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# File: clean_command.rb
|
4
|
+
#
|
5
|
+
# Brief: clean command
|
6
|
+
#
|
7
|
+
# Author: Eddy Xu <eddyxu@gmail.com>
|
8
|
+
#
|
9
|
+
# Copyright: 2008 (c) Quarkware.com
|
10
|
+
#
|
11
|
+
# $Id: clean_command.rb 5 2008-04-11 18:33:39Z eddyxu $
|
12
|
+
#
|
13
|
+
|
14
|
+
require "vimget/command"
|
15
|
+
require "vimget/configure"
|
16
|
+
|
17
|
+
module VimGet
|
18
|
+
module Commands
|
19
|
+
|
20
|
+
class CleanCommand < BaseCommand
|
21
|
+
def initialize
|
22
|
+
super('clean', 'clean all distributed files')
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
dir = VimGet.configure.distfiles_dir
|
28
|
+
puts "Cleaing..."
|
29
|
+
|
30
|
+
abs_dir = File.expand_path(dir)
|
31
|
+
Dir.glob(File.join(abs_dir,"*")).each { |f| File.delete(f) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# File: install_command.rb
|
4
|
+
#
|
5
|
+
# Brief: install command
|
6
|
+
#
|
7
|
+
# Author: Eddy Xu <eddyxu@gmail.com>
|
8
|
+
#
|
9
|
+
# Copyright: 2008 (c) Quarkware.com
|
10
|
+
#
|
11
|
+
# $Id: install_command.rb 5 2008-04-11 18:33:39Z eddyxu $
|
12
|
+
#
|
13
|
+
|
14
|
+
require "vimget/command"
|
15
|
+
require "vimget/db"
|
16
|
+
require "vimget/exceptions"
|
17
|
+
require "vimget/webparser"
|
18
|
+
require "vimget/installer"
|
19
|
+
|
20
|
+
|
21
|
+
module VimGet
|
22
|
+
module Commands
|
23
|
+
|
24
|
+
class InstallCommand < BaseCommand
|
25
|
+
def initialize
|
26
|
+
super('install', "Install a script")
|
27
|
+
|
28
|
+
custom_options
|
29
|
+
end
|
30
|
+
|
31
|
+
def usage
|
32
|
+
"#{@program_name} [NAME]"
|
33
|
+
end
|
34
|
+
|
35
|
+
def arguments
|
36
|
+
"NAME name of script to install"
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute
|
40
|
+
if @options[:install_id]
|
41
|
+
script = VimGet.db.find_with_id @options[:install_id]
|
42
|
+
|
43
|
+
if script.nil?
|
44
|
+
script = VimGet.parse_script_page(@options[:install_id])
|
45
|
+
VimGet.db.add(script)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
@rest.shift if @rest.first == "install"
|
49
|
+
if @rest.empty?
|
50
|
+
raise CommandLineError, "Missing arguments"
|
51
|
+
end
|
52
|
+
|
53
|
+
name = @rest.first
|
54
|
+
|
55
|
+
script = VimGet.db.find(name)
|
56
|
+
|
57
|
+
raise UnknownScriptError, "Unknow script!" if script.nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
installer = Installer.new(@options)
|
61
|
+
installer.install(script)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def custom_options
|
67
|
+
add_option(:install, '-i', '--id ID', Integer, "Install a script with script id") do |v, opts|
|
68
|
+
opts[:install_id] = v
|
69
|
+
end
|
70
|
+
add_option(:install, '--dry-run', "Do not modify anything") { |v, opts| opts[:dryrun] = v }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# File: installed_command.rb
|
4
|
+
#
|
5
|
+
# Brief: installed command
|
6
|
+
#
|
7
|
+
# Author: Eddy Xu <eddyxu@gmail.com>
|
8
|
+
#
|
9
|
+
# Copyright: 2008 (c) Quarkware.com
|
10
|
+
#
|
11
|
+
# $Id: installed_command.rb 6 2008-04-11 19:01:26Z eddyxu $
|
12
|
+
#
|
13
|
+
|
14
|
+
require "vimget/commands/list_command"
|
15
|
+
|
16
|
+
module VimGet
|
17
|
+
|
18
|
+
module Commands
|
19
|
+
|
20
|
+
class InstalledCommand < ListCommand
|
21
|
+
def initialize
|
22
|
+
super("installed", "Display all installed scripts")
|
23
|
+
options[:installed] = true
|
24
|
+
remove_option('--outdated')
|
25
|
+
remove_option('--installed')
|
26
|
+
end
|
27
|
+
|
28
|
+
def usage
|
29
|
+
@program_name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
#
|
3
|
+
# list command
|
4
|
+
#
|
5
|
+
# $Id: list_command.rb 5 2008-04-11 18:33:39Z eddyxu $
|
6
|
+
|
7
|
+
require "vimget/command"
|
8
|
+
require "vimget/db.rb"
|
9
|
+
|
10
|
+
module VimGet
|
11
|
+
module Commands
|
12
|
+
|
13
|
+
class ListCommand < BaseCommand
|
14
|
+
def initialize(name = 'list', summary = 'Display all script in local')
|
15
|
+
super(name,
|
16
|
+
summary,
|
17
|
+
:format => "plain")
|
18
|
+
|
19
|
+
add_customer_options
|
20
|
+
end
|
21
|
+
|
22
|
+
def usage
|
23
|
+
"#{program_name} [STRING]"
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
raise CommandLineError, "Ambiguous command!" if @options[:outdated] && @options[:installed]
|
28
|
+
|
29
|
+
if @options[:outdated]
|
30
|
+
puts "List outdated scripts"
|
31
|
+
elsif @options[:installed]
|
32
|
+
puts "List installed scripts"
|
33
|
+
else
|
34
|
+
puts "List scripts"
|
35
|
+
end
|
36
|
+
|
37
|
+
scripts = VimGet.db.search()
|
38
|
+
|
39
|
+
# Todo: decouple it to output module
|
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
|
+
if @options[:format] == "plain"
|
48
|
+
puts "[#{s.name}]"
|
49
|
+
puts "id: #{s.sid}"
|
50
|
+
puts "author: #{s.author}"
|
51
|
+
puts "installed: #{s.installed}"
|
52
|
+
puts "version: #{s.version}"
|
53
|
+
puts
|
54
|
+
#elsif @options[:format] == "xml"
|
55
|
+
# puts "<script name=\"#{s.name}\" id=\"#{s.sid}\">"
|
56
|
+
# puts "</script>"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def add_customer_options
|
64
|
+
#add_option(:list, '--xml', 'Display in XML Format') { |v,opts| opts[:format] = "xml" }
|
65
|
+
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}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# File: outdated_command.rb
|
4
|
+
#
|
5
|
+
# Brief: outdated command
|
6
|
+
#
|
7
|
+
# Author: Eddy Xu <eddyxu@gmail.com>
|
8
|
+
#
|
9
|
+
# Copyright: 2008 (c) Quarkware.com
|
10
|
+
#
|
11
|
+
# $Id: outdated_command.rb 6 2008-04-11 19:01:26Z eddyxu $
|
12
|
+
#
|
13
|
+
|
14
|
+
require "vimget/commands/list_command"
|
15
|
+
|
16
|
+
module VimGet
|
17
|
+
|
18
|
+
module Commands
|
19
|
+
|
20
|
+
class OutdatedCommand < ListCommand
|
21
|
+
def initialize
|
22
|
+
super("outdated", "Display all outdated scripts")
|
23
|
+
options[:outdated] = true
|
24
|
+
remove_option('--outdated')
|
25
|
+
remove_option('--installed')
|
26
|
+
end
|
27
|
+
|
28
|
+
def usage
|
29
|
+
@program_name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# File: sync_command.rb
|
4
|
+
#
|
5
|
+
# Brief: do sync command
|
6
|
+
#
|
7
|
+
# Author: Eddy Xu <eddyxu@gmail.com>
|
8
|
+
#
|
9
|
+
# Copyright: 2008 (c) Quarkware.com
|
10
|
+
#
|
11
|
+
# $Id: sync_command.rb 5 2008-04-11 18:33:39Z eddyxu $
|
12
|
+
#
|
13
|
+
|
14
|
+
require "vimget/command"
|
15
|
+
require "vimget/db"
|
16
|
+
require "vimget/webparser"
|
17
|
+
|
18
|
+
module VimGet
|
19
|
+
module Commands
|
20
|
+
|
21
|
+
class SyncCommand < BaseCommand
|
22
|
+
def initialize
|
23
|
+
super('sync', 'Sync with vim site')
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
puts "Syncing..."
|
28
|
+
|
29
|
+
db = VimGet.db
|
30
|
+
db.search().each do |s|
|
31
|
+
puts "-> sync #{s.name}.."
|
32
|
+
new_script = VimGet::parse_script_page(s.sid)
|
33
|
+
new_script.installed = s.installed
|
34
|
+
db.update(new_script)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# File uninstall.rb
|
4
|
+
#
|
5
|
+
# Brief act the uninstall operations
|
6
|
+
#
|
7
|
+
# Author Eddy Xu <eddyxu@gmail.com>
|
8
|
+
#
|
9
|
+
# Copyright 2008 (c) Quarkware.com
|
10
|
+
#
|
11
|
+
# $Id: uninstall_command.rb 5 2008-04-11 18:33:39Z eddyxu $
|
12
|
+
|
13
|
+
require "vimget/command"
|
14
|
+
require "vimget/db"
|
15
|
+
require "vimget/installer"
|
16
|
+
|
17
|
+
|
18
|
+
module VimGet
|
19
|
+
|
20
|
+
module Commands
|
21
|
+
|
22
|
+
class UninstallCommand < BaseCommand
|
23
|
+
def initialize
|
24
|
+
super("uninstall", "Uninstall a script")
|
25
|
+
|
26
|
+
add_option("-i",
|
27
|
+
"--id ID",
|
28
|
+
Integer,
|
29
|
+
"Indicated the id of script to uninstall") { |v,opts| opts[:uninstall_id] = v }
|
30
|
+
|
31
|
+
add_option('--purge',
|
32
|
+
'Remove all associated files, including vim-get manifest') { |v,opts| opts[:purge] = v }
|
33
|
+
|
34
|
+
add_option('--dry-run',
|
35
|
+
'Do not motify any files') { |v,opts| opts[:dry_run] = v }
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute
|
39
|
+
if @options[:uninstall_id]
|
40
|
+
script = VimGet.db.find_with_id(@options[:uninstall_id])
|
41
|
+
else
|
42
|
+
@rest.shift if @rest.first == "uninstall"
|
43
|
+
raise CommandLineError, "Missing arguments" if @rest.empty?
|
44
|
+
|
45
|
+
name = @rest.first
|
46
|
+
script = VimGet.db.find(name)
|
47
|
+
end
|
48
|
+
|
49
|
+
if script.nil?
|
50
|
+
raise UnknownScriptError, "This script is not installed yet."
|
51
|
+
end
|
52
|
+
|
53
|
+
installer = Installer.new(@options)
|
54
|
+
installer.uninstall(script)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# File: upgrade_command.rb
|
4
|
+
#
|
5
|
+
# Brief: perform upgrading operation
|
6
|
+
#
|
7
|
+
# Author: Eddy Xu <eddyxu@gmail.com>
|
8
|
+
#
|
9
|
+
# Copyright: 2008 (c) Quarkware.com
|
10
|
+
#
|
11
|
+
# $Id: upgrade_command.rb 6 2008-04-11 19:01:26Z eddyxu $
|
12
|
+
#
|
13
|
+
|
14
|
+
require "vimget/command"
|
15
|
+
require "vimget/installer"
|
16
|
+
require "vimget/db"
|
17
|
+
|
18
|
+
module VimGet
|
19
|
+
module Commands
|
20
|
+
|
21
|
+
class UpgradeCommand < BaseCommand
|
22
|
+
def initialize
|
23
|
+
super('upgrade', 'upgrade outdated script(s)')
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute
|
27
|
+
outdated_scripts = VimGet.db.get_outdated_scripts
|
28
|
+
|
29
|
+
if outdated_scripts.empty?
|
30
|
+
puts "There is no script outdated."
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
installer = Installer.new(@options)
|
35
|
+
outdated_scripts.each do |s|
|
36
|
+
installer.upgrade(s)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|