andela-echigbo/enygma

View on GitHub
bin/decrypt

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

require 'enygma'

if ARGV[0] && (ARGV[0] == 'help' || ARGV[0] == '--help' || ARGV[0] == '-h')
  Enygma::Help.decrypt
elsif ARGV.length < 3 || ARGV.length > 4
  puts "Incorrect number of argument. Run with --help for explanation"
elsif !File.file?(ARGV[0])
  puts "The input file path does not exist. Run with --help for explanation"
elsif ARGV.length == 4 && File.file?(ARGV[1])
  puts "The output file path cannot be created, or file already exist. Run with --help for explanation"
else
  if ARGV.length == 4
    Enygma::Decryptor.new(ARGV[0], ARGV[1], ARGV[2], ARGV[3]).decrypt
  else
    Enygma::Decryptor.new(ARGV[0], ARGV[1], ARGV[2]).decrypt
  end
end