Class: Ronin::UI::CLI::Commands::Repos

Inherits:
ModelCommand show all
Defined in:
lib/ronin/ui/cli/commands/repos.rb

Overview

The ronin-repos command.

Instance Method Summary collapse

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.

Parameters:

  • path (String)

    The path of the local 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.message
           exit -1
         end

  print_info "Repository #{repo} added."
end

#executeObject

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 options[:add]
    add options[:add]
  elsif options[:install]
    install options[:install]
  elsif options.update?
    update
  elsif options[:uninstall]
    uninstall options[:uninstall]
  else
    list
  end
end

#install(uri) ⇒ Object (protected)

Installs a Repository.

Parameters:

  • uri (String, URI)

    The URI of the remote 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.message
           exit -1
         end

  print_cache_errors(repo)
  print_info "Repository #{repo} has been installed."
end

#listObject (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.message
             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 out any exceptions or validation errors encountered when caching the files of the repository.

Parameters:

  • repo (Repository)

    The repository that was updated.



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

#scmSymbol (protected)

The selected SCM.

Returns:

  • (Symbol)

    The name of 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 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

#uninstall(name) ⇒ Object (protected)

Uninstalls a Repository.

Parameters:

  • name (String)

    The name of the 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

#updateObject (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.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