<commit_before>require_relative '../ec2'

namespace :ec2 do

  desc 'share ami'
  task :share_ami, [:image_id, :user_id]  do |t, args|
    AwsPocketknife::Ec2.share_ami(image_id: args[:instance_id], user_id: args[:instance_id])
  end

  desc 'Stop instance by id'
  task :stop_by_id, [:instance_id]  do |t, args|
    AwsPocketknife::Ec2.stop_instance_by_id(args[:instance_id])
  end

  desc 'Start instance by id'
  task :start_by_id, [:instance_id]  do |t, args|
    AwsPocketknife::Ec2.start_instance_by_id(args[:instance_id])
  end

  desc 'Describe instance by id'
  task :describe_instance_by_id, [:instance_id]  do |t, args|
    instance = AwsPocketknife::Ec2.describe_instance_by_id(instance_id: args[:instance_id])
    if instance.nil?
      puts "Instance #{args[:instance_id]} not found"
    else
      AwsPocketknife::Ec2.nice_print(object: instance.to_h)
    end
  end

  desc 'Describe instance by name'
  task :describe_instance_by_name, [:name]  do |t, args|
    instances = AwsPocketknife::Ec2.describe_instances_by_name(name: args[:name])
    headers = ["name", "id", "image", "state", "private ip", "public ip", "type", "key name", "launch time"]
    data = []
    if instances.length > 0
      instances.each do |instance|
        name = AwsPocketknife::Ec2.get_tag_value(tags: instance.tags, tag_key: "Name")
        data << [name, instance.instance_id, instance.image_id, instance.state.name,
                 instance.private_ip_address, instance.public_ip_address, instance.instance_type,
                instance.key_name, instance.launch_time]
      end
      AwsPocketknife::Ec2.pretty_table(headers: headers, data: data)
    else
      puts "No instance(s) found for name #{args[:name]}"
    end
  end

  desc 'Get windows password'<commit_msg>alias to find instances by name<commit_after>require_relative '../ec2'

namespace :ec2 do

  desc 'share ami'
  task :share_ami, [:image_id, :user_id]  do |t, args|
    AwsPocketknife::Ec2.share_ami(image_id: args[:instance_id], user_id: args[:instance_id])
  end

  desc 'Stop instance by id'
  task :stop_by_id, [:instance_id]  do |t, args|
    AwsPocketknife::Ec2.stop_instance_by_id(args[:instance_id])
  end

  desc 'Start instance by id'
  task :start_by_id, [:instance_id]  do |t, args|
    AwsPocketknife::Ec2.start_instance_by_id(args[:instance_id])
  end

  desc 'Describe instance by id'
  task :describe_instance_by_id, [:instance_id]  do |t, args|
    instance = AwsPocketknife::Ec2.describe_instance_by_id(instance_id: args[:instance_id])
    if instance.nil?
      puts "Instance #{args[:instance_id]} not found"
    else
      AwsPocketknife::Ec2.nice_print(object: instance.to_h)
    end
  end

  desc 'Describe instance by name'
  task :describe_instance_by_name, [:name]  do |t, args|
    instances = AwsPocketknife::Ec2.describe_instances_by_name(name: args[:name])
    headers = ["name", "id", "image", "state", "private ip", "public ip", "type", "key name", "launch time"]
    data = []
    if instances.length > 0
      instances.each do |instance|
        name = AwsPocketknife::Ec2.get_tag_value(tags: instance.tags, tag_key: "Name")
        data << [name, instance.instance_id, instance.image_id, instance.state.name,
                 instance.private_ip_address, instance.public_ip_address, instance.instance_type,
                instance.key_name, instance.launch_time]
      end
      AwsPocketknife::Ec2.pretty_table(headers: headers, data: data)
    else
      puts "No instance(s) found for name #{args[:name]}"
    end
  end

  desc 'Find instances by name'
  task :find_instances_by_name, [:name]  do |t, args|
    Rake::Task["ec2:describe_instance_by_name"].invoke(args[:name])
  end

  desc 'Get windows password'
{'fraction_non_alphanumeric': 0.12335393711367912, 'fraction_numerical': 0.006181134103735555, 'mean_word_length': 4.02972972972973, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6325338', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1305, 'n_words': 299}