lib/rim/command_helper.rb in esr-rim-1.1.5 vs lib/rim/command_helper.rb in esr-rim-1.2.0
- old
+ new
@@ -2,10 +2,11 @@
require 'rim/processor'
require 'rim/module_info'
require 'rim/rim_info'
require 'rim/manifest/json_reader'
require 'rim/status_builder'
+require 'pathname'
module RIM
class CommandHelper < Processor
@@ -30,11 +31,11 @@
def check_arguments
raise RimException.new("Unexpected command line arguments.") if !ARGV.empty?
end
def create_module_info(remote_url, local_path, target_revision, ignores)
- ModuleInfo.new(remote_url, get_relative_path(local_path), target_revision, ignores, get_remote_branch_format(remote_url))
+ ModuleInfo.new(remote_url, get_relative_path(local_path), target_revision, ignores, remote_url ? get_remote_branch_format(remote_url) : nil)
end
def modules_from_manifest(path)
manifest = read_manifest(path)
manifest.modules.each do |mod|
@@ -44,42 +45,56 @@
end
def modules_from_paths(paths, opts = {})
if paths.empty?
module_from_path(nil, opts)
- elsif paths.length == 1 || opts.empty?
+ elsif paths.length == 1 || !opts.has_key?(:remote_url)
while !paths.empty?
module_from_path(paths.shift, opts)
end
else
- raise RimException.new("Multiple modules cannot be used with additional options.")
+ raise RimException.new("Multiple modules cannot be used with URL option.")
end
end
def module_from_path(path, opts = {})
module_path = find_file_dir_in_workspace(path || ".", RimInfo::InfoFileName)
if module_path
rim_info = RimInfo.from_dir(module_path)
- add_unique_module_info(create_module_info(opts.has_key?(:remote_url) ? opts[:remote_url] : rim_info.remote_url, \
+ module_info = create_module_info(opts.has_key?(:remote_url) ? opts[:remote_url] : rim_info.remote_url, \
module_path, opts.has_key?(:target_revision) ? opts[:target_revision] : rim_info.target_revision, \
- opts.has_key?(:ignores) ? opts[:ignores] : rim_info.ignores))
- module_path
+ opts.has_key?(:ignores) ? opts[:ignores] : rim_info.ignores)
+ if module_info.valid?
+ add_unique_module_info(module_info)
+ module_path
+ else
+ raise RimException.new("Invalid .riminfo file found in directory '#{module_path}'.")
+ end
else
raise RimException.new(path ? "No module info found in '#{path}'." : "No module info found.")
end
end
- def modules_from_workspace()
- if File.directory?(File.join(@ws_root, ".rim"))
- status = StatusBuilder.new.fs_status(@ws_root)
- status.modules.each do |mod|
- rim_info = mod.rim_info
- add_unique_module_info(ModuleInfo.new(rim_info.remote_url, mod.dir, rim_info.upstream, rim_info.ignores))
+ def module_paths(paths, exclude_paths = nil)
+ module_paths = []
+ (paths.empty? ? ['.'] : paths).each do |p|
+ module_paths.concat(all_module_paths_from_path(p))
+ end
+ paths.clear
+ if exclude_paths
+ exclude_paths.each do |e|
+ all_module_paths_from_path(e).each do |p|
+ module_paths.delete(p)
+ end
end
- true
end
+ module_paths.sort
end
-
+
+ def all_module_paths_from_path(path)
+ Dir.glob(File.join(path, "**/.riminfo")).map { |f| Pathname.new(File.expand_path(File.dirname(f))).relative_path_from(Pathname.pwd).to_s }
+ end
+
def add_unique_module_info(module_info)
if !@paths.include?(module_info.local_path)
@paths.push(module_info.local_path)
add_module_info(module_info)
else