Initial import

This commit is contained in:
Dan Milne
2025-01-19 10:42:59 +11:00
commit 05d55ca665
20 changed files with 439 additions and 0 deletions

88
lib/picop/cli.rb Normal file
View File

@@ -0,0 +1,88 @@
require "optparse"
module Picop
class CLI
def self.run(argv = ARGV)
command = argv.shift
case command
when 'scan'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: picop scan [options] DIRECTORY"
opts.on('-v', '--verbose', 'Run verbosely') { |v| options[:verbose] = v }
end.parse!(argv)
dir = argv.first || '.'
Picop::Scanner.scan(dir, options)
when 'sign'
OptionParser.new do |opts|
opts.banner = "Usage: picop sign FILE"
end.parse!(argv)
file = argv.first
Picop::SourceFile.new(file).sign
when 'checksum'
OptionParser.new do |opts|
opts.banner = "Usage: picop checksum FILE"
end.parse!(argv)
file = argv.first
puts Picop::SourceFile.new(file).checksum
when 'verify'
OptionParser.new do |opts|
opts.banner = "Usage: picop sign FILE"
end.parse!(argv)
path = argv.first
source = SourceFile.new(path)
if source.metadata['content_checksum'].nil?
puts "⚠️ No checksum found in #{path}"
puts "Run 'picop 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 'show'
OptionParser.new do |opts|
opts.banner = "Usage: picop show FILE|DIRECTORY"
end.parse!(argv)
path = argv.first
Picop.show(path)
when 'update'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: picop update [options] FILE"
opts.on('-f', '--force', 'Force update') { |f| options[:force] = f }
end.parse!(argv)
file = argv.first
Picop.update(file, options)
else
puts "Unknown command: #{command}"
puts "Available commands: scan, sign, show, 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