Sha256: 60a8302d7d40c2cd6ddc89cca9f3e1438db78c5d186be36e32fc0e348f684304

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require 'thor'
require 'headdesk'
require 'tmpdir'

module Headdesk
  module CliCommands
    #
    # Analyze an APK/IPA file
    #
    module Analyze
      include Headdesk::CliCommand

      def self.included(thor)
        thor.class_eval do
          desc 'analyze [FILE]', 'Analyze an APK or IPA'
          method_option :path, type: :string
          method_option :json, type: :boolean
          def analyze(file = nil)
            # Make sure input file exsts, if specified
            unless !file || File.exist?(file)
              STDERR.puts "Could not find input file: #{file}"
              CLI.command_help(Thor::Base.shell.new, 'analyze')
              exit 1
            end

            # Unpack APK if needed
            path = options[:path]
            tmp_dir = nil
            if file
              path = tmp_dir = Dir.mktmpdir
              Headdesk::ApkTool.unpack_to(file, tmp_dir)
            end

            # Make sure path exists
            unless Dir.exist?(path)
              STDERR.puts "Could not find path: #{path}"
              CLI.command_help(Thor::Base.shell.new, 'analyze')
              exit 1
            end

            # analyze
            begin
              report = Headdesk::Analyze.at(path)

              if options[:json]
                STDOUT.puts report.to_json
              else
                STDOUT.puts report.to_s
                CLI.print_update_message unless Headdesk::Versions.latest_version?
              end
            rescue CliError => cli_err
              STDERR.puts cli_err.message
              CLI.command_help(Thor::Base.shell.new, 'analyze')
              exit 1
            rescue StandardError => err
              STDERR.puts err.message.red
              STDERR.puts err.backtrace.ai
              exit 1
            end
          ensure
            FileUtils.remove_entry(tmp_dir) if tmp_dir
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
headdesk-0.16.0 lib/headdesk/cli_commands/analyze.rb
headdesk-0.15.1 lib/headdesk/cli_commands/analyze.rb
headdesk-0.15.0 lib/headdesk/cli_commands/analyze.rb
headdesk-0.14.0 lib/headdesk/cli_commands/analyze.rb
headdesk-0.13.0 lib/headdesk/cli_commands/analyze.rb
headdesk-0.12.0 lib/headdesk/cli_commands/analyze.rb
headdesk-0.11.3 lib/headdesk/cli_commands/analyze.rb
headdesk-0.11.2 lib/headdesk/cli_commands/analyze.rb
headdesk-0.11.1 lib/headdesk/cli_commands/analyze.rb
headdesk-0.11.0 lib/headdesk/cli_commands/analyze.rb