Rename from Picop to Picopackage
This commit is contained in:
104
lib/picopackage/cli.rb
Normal file
104
lib/picopackage/cli.rb
Normal file
@@ -0,0 +1,104 @@
|
||||
require "optparse"
|
||||
|
||||
module Picopackage
|
||||
class CLI
|
||||
def self.run(argv = ARGV)
|
||||
command = argv.shift
|
||||
case command
|
||||
when 'scan'
|
||||
options = {}
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: ppkg scan [options] DIRECTORY"
|
||||
# opts.on('-v', '--verbose', 'Run verbosely') { |v| options[:verbose] = v }
|
||||
end.parse!(argv)
|
||||
|
||||
dir = argv.first || '.'
|
||||
Picopackage::Scanner.scan(dir).each {|f| puts f.file_path }
|
||||
|
||||
when 'sign'
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: ppkg sign FILE"
|
||||
end.parse!(argv)
|
||||
|
||||
file = argv.first
|
||||
Picopackage::SourceFile.from_file(file).sign
|
||||
|
||||
when 'checksum'
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: ppkg checksum FILE"
|
||||
end.parse!(argv)
|
||||
file = argv.first
|
||||
puts Picopackage::SourceFile.from_file(file).checksum
|
||||
|
||||
when 'verify'
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: ppkg sign FILE"
|
||||
end.parse!(argv)
|
||||
|
||||
path = argv.first
|
||||
source = SourceFile.from_file(path)
|
||||
|
||||
if source.metadata['content_checksum'].nil?
|
||||
puts "⚠️ No checksum found in #{path}"
|
||||
puts "Run 'ppkg sign #{path}' to add one"
|
||||
exit 1
|
||||
end
|
||||
|
||||
unless source.verify
|
||||
puts "❌ Checksum verification failed for #{path}"
|
||||
puts "Expected: #{source.metadata['content_checksum']}"
|
||||
puts "Got: #{source.checksum}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
puts "✅ #{path} verified successfully"
|
||||
|
||||
when 'inspect'
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: ppkg inspect FILE|DIRECTORY"
|
||||
end.parse!(argv)
|
||||
|
||||
path = argv.first
|
||||
Picopackage::SourceFile.from_file(path).inspect
|
||||
|
||||
when 'fetch'
|
||||
options = { force: false }
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: ppkg fetch [options] URI [PATH]"
|
||||
opts.on('-f', '--force', 'Force fetch') { |f| options[:force] = f }
|
||||
end.parse!(argv)
|
||||
|
||||
url = argv.shift
|
||||
path = argv.shift || '.' # use '.' if no path provided
|
||||
|
||||
if url.nil?
|
||||
puts "Error: URI is required"
|
||||
exit 1
|
||||
end
|
||||
|
||||
begin
|
||||
source_file = Fetch.fetch(url, path, force: options[:force])
|
||||
rescue LocalModificationError => e
|
||||
puts "Error: #{e.message}"
|
||||
rescue => e
|
||||
puts "Error: #{e.message}"
|
||||
exit 1
|
||||
# Optionally retry with force
|
||||
# source_file = Fetch.fetch(url, destination, force: true)
|
||||
end
|
||||
|
||||
else
|
||||
puts "Unknown command: #{command}"
|
||||
puts "Available commands: scan, sign, inspect, update"
|
||||
exit 1
|
||||
end
|
||||
rescue OptionParser::InvalidOption => e
|
||||
puts e.message
|
||||
exit 1
|
||||
rescue => e
|
||||
puts "Error: #{e.message}"
|
||||
puts e.backtrace if ENV['DEBUG']
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user