ratch 1.2.0 → 2.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.
- checksums.yaml +7 -0
- data/HISTORY.rdoc +87 -0
- data/README.rdoc +86 -66
- data/bin/ludo +26 -10
- data/lib/ratch/batch.rb +115 -74
- data/lib/ratch/core_ext/facets.rb +2 -1
- data/lib/ratch/core_ext/to_console.rb +11 -11
- data/lib/ratch/file_list.rb +6 -15
- data/lib/ratch/script.rb +1 -1
- data/lib/ratch/shell.rb +356 -518
- data/lib/ratch/utils/config.rb +4 -4
- data/lib/ratch/utils/email.rb +20 -97
- data/lib/ratch/utils/rdoc.rb +4 -7
- data/lib/ratch/utils/tar.rb +94 -50
- data/lib/ratch/utils/xdg.rb +2 -3
- data/lib/ratch/utils/zlib.rb +5 -4
- data/lib/ratch/version.rb +3 -0
- data/lib/ratch.rb +8 -24
- metadata +134 -157
- data/.ruby +0 -99
- data/History.rdoc +0 -35
- data/License.txt +0 -204
- data/Version +0 -1
- data/lib/ratch/console.rb +0 -199
- data/lib/ratch/system.rb +0 -15
- data/lib/ratch/utils/ftp.rb +0 -134
- data/lib/ratch/utils/pom.rb +0 -22
- data/lib/ratch.yml +0 -99
- data/man/ratch.1 +0 -28
- data/spec/01_shell.rdoc +0 -198
- data/spec/02_script.rdoc +0 -34
- data/spec/03_batch.rdoc +0 -71
- data/spec/04_system.rdoc +0 -3
- data/spec/applique/array.rb +0 -8
- data/spec/applique/setup.rb +0 -20
- data/test/case_batch.rb +0 -63
- data/test/case_shell.rb +0 -46
- data/test/core_ext/case_pathname.rb +0 -361
- data/test/helper.rb +0 -4
- data/test/utils/case_cli.rb +0 -6
- data/test/utils/case_config.rb +0 -12
- data/test/utils/case_email.rb +0 -10
- data/test/utils/case_ftp.rb +0 -6
- data/test/utils/case_pom.rb +0 -17
- data/test/utils/case_rdoc.rb +0 -23
- data/test/utils/case_tar.rb +0 -6
- data/test/utils/case_zlib.rb +0 -11
- data/test/utils/fixtures/pom_sample/Profile +0 -4
- data/test/utils/fixtures/rdoc_sample/README.rdoc +0 -4
- data/test/utils/fixtures/rdoc_sample/lib/rdoc_sample/rdoc_sample.rb +0 -9
- /data/{COPYING → LICENSE.txt} +0 -0
data/lib/ratch/console.rb
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
module Ratch
|
|
2
|
-
|
|
3
|
-
# Ratch Shell Console
|
|
4
|
-
#
|
|
5
|
-
# NOTE: Console class is still a work in progress.
|
|
6
|
-
class Console
|
|
7
|
-
|
|
8
|
-
attr_accessor :suppress_output
|
|
9
|
-
|
|
10
|
-
# Set up the user's environment, including a pure binding into which
|
|
11
|
-
# env.rb and commands.rb are mixed.
|
|
12
|
-
def initialize
|
|
13
|
-
require 'readline'
|
|
14
|
-
#root = Rush::Dir.new('/')
|
|
15
|
-
#home = Rush::Dir.new(ENV['HOME']) if ENV['HOME']
|
|
16
|
-
#pwd = Rush::Dir.new(ENV['PWD']) if ENV['PWD']
|
|
17
|
-
|
|
18
|
-
#@config = Rush::Config.new
|
|
19
|
-
|
|
20
|
-
@config.load_history.each do |item|
|
|
21
|
-
Readline::HISTORY.push(item)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
Readline.basic_word_break_characters = ""
|
|
25
|
-
Readline.completion_append_character = nil
|
|
26
|
-
Readline.completion_proc = completion_proc
|
|
27
|
-
|
|
28
|
-
@shell = Ratch::Shell.new
|
|
29
|
-
|
|
30
|
-
@pure_binding = @shell.instance_eval("binding")
|
|
31
|
-
|
|
32
|
-
$last_res = nil
|
|
33
|
-
|
|
34
|
-
#eval @config.load_env, @pure_binding
|
|
35
|
-
|
|
36
|
-
#commands = @config.load_commands
|
|
37
|
-
#Rush::Dir.class_eval commands
|
|
38
|
-
#Array.class_eval commands
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Run the interactive shell using readline.
|
|
42
|
-
def run
|
|
43
|
-
loop do
|
|
44
|
-
cmd = Readline.readline('ratch> ')
|
|
45
|
-
|
|
46
|
-
finish if cmd.nil? or cmd == 'exit'
|
|
47
|
-
|
|
48
|
-
next if cmd == ""
|
|
49
|
-
|
|
50
|
-
Readline::HISTORY.push(cmd)
|
|
51
|
-
|
|
52
|
-
execute(cmd)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Run a single command.
|
|
57
|
-
def execute(cmd)
|
|
58
|
-
res = eval(cmd, @pure_binding)
|
|
59
|
-
$last_res = res
|
|
60
|
-
eval("_ = $last_res", @pure_binding)
|
|
61
|
-
print_result(res)
|
|
62
|
-
#rescue Rush::Exception => e
|
|
63
|
-
# puts "Exception #{e.class} -> #{e.message}"
|
|
64
|
-
rescue ::Exception => e
|
|
65
|
-
puts "Exception #{e.class} -> #{e.message}"
|
|
66
|
-
e.backtrace.each do |t|
|
|
67
|
-
puts " #{::File.expand_path(t)}"
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# Save history to ~/.config/ratch/history when the shell exists.
|
|
72
|
-
def finish
|
|
73
|
-
@config.save_history(Readline::HISTORY.to_a)
|
|
74
|
-
puts
|
|
75
|
-
exit
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# TODO: FIX ALL BELOW
|
|
79
|
-
|
|
80
|
-
# Nice printing of different return types, particularly Rush::SearchResults.
|
|
81
|
-
def print_result(res)
|
|
82
|
-
return if self.suppress_output
|
|
83
|
-
if res.kind_of? String
|
|
84
|
-
puts res
|
|
85
|
-
elsif res.kind_of? Rush::SearchResults
|
|
86
|
-
widest = res.entries.map { |k| k.full_path.length }.max
|
|
87
|
-
res.entries_with_lines.each do |entry, lines|
|
|
88
|
-
print entry.full_path
|
|
89
|
-
print ' ' * (widest - entry.full_path.length + 2)
|
|
90
|
-
print "=> "
|
|
91
|
-
print res.colorize(lines.first.strip.head(30))
|
|
92
|
-
print "..." if lines.first.strip.length > 30
|
|
93
|
-
if lines.size > 1
|
|
94
|
-
print " (plus #{lines.size - 1} more matches)"
|
|
95
|
-
end
|
|
96
|
-
print "\n"
|
|
97
|
-
end
|
|
98
|
-
puts "#{res.entries.size} matching files with #{res.lines.size} matching lines"
|
|
99
|
-
elsif res.respond_to? :each
|
|
100
|
-
counts = {}
|
|
101
|
-
res.each do |item|
|
|
102
|
-
puts item
|
|
103
|
-
counts[item.class] ||= 0
|
|
104
|
-
counts[item.class] += 1
|
|
105
|
-
end
|
|
106
|
-
if counts == {}
|
|
107
|
-
puts "=> (empty set)"
|
|
108
|
-
else
|
|
109
|
-
count_s = counts.map do |klass, count|
|
|
110
|
-
"#{count} x #{klass}"
|
|
111
|
-
end.join(', ')
|
|
112
|
-
puts "=> #{count_s}"
|
|
113
|
-
end
|
|
114
|
-
else
|
|
115
|
-
puts "=> #{res.inspect}"
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def path_parts(input) # :nodoc:
|
|
120
|
-
case input
|
|
121
|
-
when /((?:@{1,2}|\$|)\w+(?:\[[^\]]+\])*)([\[\/])(['"])([^\3]*)$/
|
|
122
|
-
$~.to_a.slice(1, 4).push($~.pre_match)
|
|
123
|
-
when /((?:@{1,2}|\$|)\w+(?:\[[^\]]+\])*)(\.)(\w*)$/
|
|
124
|
-
$~.to_a.slice(1, 3).push($~.pre_match)
|
|
125
|
-
when /((?:@{1,2}|\$|)\w+)$/
|
|
126
|
-
$~.to_a.slice(1, 1).push(nil).push($~.pre_match)
|
|
127
|
-
else
|
|
128
|
-
[ nil, nil, nil ]
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def complete_method(receiver, dot, partial_name, pre)
|
|
133
|
-
path = eval("#{receiver}.full_path", @pure_binding) rescue nil
|
|
134
|
-
box = eval("#{receiver}.box", @pure_binding) rescue nil
|
|
135
|
-
if path and box
|
|
136
|
-
(box[path].methods - Object.methods).select do |e|
|
|
137
|
-
e.match(/^#{Regexp.escape(partial_name)}/)
|
|
138
|
-
end.map do |e|
|
|
139
|
-
(pre || '') + receiver + dot + e
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def complete_path(possible_var, accessor, quote, partial_path, pre) # :nodoc:
|
|
145
|
-
original_var, fixed_path = possible_var, ''
|
|
146
|
-
if /^(.+\/)([^\/]*)$/ === partial_path
|
|
147
|
-
fixed_path, partial_path = $~.captures
|
|
148
|
-
possible_var += "['#{fixed_path}']"
|
|
149
|
-
end
|
|
150
|
-
full_path = eval("#{possible_var}.full_path", @pure_binding) rescue nil
|
|
151
|
-
box = eval("#{possible_var}.box", @pure_binding) rescue nil
|
|
152
|
-
if full_path and box
|
|
153
|
-
Rush::Dir.new(full_path, box).entries.select do |e|
|
|
154
|
-
e.name.match(/^#{Regexp.escape(partial_path)}/)
|
|
155
|
-
end.map do |e|
|
|
156
|
-
(pre || '') + original_var + accessor + quote + fixed_path + e.name + (e.dir? ? "/" : "")
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def complete_variable(partial_name, pre)
|
|
162
|
-
lvars = eval('local_variables', @pure_binding)
|
|
163
|
-
gvars = eval('global_variables', @pure_binding)
|
|
164
|
-
ivars = eval('instance_variables', @pure_binding)
|
|
165
|
-
(lvars + gvars + ivars).select do |e|
|
|
166
|
-
e.match(/^#{Regexp.escape(partial_name)}/)
|
|
167
|
-
end.map do |e|
|
|
168
|
-
(pre || '') + e
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
# Try to do tab completion on dir square brackets and slash accessors.
|
|
173
|
-
#
|
|
174
|
-
# Example:
|
|
175
|
-
#
|
|
176
|
-
# dir['subd # presing tab here will produce dir['subdir/ if subdir exists
|
|
177
|
-
# dir/'subd # presing tab here will produce dir/'subdir/ if subdir exists
|
|
178
|
-
#
|
|
179
|
-
# This isn't that cool yet, because it can't do multiple levels of subdirs.
|
|
180
|
-
# It does work remotely, though, which is pretty sweet.
|
|
181
|
-
def completion_proc
|
|
182
|
-
proc do |input|
|
|
183
|
-
receiver, accessor, *rest = path_parts(input)
|
|
184
|
-
if receiver
|
|
185
|
-
case accessor
|
|
186
|
-
when /^[\[\/]$/
|
|
187
|
-
complete_path(receiver, accessor, *rest)
|
|
188
|
-
when /^\.$/
|
|
189
|
-
complete_method(receiver, accessor, *rest)
|
|
190
|
-
when nil
|
|
191
|
-
complete_variable(receiver, *rest)
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
end
|
data/lib/ratch/system.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module Ratch
|
|
2
|
-
|
|
3
|
-
# TODO: Build it!
|
|
4
|
-
#
|
|
5
|
-
# The System class provides a robust interface for interacting with
|
|
6
|
-
# system commands. It is essenatially a wrapper around popen3 or popen4.
|
|
7
|
-
#
|
|
8
|
-
# Having a separate class rather integrating this into Shell (as
|
|
9
|
-
# Ruby's standard Shell class does) provides a better SOC.
|
|
10
|
-
#
|
|
11
|
-
class System
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
end
|
data/lib/ratch/utils/ftp.rb
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
module Ratch
|
|
2
|
-
|
|
3
|
-
# FIXME: This module needs major work. Methods #ftp_files and
|
|
4
|
-
# ftp_stage_transfer need to either be generalized and moved to
|
|
5
|
-
# Shell or Script, or removed.
|
|
6
|
-
#
|
|
7
|
-
module FTPUtils
|
|
8
|
-
|
|
9
|
-
def self.included(base)
|
|
10
|
-
require 'net/ftp'
|
|
11
|
-
require 'net/sftp'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def self.extended(base)
|
|
15
|
-
included(base)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Use ftp to upload files.
|
|
19
|
-
#
|
|
20
|
-
def ftp(keys)
|
|
21
|
-
keys = upload_parameters(keys)
|
|
22
|
-
|
|
23
|
-
# set transfer rules
|
|
24
|
-
if keys.stage
|
|
25
|
-
trans = ftp_stage_transfer(keys.stage)
|
|
26
|
-
else
|
|
27
|
-
ftp_files(keys.dir, keys.copy).each do |from|
|
|
28
|
-
trans << [from,from]
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# append location of publication dir to from
|
|
33
|
-
dir = keys.dir
|
|
34
|
-
trans.collect!{ |from,to| [File.join(dir,from), to] }
|
|
35
|
-
|
|
36
|
-
if keys.dryrun
|
|
37
|
-
puts "ftp open #{keys.user}@#{keys.host}:#{keys.root}/"
|
|
38
|
-
keys.trans.each do |f, t|
|
|
39
|
-
puts "ftp put #{f} #{t}"
|
|
40
|
-
end
|
|
41
|
-
else
|
|
42
|
-
Net::FTP.open(keys.host) do |ftp|
|
|
43
|
-
ftp.login(keys.user) #password?
|
|
44
|
-
ftp.chdir(keys.root)
|
|
45
|
-
keys.trans.each do |f, t|
|
|
46
|
-
puts "ftp #{f} #{t}" unless keys.quiet
|
|
47
|
-
ftp.putbinaryfile( f, t, 1024 )
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Use sftp to upload files.
|
|
54
|
-
#
|
|
55
|
-
def sftp( keys )
|
|
56
|
-
keys = upload_parameters(keys)
|
|
57
|
-
|
|
58
|
-
# set transfer rules
|
|
59
|
-
if keys.stage
|
|
60
|
-
trans = ftp_stage_transfer(keys.stage)
|
|
61
|
-
else
|
|
62
|
-
ftp_files(keys.dir, keys.copy).each do |from|
|
|
63
|
-
trans << [from,from]
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# append location of publication dir to from
|
|
68
|
-
dir = keys.dir
|
|
69
|
-
trans.collect!{ |from,to| [File.join(dir,from), to] }
|
|
70
|
-
|
|
71
|
-
if keys.dryrun
|
|
72
|
-
puts "sftp open #{keys.user}@#{keys.host}:#{keys.root}/"
|
|
73
|
-
keys.trans.each do |f,t|
|
|
74
|
-
puts "sftp put #{f} #{t}"
|
|
75
|
-
end
|
|
76
|
-
else
|
|
77
|
-
Net::SFTP.start(keys.host, keys.user, keys.pass) do |sftp|
|
|
78
|
-
#sftp.login( user )
|
|
79
|
-
sftp.chdir(keys.root)
|
|
80
|
-
keys.trans.each do |f,t|
|
|
81
|
-
puts "sftp #{f} #{t}" unless keys.quiet
|
|
82
|
-
sftp.put_file(f,t) #, 1024 )
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Put together the list of files to copy.
|
|
89
|
-
def ftp_files( dir, copy )
|
|
90
|
-
Dir.chdir(dir) do
|
|
91
|
-
del, add = copy.partition{ |f| /^[-]/ =~ f }
|
|
92
|
-
|
|
93
|
-
# remove - and + prefixes
|
|
94
|
-
del.collect!{ |f| f.sub(/^[-]/,'') }
|
|
95
|
-
add.collect!{ |f| f.sub(/^[+]/,'') }
|
|
96
|
-
|
|
97
|
-
#del.concat(must_exclude)
|
|
98
|
-
|
|
99
|
-
ftp_files = []
|
|
100
|
-
add.each{ |g| files += Dir.glob(g) }
|
|
101
|
-
del.each{ |g| files -= Dir.glob(g) }
|
|
102
|
-
|
|
103
|
-
files.collect!{ |f| f.sub(/^\//,'') }
|
|
104
|
-
|
|
105
|
-
return files
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# Combine three part stage list into a two part from->to list.
|
|
110
|
-
#
|
|
111
|
-
# Using the stage list of three space separated fields.
|
|
112
|
-
#
|
|
113
|
-
# fromdir file todir
|
|
114
|
-
#
|
|
115
|
-
# This is used to generate a from -> to list of the form:
|
|
116
|
-
#
|
|
117
|
-
# fromdir/file todir/file
|
|
118
|
-
#
|
|
119
|
-
def ftp_stage_transfer( list )
|
|
120
|
-
trans = []
|
|
121
|
-
list.each do |line|
|
|
122
|
-
trans << Shellwords.shellwords(line)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
trans.collect! do |from, base, to|
|
|
126
|
-
file = File.join(from,base)
|
|
127
|
-
to = File.join(to,base)
|
|
128
|
-
[from, to]
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
end
|
data/lib/ratch/utils/pom.rb
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module Ratch
|
|
2
|
-
|
|
3
|
-
# Methods for utilizing Ruby POM.
|
|
4
|
-
module POMUtils
|
|
5
|
-
|
|
6
|
-
def self.included(base)
|
|
7
|
-
require 'pom'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.extended(base)
|
|
11
|
-
included(base)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
def project
|
|
16
|
-
@project ||= ::POM::Project.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
|
data/lib/ratch.yml
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: ratch
|
|
3
|
-
spec_version: 1.0.0
|
|
4
|
-
repositories:
|
|
5
|
-
public: git://github.com/rubyworks/ratch.git
|
|
6
|
-
title: Ratch
|
|
7
|
-
contact: trans <transfire@gmail.com>
|
|
8
|
-
requires:
|
|
9
|
-
- group: []
|
|
10
|
-
|
|
11
|
-
name: facets
|
|
12
|
-
version: 2.9.1+
|
|
13
|
-
- group: []
|
|
14
|
-
|
|
15
|
-
name: minitar
|
|
16
|
-
version: 0.5.3+
|
|
17
|
-
- group:
|
|
18
|
-
- test
|
|
19
|
-
name: ko
|
|
20
|
-
version: 1.2.0~
|
|
21
|
-
- group:
|
|
22
|
-
- test
|
|
23
|
-
name: qed
|
|
24
|
-
version: 0+
|
|
25
|
-
- group:
|
|
26
|
-
- build
|
|
27
|
-
name: syckle
|
|
28
|
-
version: 0+
|
|
29
|
-
resources:
|
|
30
|
-
code: http://github.org/rubyworks/ratch
|
|
31
|
-
mail: http://groups.gooogle.com/group/rubyworks-mailinglist
|
|
32
|
-
home: http://rubyworks.github.org/ratch
|
|
33
|
-
manifest:
|
|
34
|
-
- .ruby
|
|
35
|
-
- bin/ludo
|
|
36
|
-
- bin/ratch
|
|
37
|
-
- lib/ratch/batch.rb
|
|
38
|
-
- lib/ratch/console.rb
|
|
39
|
-
- lib/ratch/core_ext/facets.rb
|
|
40
|
-
- lib/ratch/core_ext/filetest.rb
|
|
41
|
-
- lib/ratch/core_ext/to_actual_filename.rb
|
|
42
|
-
- lib/ratch/core_ext/to_console.rb
|
|
43
|
-
- lib/ratch/core_ext/to_list.rb
|
|
44
|
-
- lib/ratch/core_ext/to_yamlfrag.rb
|
|
45
|
-
- lib/ratch/core_ext/unfold_paragraphs.rb
|
|
46
|
-
- lib/ratch/core_ext.rb
|
|
47
|
-
- lib/ratch/file_list.rb
|
|
48
|
-
- lib/ratch/script/help.rb
|
|
49
|
-
- lib/ratch/script.rb
|
|
50
|
-
- lib/ratch/shell.rb
|
|
51
|
-
- lib/ratch/system.rb
|
|
52
|
-
- lib/ratch/utils/cli.rb
|
|
53
|
-
- lib/ratch/utils/config.rb
|
|
54
|
-
- lib/ratch/utils/email.rb
|
|
55
|
-
- lib/ratch/utils/ftp.rb
|
|
56
|
-
- lib/ratch/utils/pom.rb
|
|
57
|
-
- lib/ratch/utils/rdoc.rb
|
|
58
|
-
- lib/ratch/utils/tar.rb
|
|
59
|
-
- lib/ratch/utils/xdg.rb
|
|
60
|
-
- lib/ratch/utils/zlib.rb
|
|
61
|
-
- lib/ratch.rb
|
|
62
|
-
- lib/ratch.yml
|
|
63
|
-
- man/ratch.1
|
|
64
|
-
- spec/01_shell.rdoc
|
|
65
|
-
- spec/02_script.rdoc
|
|
66
|
-
- spec/03_batch.rdoc
|
|
67
|
-
- spec/04_system.rdoc
|
|
68
|
-
- spec/applique/array.rb
|
|
69
|
-
- spec/applique/setup.rb
|
|
70
|
-
- test/case_batch.rb
|
|
71
|
-
- test/case_shell.rb
|
|
72
|
-
- test/core_ext/case_pathname.rb
|
|
73
|
-
- test/helper.rb
|
|
74
|
-
- test/utils/case_cli.rb
|
|
75
|
-
- test/utils/case_config.rb
|
|
76
|
-
- test/utils/case_email.rb
|
|
77
|
-
- test/utils/case_ftp.rb
|
|
78
|
-
- test/utils/case_pom.rb
|
|
79
|
-
- test/utils/case_rdoc.rb
|
|
80
|
-
- test/utils/case_tar.rb
|
|
81
|
-
- test/utils/case_zlib.rb
|
|
82
|
-
- test/utils/fixtures/pom_sample/Profile
|
|
83
|
-
- test/utils/fixtures/rdoc_sample/README.rdoc
|
|
84
|
-
- test/utils/fixtures/rdoc_sample/lib/rdoc_sample/rdoc_sample.rb
|
|
85
|
-
- README.rdoc
|
|
86
|
-
- History.rdoc
|
|
87
|
-
- Version
|
|
88
|
-
- License.txt
|
|
89
|
-
- COPYING
|
|
90
|
-
version: 1.2.0
|
|
91
|
-
licenses:
|
|
92
|
-
- Apache 2.0
|
|
93
|
-
copyright: Copyright (c) 2009 Thomas Sawyer
|
|
94
|
-
description: Ratch is a Ruby-based batch scripting language. It's a DSL over regular Ruby to make the life of the batch script writter easier.
|
|
95
|
-
summary: Ruby-based Batch Scripting
|
|
96
|
-
organization: RubyWorks
|
|
97
|
-
authors:
|
|
98
|
-
- Trans <transfire@gmail.com>
|
|
99
|
-
created: 2009-09-22
|
data/man/ratch.1
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
.\" NAME
|
|
2
|
-
.\" ratch - ruby-based batch files
|
|
3
|
-
.\"
|
|
4
|
-
.\" SYNOPSIS
|
|
5
|
-
.\" reap [-n] [-h] [file]
|
|
6
|
-
.\"
|
|
7
|
-
.\" DESCRIPTION
|
|
8
|
-
.\" Ratch is batch file system using a Ruby=based DSL.
|
|
9
|
-
.\"
|
|
10
|
-
.\" OPTIONS
|
|
11
|
-
.\" -h help This option displays help.
|
|
12
|
-
.\" -n dryrun Dry-run/no-harm mode.
|
|
13
|
-
.\"
|
|
14
|
-
.\" ENVIRONMENT
|
|
15
|
-
.\" PAGER name of paging command, usually more(1), or less(1). If not set
|
|
16
|
-
.\" falls back to more(1).
|
|
17
|
-
.\"
|
|
18
|
-
.\" EXAMPLES
|
|
19
|
-
.\" Try this command to format this text itself:
|
|
20
|
-
.\"
|
|
21
|
-
.\" $ txt2man -h 2>&1 | txt2man -T
|
|
22
|
-
.\"
|
|
23
|
-
.\" SEE ALSO:
|
|
24
|
-
.\" ruby(1).
|
|
25
|
-
.\"
|
|
26
|
-
.\" AUTHOR:
|
|
27
|
-
.\" 7rans <transfire@gmail,com>
|
|
28
|
-
|
data/spec/01_shell.rdoc
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
= Ratch::Shell
|
|
2
|
-
|
|
3
|
-
The Shell class mimics a basic shell command line prompt.
|
|
4
|
-
|
|
5
|
-
require 'ratch/shell'
|
|
6
|
-
|
|
7
|
-
The demonstration sets up sample directory consisting of the following
|
|
8
|
-
entires in the tmp/qed directory:
|
|
9
|
-
|
|
10
|
-
foo.txt
|
|
11
|
-
zoo/
|
|
12
|
-
zoo/bar.txt
|
|
13
|
-
|
|
14
|
-
== Initial Path
|
|
15
|
-
|
|
16
|
-
When no path argument is provided to the initializer, the present working path
|
|
17
|
-
is used. The path is stored as a Pathname object.
|
|
18
|
-
|
|
19
|
-
shell = Ratch::Shell.new
|
|
20
|
-
shell.work.assert = Pathname.new(Dir.pwd).expand_path
|
|
21
|
-
|
|
22
|
-
Otherwise the path given is used.
|
|
23
|
-
|
|
24
|
-
shell = Ratch::Shell.new('.')
|
|
25
|
-
shell.work.assert = Pathname.new('.').expand_path
|
|
26
|
-
|
|
27
|
-
shell = Ratch::Shell.new('..')
|
|
28
|
-
shell.work.assert = Pathname.new('..').expand_path
|
|
29
|
-
|
|
30
|
-
An error is raise if the path does not exist.
|
|
31
|
-
|
|
32
|
-
expect Ratch::FileNotFound do
|
|
33
|
-
Ratch::Shell.new('not_a_path')
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
== Processing Options
|
|
37
|
-
|
|
38
|
-
The +initialize+ method accepts a few options. The +quiet+ option supresses
|
|
39
|
-
all output to stdout.
|
|
40
|
-
|
|
41
|
-
shell = Ratch::Shell.new(:quiet=>true)
|
|
42
|
-
shell.assert.quiet?
|
|
43
|
-
|
|
44
|
-
The +noop+ option prevents any actual writing to disk --the process will
|
|
45
|
-
simply pretend that it has done so.
|
|
46
|
-
|
|
47
|
-
shell = Ratch::Shell.new(:noop=>true)
|
|
48
|
-
shell.assert.noop?
|
|
49
|
-
|
|
50
|
-
The +trace+ option provides step by step feedback on what is taking place.
|
|
51
|
-
|
|
52
|
-
shell = Ratch::Shell.new(:trace=>true)
|
|
53
|
-
shell.assert.trace?
|
|
54
|
-
|
|
55
|
-
The +dryrun+ option is simply a compbination of +noop+ and +trace+.
|
|
56
|
-
|
|
57
|
-
shell = Ratch::Shell.new(:dryrun=>true)
|
|
58
|
-
shell.assert.noop?
|
|
59
|
-
shell.assert.trace?
|
|
60
|
-
shell.assert.dryrun?
|
|
61
|
-
|
|
62
|
-
== Equality
|
|
63
|
-
|
|
64
|
-
For two Shell objects to be considered equal, via #==, they must both
|
|
65
|
-
be instances of Ratch::Shell (or subclass) and have the same working
|
|
66
|
-
path.
|
|
67
|
-
|
|
68
|
-
shell1 = Ratch::Shell.new('.')
|
|
69
|
-
shell2 = Ratch::Shell.new('.')
|
|
70
|
-
shell1.assert = shell2
|
|
71
|
-
|
|
72
|
-
shell1 = Ratch::Shell.new('.')
|
|
73
|
-
shell2 = Ratch::Shell.new('..')
|
|
74
|
-
shell1.refute = shell2
|
|
75
|
-
|
|
76
|
-
The more strict #eql? method also ensures that the +noop+ option is the same.
|
|
77
|
-
|
|
78
|
-
shell1 = Ratch::Shell.new('.', :noop=>true)
|
|
79
|
-
shell2 = Ratch::Shell.new('.', :noop=>true)
|
|
80
|
-
shell1.assert.eql? shell2
|
|
81
|
-
|
|
82
|
-
shell1 = Ratch::Shell.new('.', :noop=>true)
|
|
83
|
-
shell2 = Ratch::Shell.new('.', :noop=>false)
|
|
84
|
-
shell1.refute.eql? shell2
|
|
85
|
-
|
|
86
|
-
== File System Locations
|
|
87
|
-
|
|
88
|
-
The Shell class provides a few convenient methods for accessing common
|
|
89
|
-
locations in the file system, namely #work, #home, #parent and #root.
|
|
90
|
-
|
|
91
|
-
shell = Ratch::Shell.new
|
|
92
|
-
|
|
93
|
-
shell.work.assert == Pathname.new('.').expand_path
|
|
94
|
-
shell.parent.assert == Pathname.new('..').expand_path
|
|
95
|
-
|
|
96
|
-
The current user's home directoryis accessible via the #home method.
|
|
97
|
-
|
|
98
|
-
shell.home.assert == Pathname.new('~').expand_path
|
|
99
|
-
|
|
100
|
-
The system's root folder can be accessed via #root method.
|
|
101
|
-
|
|
102
|
-
shell.root.assert == Pathname.new('/').expand_path
|
|
103
|
-
|
|
104
|
-
In addition the Shell class provides methods for accessing pathnames
|
|
105
|
-
relative to the current shell directory. The #path (or #pathname) method
|
|
106
|
-
returns a Pathname object with the given path.
|
|
107
|
-
|
|
108
|
-
shell.path('foo')
|
|
109
|
-
|
|
110
|
-
This will work regardless if the path actually exists or not. On the other hand,
|
|
111
|
-
the #file and #dir methods will do the same, but will raise an error if the path
|
|
112
|
-
given is not an existing file or a directory, respectively.
|
|
113
|
-
|
|
114
|
-
shell.file('foo.txt')
|
|
115
|
-
|
|
116
|
-
expect Ratch::FileNotFound do
|
|
117
|
-
shell.file('not.txt')
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
shell.dir('zoo')
|
|
121
|
-
|
|
122
|
-
expect Ratch::FileNotFound do
|
|
123
|
-
shell.dir('not')
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
== Entries
|
|
127
|
-
|
|
128
|
-
Shell#entries works just like Dir.entries except that each path is returned
|
|
129
|
-
as a Pathname object.
|
|
130
|
-
|
|
131
|
-
shell = Ratch::Shell.new
|
|
132
|
-
|
|
133
|
-
shell.entries.assert == ['foo.txt', '.', '..', 'zoo'].map{|f| Pathname.new(f)}
|
|
134
|
-
|
|
135
|
-
The #file_entries method limits the list to files only.
|
|
136
|
-
|
|
137
|
-
shell.file_entries.assert == ['foo.txt'].map{|f| Pathname.new(f)}
|
|
138
|
-
|
|
139
|
-
Whereas #directory_entries (or #dir_entries) limits the list to directories.
|
|
140
|
-
|
|
141
|
-
shell.directory_entries.assert == ['.', '..', 'zoo'].map{|f| Pathname.new(f)}
|
|
142
|
-
|
|
143
|
-
Of course, having to deal with the '.' and '..' is annoying most of the time
|
|
144
|
-
so Shell provides more convenient methods. Like #entries, #pathnames
|
|
145
|
-
provides a list of entries less the dot paths.
|
|
146
|
-
|
|
147
|
-
shell.pathnames.assert == ['foo.txt', 'zoo'].map{|f| Pathname.new(f)}
|
|
148
|
-
|
|
149
|
-
The #directories (also #folders) method limits this list to directories only.
|
|
150
|
-
|
|
151
|
-
shell.directories.assert == ['zoo'].map{|f| Pathname.new(f)}
|
|
152
|
-
|
|
153
|
-
And #files works out to be the same as #file_entires.
|
|
154
|
-
|
|
155
|
-
shell.files.assert == ['foo.txt'].map{|f| Pathname.new(f)}
|
|
156
|
-
|
|
157
|
-
== Globbing
|
|
158
|
-
|
|
159
|
-
shell = Ratch::Shell.new
|
|
160
|
-
|
|
161
|
-
shell.glob('*').assert == ['foo.txt', 'zoo']
|
|
162
|
-
|
|
163
|
-
== File Testing
|
|
164
|
-
|
|
165
|
-
Shell provides an interface to most of FileTest's functions.
|
|
166
|
-
|
|
167
|
-
shell.assert.exist?('foo.txt')
|
|
168
|
-
shell.assert.file?('foo.txt')
|
|
169
|
-
shell.refute.directory?('foo.txt')
|
|
170
|
-
shell.assert.directory?('zoo')
|
|
171
|
-
|
|
172
|
-
== File IO
|
|
173
|
-
|
|
174
|
-
Shell can be used to easily read the contents of a file.
|
|
175
|
-
|
|
176
|
-
shell = Ratch::Shell.new
|
|
177
|
-
|
|
178
|
-
shell.read('foo.txt').assert == 'SAMPLE FOO.TXT'
|
|
179
|
-
|
|
180
|
-
As well as write a new file.
|
|
181
|
-
|
|
182
|
-
shell.write('baz.txt', 'BAZ TEXT')
|
|
183
|
-
shell.read('baz.txt').assert == 'BAZ TEXT'
|
|
184
|
-
|
|
185
|
-
Or append to an existing file.
|
|
186
|
-
|
|
187
|
-
shell.append('baz.txt', ' 2')
|
|
188
|
-
shell.read('baz.txt').assert == 'BAZ TEXT 2'
|
|
189
|
-
|
|
190
|
-
The shell command supports many file methods, including #rm.
|
|
191
|
-
|
|
192
|
-
shell.rm('baz.txt')
|
|
193
|
-
|
|
194
|
-
== System Calls
|
|
195
|
-
|
|
196
|
-
The Shell class can also call out to system commands. This is handled
|
|
197
|
-
by the Ratch::System class. See the system.rdoc file for details.
|
|
198
|
-
|