Sha256: 17c1c35e977e3fb3c272ce3aa563d8baf492ceeb455e8bbe718f48c2ea504c1d
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
command :serve do |c| c.syntax = 'pk serve [PASSNAME]' c.summary = 'Serves a .pkpass archive from a webserver' c.description = '' c.example 'description', 'pk archive mypass' c.option '-c', '--certificate /path/to/cert.pem', 'Pass certificate' c.option '-p', '--[no]-password', 'Prompt for certificate password' c.option '-H', '--host [HOST]', 'Host to bind to' c.action do |args, options| determine_directory! unless @directory = args.first validate_directory! @certificate = options.certificate validate_certificate! @password = ask("Enter certificate password:"){|q| q.echo = false} if options.password Dubai::Passbook.certificate, Dubai::Passbook.password = @certificate, @password Dubai::Server.set :directory, @directory Dubai::Server.set :bind, options.host if options.host Dubai::Server.run! end end # alias_command :serve, :preview # alias_command :serve, :s private def determine_directory! files = Dir['*/pass.json'] @directory ||= case files.length when 0 then nil when 1 then File.dirname(files.first) else @directory = choose "Select a directory:", *files.collect{|f| File.dirname(f)} end end def validate_directory! say_error "Missing argument" and abort if @directory.nil? say_error "Directory #{@directory} does not exist" and abort unless File.directory?(@directory) say_error "Directory #{@directory} is not valid pass" and abort unless File.exist?(File.join(@directory, "pass.json")) end def validate_certificate! say_error "Missing or invalid certificate file" and abort if @certificate.nil? or not File.exist?(@certificate) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dubai-0.1.2 | ./lib/dubai/commands/serve.rb |
dubai-0.1.1 | ./lib/dubai/commands/serve.rb |