Sha256: f50184e11d2b12bd301a2d40de210bfdb0522cdcb69c757e18f7677792f1690d

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

command :build do |c|
  c.syntax = 'pk build [PASSNAME]'
  c.summary = 'Creates a .pkpass archive'
  c.description = ''

  c.example 'description', 'pk archive mypass -o mypass.pkpass'
  c.option '-c', '--certificate /path/to/cert.pem', 'Pass certificate'
  c.option '-p', '--[no]-password', 'Prompt for certificate password'
  c.option '-o', '--output /path/to/out.pkpass', '.pkpass output filepath'

  c.action do |args, options|
    determine_directory! unless @directory = args.first
    validate_directory!

    @filepath = options.output || "#{@directory}.pkpass"
    validate_output_filepath!

    @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

    File.open(@filepath, 'w') do |f|
      f.write Dubai::Passbook::Pass.new(@directory).pkpass.string
    end
  end
end

# alias_command :build, :archive
# alias_command :build, :b

private

def validate_output_filepath!
  say_error "Filepath required" and abort if @filepath.nil? or @filepath.empty?
  say_error "#{@filepath} already exists" and abort if File.exist?(@filepath)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dubai-0.0.1 ./lib/dubai/commands/build.rb