lib/ronin/ui/cli/commands/repos.rb in ronin-1.3.0 vs lib/ronin/ui/cli/commands/repos.rb in ronin-1.4.0.rc1
- old
+ new
@@ -27,227 +27,114 @@
#
# The `ronin-repos` command.
#
class Repos < ModelCommand
- desc 'Manages Ronin repositories'
- class_option :add, :type => :string,
- :aliases => '-A',
- :banner => 'PATH'
- class_option :install, :type => :string,
- :aliases => '-I',
- :banner => 'URI'
- class_option :list, :type => :boolean,
- :aliases => '-l'
- class_option :update, :type => :boolean,
- :aliases => '-u'
- class_option :uninstall, :type => :string,
- :aliases => '-U',
- :banner => 'REPO'
- class_option :scm, :type => :string, :aliases => '-S'
+ summary 'Lists Ronin Repositories'
- class_option :rsync, :type => :boolean
- class_option :svn, :type => :boolean
- class_option :hg, :type => :boolean
- class_option :git, :type => :boolean
+ model Repository
- argument :name, :type => :string, :required => false
+ query_option :domain, :type => String,
+ :description => 'Domain to filter by'
+ query_option :named, :type => String,
+ :flag => '-n',
+ :usage => 'NAME',
+ :description => 'Name to filter by'
+
+ query_option :titled, :type => String,
+ :flag => '-t',
+ :usage => 'TITLE',
+ :description => 'Title to filter by'
+
+ query_option :describing, :type => String,
+ :flag => '-d',
+ :usage => 'DESC',
+ :desc => 'Description to filter by'
+
+ query_option :licensed_under, :type => String,
+ :flag => '-L',
+ :usage => 'LICENSE',
+ :description => 'License to filter by'
+
+ argument :repo, :type => String,
+ :description => 'Repository to list'
+
#
# Executes the command.
#
def execute
- if options[:add]
- add options[:add]
- elsif options[:install]
- install options[:install]
- elsif options.update?
- update
- elsif options[:uninstall]
- uninstall options[:uninstall]
+ if repo?
+ repository = begin
+ Repository.find(@repo)
+ rescue RepositoryNotFound => e
+ print_error e.message
+ exit -1
+ end
+
+ print_repository(repository)
else
- list
+ print_array query
end
end
protected
#
- # The selected SCM.
+ # Prints information about a Repository.
#
- # @return [Symbol]
- # The name of the selected SCM.
- #
- def scm
- @scm ||= if options[:scm]
- options[:scm].to_sym
- elsif options.rsync?
- :rsync
- elsif options.svn?
- :sub_version
- elsif options.hg?
- :mercurial
- elsif options.git?
- :git
- end
- end
-
- #
- # Print out any exceptions or validation errors encountered
- # when caching the files of the repository.
- #
# @param [Repository] repo
- # The repository that was updated.
+ # The repository to print.
#
- def print_cache_errors(repo)
- repo.cached_files.each do |cached_file|
- if cached_file.cache_exception
- print_exception cached_file.cache_exception
- end
+ def print_repository(repo)
+ print_title repo.name
- if cached_file.cache_errors
- cached_file.cache_errors.each do |error|
- print_error error
- end
+ indent do
+ if repo.installed?
+ puts "Domain: #{repo.domain}"
+ else
+ puts "Path: #{repo.path}"
end
- end
- end
- #
- # Lists installed or added Repositories.
- #
- def list
- unless name
- print_array Repository.all
- else
- repo = begin
- [Repository.find(name)]
- rescue RepositoryNotFound => e
- print_error e.message
- exit -1
- end
+ puts "SCM: #{repo.scm}" if repo.scm
- print_title repo.name
+ if repo.verbose?
+ putc "\n"
- indent do
- if repo.installed?
- puts "Domain: #{repo.domain}"
- else
- puts "Path: #{repo.path}"
- end
+ puts "Title: #{repo.title}" if repo.title
+ puts "URI: #{repo.uri}" if repo.uri
+ puts "Source URI: #{repo.source}" if repo.source
+ puts "Website: #{repo.website}" if repo.website
- puts "SCM: #{repo.scm}" if repo.scm
+ executables = repo.executables
- if repo.verbose?
- putc "\n"
+ unless executables.empty?
+ puts "Executables: #{executables.join(', ')}"
+ end
- puts "Title: #{repo.title}" if repo.title
- puts "URI: #{repo.uri}" if repo.uri
- puts "Source URI: #{repo.source}" if repo.source
- puts "Website: #{repo.website}" if repo.website
+ putc "\n"
- executables = repo.executables
+ unless repo.script_paths.empty?
+ print_title 'Cached Files'
- unless executables.empty?
- puts "Executables: #{executables.join(', ')}"
- end
-
- putc "\n"
-
- unless repo.cached_files.empty?
- print_title 'Cached Files'
-
- indent do
- repo.cached_files.each do |cached_file|
- puts cached_file.path
- end
+ indent do
+ repo.script_paths.each do |script_path|
+ puts script_path.path
end
end
+ end
- if repo.description
- print_title "Description"
+ if repo.description
+ print_title "Description"
- indent { puts "#{repo.description}\n\n" }
- else
- putc "\n"
- end
+ indent { puts "#{repo.description}\n\n" }
else
putc "\n"
end
+ else
+ putc "\n"
end
end
- end
-
- #
- # Adds a Repository.
- #
- # @param [String] path
- # The path of the local repository.
- #
- def add(path)
- repo = begin
- Repository.add!(:path => path, :scm => @scm)
- rescue DuplicateRepository => e
- print_error e.message
- exit -1
- end
-
- print_info "Repository #{repo} added."
- end
-
- #
- # Installs a Repository.
- #
- # @param [String, URI] uri
- # The URI of the remote repository.
- #
- def install(uri)
- repo = begin
- Repository.install!(:uri => uri, :scm => scm)
- rescue DuplicateRepository => e
- print_error e.message
- exit -1
- end
-
- print_cache_errors(repo)
- print_info "Repository #{repo} has been installed."
- end
-
- #
- # Updates installed Repositories.
- #
- def update
- repos = if name
- begin
- [Repository.find(name)]
- rescue RepositoryNotFound => e
- print_error e.message
- exit -1
- end
- else
- Repository.all
- end
-
- repos.each do |repo|
- print_info "Updating repository #{repo} ..."
-
- repo.update!
-
- print_cache_errors(repo)
- print_info "Repository updated."
- end
- end
-
- #
- # Uninstalls a Repository.
- #
- # @param [String] name
- # The name of the repository.
- #
- def uninstall(name)
- repo = Repository.uninstall!(name)
-
- print_info "Uninstalling repository #{repo} ..."
end
end
end
end