Class: Sub
- Inherits:
-
Object
- Object
- Sub
- Defined in:
- lib/sub/version.rb,
lib/sub/app.rb
Overview
:nodoc:
Defined Under Namespace
Modules: VERSION
Constant Summary collapse
- DEFAULT_BASE_URL =
"svn+ssh://rubyforge.org/var/svn"
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#clean ⇒ Object
readonly
Returns the value of attribute clean.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#verbosity ⇒ Object
Returns the value of attribute verbosity.
Class Method Summary collapse
Instance Method Summary collapse
- #co ⇒ Object
- #defaults ⇒ Object
- #execute ⇒ Object
- #externals(root) ⇒ Object
- #help ⇒ Object
-
#initialize(options = {:verbosity => NORMAL}, args = []) ⇒ Sub
constructor
A new instance of Sub.
- #parse_externals(st) ⇒ Object
- #run(cmd, return_output = false) ⇒ Object
- #say(msg) ⇒ Object
- #svn(cmd) ⇒ Object
-
#up ⇒ Object
commands.
- #update(root) ⇒ Object
-
#update_many(roots) ⇒ Object
methods.
Constructor Details
#initialize(options = {:verbosity => NORMAL}, args = []) ⇒ Sub
Returns a new instance of Sub.
48 49 50 51 52 53 54 55 |
# File 'lib/sub/app.rb', line 48 def initialize( = {:verbosity => NORMAL}, args = []) = defaults.merge() @verbosity = [:verbosity] @clean = [:clean] @command = [:command] @url = [:url] || ENV['SUB_BASE_URL'] || ENV['SVN'] || DEFAULT_BASE_URL @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
45 46 47 |
# File 'lib/sub/app.rb', line 45 def args @args end |
#clean ⇒ Object (readonly)
Returns the value of attribute clean.
45 46 47 |
# File 'lib/sub/app.rb', line 45 def clean @clean end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
45 46 47 |
# File 'lib/sub/app.rb', line 45 def command @command end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
45 46 47 |
# File 'lib/sub/app.rb', line 45 def url @url end |
#verbosity ⇒ Object
Returns the value of attribute verbosity.
46 47 48 |
# File 'lib/sub/app.rb', line 46 def verbosity @verbosity end |
Class Method Details
.from_args(args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sub/app.rb', line 12 def self.from_args(args) verbosity = NORMAL = true command = :up = {} while case args[0] when 'up', 'co', 'help' [:command] = args[0] when '-v', '--verbose' [:verbosity] = VERBOSE when '-q', '--quiet' [:verbosity] = QUIET when '-h', '--help' [:command] = 'help' = false when '-c', '--clean' [:clean] = true when '--url' args.shift [:url] = args[0] when '--version' puts "Sub version #{Sub::VERSION::STRING}" exit 0 else = false end args.shift if end Sub.new(, args) end |
Instance Method Details
#co ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/sub/app.rb', line 76 def co if @args.empty? raise "Please specify a project to check out" end project = args.shift dir_name = args.shift || project svn("co #{url}/#{project}/trunk #{dir_name}") end |
#defaults ⇒ Object
57 58 59 60 61 62 |
# File 'lib/sub/app.rb', line 57 def defaults { :verbosity => NORMAL, :command => :up, } end |
#execute ⇒ Object
64 65 66 |
# File 'lib/sub/app.rb', line 64 def execute self.send(@command) end |
#externals(root) ⇒ Object
131 132 133 |
# File 'lib/sub/app.rb', line 131 def externals(root) Root.new(root, self, clean).externals end |
#help ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/sub/app.rb', line 86 def help puts """ sub - Alex's wrapper for subversion Version: #{Sub::VERSION::STRING} Usage: sub co project_name [dir_name] checks out [base_url]/project_name/trunk into ./project_name (or dir_name if specified) sub up [dir]* fast update (default command, so 'sub dir...' or just 'sub' work too) sub help prints this message Options: --verbose, -v lots of output --quiet, -q no output at all except for errors --help, -h prints this message --clean, -c 'up' command removes all unversioned files and directories --url [base_url] sets base repository url for 'co' command (default is ENV['SUB_BASE_URL'] or ENV['SVN'] or #{DEFAULT_BASE_URL}) --version prints release version """ end |
#parse_externals(st) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/sub/app.rb', line 135 def parse_externals(st) exts = [] st.split("\n").select do |line| line =~ /^X/ end.collect do |line| line.gsub(/^X */, '').gsub(/\/[^\/]*$/, '') end.uniq.collect do |parent| prop = `svn propget svn:externals #{parent}` prop.split("\n").each do |external| next if external.strip.empty? exts << External.new(parent, external, self) end end exts end |
#run(cmd, return_output = false) ⇒ Object
161 162 163 164 165 166 167 168 169 |
# File 'lib/sub/app.rb', line 161 def run(cmd, return_output = false) say("\t#{cmd}") if verbosity == VERBOSE if (return_output) `#{cmd}` else cmd += ">/dev/null"if verbosity == QUIET system(cmd) end end |
#say(msg) ⇒ Object
151 152 153 |
# File 'lib/sub/app.rb', line 151 def say(msg) puts msg if verbosity > QUIET end |
#svn(cmd) ⇒ Object
155 156 157 158 159 |
# File 'lib/sub/app.rb', line 155 def svn(cmd) svncmd = "svn" svncmd += " --quiet" if (cmd =~ /^(up|co)/ && verbosity == QUIET) run("#{svncmd} #{cmd}") end |
#up ⇒ Object
commands
69 70 71 72 73 74 |
# File 'lib/sub/app.rb', line 69 def up if @args.empty? @args = [`pwd`.chomp] end update_many(@args) end |