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
- #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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/repo_mgr/cli.rb', line 91 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 |
# File 'lib/repo_mgr/cli.rb', line 30 def check_depends rows = [] %w[aptly dpkg-sig createrepo rpm git].each do |bin_dep| rows << if Tools.which bin_dep [bin_dep, '✔'.green] else [bin_dep, '✘'.red] end end puts Terminal::Table.new headings: %w[Binary Status], rows: rows end |
#check_sig ⇒ Object
142 143 144 145 |
# File 'lib/repo_mgr/cli.rb', line 142 def check_sig backend, _config = load_backend [:path] puts backend.check_sig [:path] end |
#list_pkgs ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/repo_mgr/cli.rb', line 110 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
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/repo_mgr/cli.rb', line 70 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
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/repo_mgr/cli.rb', line 150 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
129 130 131 132 133 134 135 136 |
# File 'lib/repo_mgr/cli.rb', line 129 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
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/repo_mgr/cli.rb', line 165 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 |