Initial import
This commit is contained in:
88
lib/picop/cli.rb
Normal file
88
lib/picop/cli.rb
Normal 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
|
||||
Reference in New Issue
Block a user