Class: RepoMgr::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/repo_mgr/cli.rb

Overview

implements CLI interface

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/repo_mgr/cli.rb', line 16

def self.exit_on_failure?
  true
end

.publishersObject



24
25
26
# File 'lib/repo_mgr/cli.rb', line 24

def self.publishers
  %w[git]
end

.typesObject



20
21
22
# File 'lib/repo_mgr/cli.rb', line 20

def self.types
  %w[deb rpm]
end

Instance Method Details

#add_pkgObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/repo_mgr/cli.rb', line 116

def add_pkg
  backend, config = load_backend options[:path]
  backend.add_pkg options[:repo], options[:path]
  config.add_pkg options[:repo], options[:path]

  pub_type = config.cfg[:repos][options[:repo]][:publisher]
  if pub_type
    publisher = Publishers.load pub_type, config
    publisher.save options[:repo], options[:path]
  end

  puts "-- Added #{File.basename(options[:path])} to "\
       "#{options[:repo]} repository"
end

#check_dependsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/repo_mgr/cli.rb', line 30

def check_depends
  rows = []
  deps = {
    'aptly' => 'Manage apt repository',
    'dpkg-sig' => 'Sign deb packages',
    'createrepo' => 'Manage rpm repository',
    'rpm' => 'Sign rpm packages',
    'git' => 'Use git publisher'
  }

  deps.each do |bin_dep, purpose|
    rows << which_depends(bin_dep, purpose)
  end

  puts Terminal::Table.new headings: %w[Binary Status Purpose], rows: rows
end

#check_sigObject



167
168
169
170
# File 'lib/repo_mgr/cli.rb', line 167

def check_sig
  backend, _config = load_backend options[:path]
  puts backend.check_sig options[:path]
end

#dl_repoObject



100
101
102
103
104
105
106
107
108
# File 'lib/repo_mgr/cli.rb', line 100

def dl_repo
  backend, config = load_backend options[:type]

  pkgs = backend.dl_repo options

  pkgs.each do |pkg|
    config.add_pkg options[:repo], pkg
  end
end

#exportObject



207
208
209
210
211
212
213
214
# File 'lib/repo_mgr/cli.rb', line 207

def export
  config = Config.new
  backend = Backends.load config.cfg[:repos][options[:repo]][:type], config

  backend.export options[:repo]

  puts "-- Exported #{options[:repo]} repo"
end

#list_pkgsObject



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/repo_mgr/cli.rb', line 135

def list_pkgs
  packages = Config.new.cfg[:packages][options[:repo]]

  if packages.nil?
    Tools.error "#{options[:repo]} repo does not have any packages"
  end

  rows = packages.sort.each_with_index.map { |e, i| [i + 1, e] }

  puts Terminal::Table.new headings: ['#', "Packages in #{options[:repo]}"],
                           rows: rows
end

#list_reposObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/repo_mgr/cli.rb', line 73

def list_repos
  rows = []
  config = Config.new

  config.cfg[:repos].each do |name, repo|
    rows << [name, repo[:type], repo[:path], repo[:keyid], repo[:publisher]]
  end

  return puts '-- No repos have been created' if rows.count.zero?

  puts Terminal::Table.new(
    headings: %w[Name Type Path KeyID Publisher], rows: rows
  )
end

#rebuild_pkg_listObject



175
176
177
178
179
180
181
182
183
184
185
# File 'lib/repo_mgr/cli.rb', line 175

def rebuild_pkg_list
  config = Config.new
  backend = Backends.load config.cfg[:repos][options[:repo]][:type], config
  pkgs = backend.rebuild_pkg_list options[:repo]

  pkgs.each do |pkg|
    config.add_pkg options[:repo], pkg
  end

  puts "-- Rebuilt #{options[:repo]} repo pkg list"
end

#remove_pkgObject



154
155
156
157
158
159
160
161
# File 'lib/repo_mgr/cli.rb', line 154

def remove_pkg
  backend, config = load_backend options[:path]
  backend.remove_pkg options[:repo], options[:path]
  config.remove_pkg options[:repo], options[:path]

  puts "-- Removed #{File.basename(options[:path])} from "\
       "#{options[:repo]} repository"
end

#syncObject



190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/repo_mgr/cli.rb', line 190

def sync
  config = Config.new
  pub_type = config.cfg[:repos][options[:repo]][:publisher]

  unless pub_type
    Tools.error "#{options[:repo]} repo does not have a publisher"
  end

  publisher = Publishers.load pub_type, config
  publisher.sync options[:repo]

  puts "-- Synchronised #{options[:repo]} using #{pub_type} publisher"
end

#upsert_repoObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/repo_mgr/cli.rb', line 59

def upsert_repo
  FileUtils.mkdir_p options[:path]

  config = Config.new
  config.upsert_repo options

  backend = Backends.load options[:type], config
  backend.add_repo options[:name]

  puts "-- Upserted #{options[:name]} repository"
end