Class: RepoMgr::CLI
- Inherits:
-
Thor
- Object
- Thor
- RepoMgr::CLI
- Defined in:
- lib/repo_mgr/cli.rb
Overview
implements CLI interface
Class Method Summary collapse
Instance Method Summary collapse
- #add_pkg ⇒ Object
- #check_depends ⇒ Object
- #check_sig ⇒ Object
- #dl_repo ⇒ Object
- #export ⇒ Object
- #list_pkgs ⇒ Object
- #list_repos ⇒ Object
- #rebuild_pkg_list ⇒ Object
- #remove_pkg ⇒ Object
- #sync ⇒ Object
- #upsert_repo ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
16 17 18 |
# File 'lib/repo_mgr/cli.rb', line 16 def self.exit_on_failure? true end |
.publishers ⇒ Object
24 25 26 |
# File 'lib/repo_mgr/cli.rb', line 24 def self.publishers %w[git] end |
.types ⇒ Object
20 21 22 |
# File 'lib/repo_mgr/cli.rb', line 20 def self.types %w[deb rpm] end |
Instance Method Details
#add_pkg ⇒ Object
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 [:path] backend.add_pkg [:repo], [:path] config.add_pkg [:repo], [:path] pub_type = config.cfg[:repos][[:repo]][:publisher] if pub_type publisher = Publishers.load pub_type, config publisher.save [:repo], [:path] end puts "-- Added #{File.basename([:path])} to "\ "#{[:repo]} repository" end |
#check_depends ⇒ Object
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_sig ⇒ Object
167 168 169 170 |
# File 'lib/repo_mgr/cli.rb', line 167 def check_sig backend, _config = load_backend [:path] puts backend.check_sig [:path] end |
#dl_repo ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/repo_mgr/cli.rb', line 100 def dl_repo backend, config = load_backend [:type] pkgs = backend.dl_repo pkgs.each do |pkg| config.add_pkg [:repo], pkg end end |
#export ⇒ Object
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][[:repo]][:type], config backend.export [:repo] puts "-- Exported #{[:repo]} repo" end |
#list_pkgs ⇒ Object
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][[:repo]] if packages.nil? Tools.error "#{[: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 #{[:repo]}"], rows: rows end |
#list_repos ⇒ Object
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_list ⇒ Object
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][[:repo]][:type], config pkgs = backend.rebuild_pkg_list [:repo] pkgs.each do |pkg| config.add_pkg [:repo], pkg end puts "-- Rebuilt #{[:repo]} repo pkg list" end |
#remove_pkg ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/repo_mgr/cli.rb', line 154 def remove_pkg backend, config = load_backend [:path] backend.remove_pkg [:repo], [:path] config.remove_pkg [:repo], [:path] puts "-- Removed #{File.basename([:path])} from "\ "#{[:repo]} repository" end |
#sync ⇒ Object
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][[:repo]][:publisher] unless pub_type Tools.error "#{[:repo]} repo does not have a publisher" end publisher = Publishers.load pub_type, config publisher.sync [:repo] puts "-- Synchronised #{[:repo]} using #{pub_type} publisher" end |