Class: Ronin::UI::CLI::Commands::Repos
- Inherits:
-
ModelCommand
- Object
- Thor::Group
- Ronin::UI::CLI::Command
- ModelCommand
- Ronin::UI::CLI::Commands::Repos
- Defined in:
- lib/ronin/ui/cli/commands/repos.rb
Overview
The ronin-repos
command.
Instance Method Summary collapse
-
#add(path) ⇒ Object
protected
Adds a Repository.
-
#execute ⇒ Object
Executes the command.
-
#install(uri) ⇒ Object
protected
Installs a Repository.
-
#list ⇒ Object
protected
Lists installed or added Repositories.
-
#print_cache_errors(repo) ⇒ Object
protected
Print out any exceptions or validation errors encountered when caching the files of the repository.
-
#scm ⇒ Symbol
protected
The selected SCM.
-
#uninstall(name) ⇒ Object
protected
Uninstalls a Repository.
-
#update ⇒ Object
protected
Updates installed Repositories.
Methods inherited from ModelCommand
each_query_option, model, #query, query_option, query_options, #setup
Methods inherited from Ronin::UI::CLI::Command
banner, command_name, #indent, inherited, #initialize, #print_array, #print_exception, #print_hash, #print_section, #print_title, #puts, run, #setup
Constructor Details
This class inherits a constructor from Ronin::UI::CLI::Command
Instance Method Details
#add(path) ⇒ Object (protected)
Adds a Repository.
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ronin/ui/cli/commands/repos.rb', line 186 def add(path) repo = begin Repository.add!(:path => path, :scm => @scm) rescue DuplicateRepository => e print_error e. exit -1 end print_info "Repository #{repo} added." end |
#execute ⇒ Object
Executes the command.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ronin/ui/cli/commands/repos.rb', line 58 def execute if [:add] add [:add] elsif [:install] install [:install] elsif .update? update elsif [:uninstall] uninstall [:uninstall] else list end end |
#install(uri) ⇒ Object (protected)
Installs a Repository.
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/ronin/ui/cli/commands/repos.rb', line 203 def install(uri) repo = begin Repository.install!(:uri => uri, :scm => scm) rescue DuplicateRepository => e print_error e. exit -1 end print_cache_errors(repo) print_info "Repository #{repo} has been installed." end |
#list ⇒ Object (protected)
Lists installed or added Repositories.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ronin/ui/cli/commands/repos.rb', line 118 def list unless name print_array Repository.all else repo = begin [Repository.find(name)] rescue RepositoryNotFound => e print_error e. exit -1 end print_title repo.name indent do if repo.installed? puts "Domain: #{repo.domain}" else puts "Path: #{repo.path}" end puts "SCM: #{repo.scm}" if repo.scm if repo.verbose? putc "\n" 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 executables = repo.executables 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 end end if repo.description print_title "Description" indent { puts "#{repo.description}\n\n" } else putc "\n" end else putc "\n" end end end end |
#print_cache_errors(repo) ⇒ Object (protected)
Print out any exceptions or validation errors encountered when caching the files of the repository.
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ronin/ui/cli/commands/repos.rb', line 101 def print_cache_errors(repo) repo.cached_files.each do |cached_file| if cached_file.cache_exception print_exception cached_file.cache_exception end if cached_file.cache_errors cached_file.cache_errors.each do |error| print_error error end end end end |
#scm ⇒ Symbol (protected)
The selected SCM.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ronin/ui/cli/commands/repos.rb', line 80 def scm @scm ||= if [:scm] [:scm].to_sym elsif .rsync? :rsync elsif .svn? :sub_version elsif .hg? :mercurial elsif .git? :git end end |
#uninstall(name) ⇒ Object (protected)
Uninstalls a Repository.
246 247 248 249 250 |
# File 'lib/ronin/ui/cli/commands/repos.rb', line 246 def uninstall(name) repo = Repository.uninstall!(name) print_info "Uninstalling repository #{repo} ..." end |
#update ⇒ Object (protected)
Updates installed Repositories.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/ronin/ui/cli/commands/repos.rb', line 218 def update repos = if name begin [Repository.find(name)] rescue RepositoryNotFound => e print_error e. 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 |