<commit_before>defmodule Mix.Releases.Runtime.Control do
  @moduledoc """
  This module defines the tooling for interacting with nodes, as well
  as other utiltiy functions of use.
  """
  use Artificery

  require Record

  rec = Record.extract(:etop_proc_info, from_lib: "runtime_tools/include/observer_backend.hrl")
  Record.defrecordp(:etop_proc_info, rec)

  alias Artificery.Console

  defoption(
    :name,
    :string,
    "The name of the remote node to connect to.\n" <>
      "Can be in either long form (i.e. 'foo@bar') or short form (i.e. 'foo')"
  )

  defoption(
    :cookie,
    :string,
    "The distribution cookie to use when connecting to peers",
    transform: &String.to_atom/1
  )

  option(:verbose, :boolean, "Turns on verbose output", alias: :v)

  # Basic management tasks
  command :ping, "Pings the remote node" do
    option(:cookie, required: true)
    option(:peer, :string, "The node name of the peer to ping")
  end

  # Stub for `describe`
  command(:start, "Starts the remote node")

  command :stop, "Stops the remote node" do
    option(:name)
    option(:cookie)
  end

  command :restart, "Restarts the remote node. This will not restart the emulator" do
    option(:name)
    option(:cookie)
  end

  command :reboot, "Reboots the remote node. This will restart the emulator" do
    option(:name)
    option(:cookie)
  end

  # Stub for `describe`
  command(:attach, "Attach directly to the remote node's console")

  # Stub for `describe`
  command(:remote_console, "Connect to the remote node via remote shell")

  # Stub for `describe`
  command(:foreground, "Run the release in the foreground")

  # Upgrade management tasks
  command :unpack, "Unpacks a release upgrade for installation" do
    option(:name)
    option(:cookie)
    option(:release, :string, "The release name", required: true, hidden: true)

    argument(:version, :string, "The release version to unpack", required: true)
  end

  command :install, "Installs a release upgrade" do
    option(:name)
    option(:cookie)
    option(:release, :string, "The release name", required: true, hidden: true)

    argument(:version, :string, "The release version to install", required: true)
  end

  # Configuration tasks
  command :reload_config, "Reloads the config of the remote node" do
    option(:name)
    option(:cookie)
    option(:sysconfig, :string, "The path to a sys.config file")
  end

  command :rpc, "Executes the provided expression on the remote node" do
    option(:name)
    option(:cookie)
    option(:file, :string, "Evaluate a file instead of an expression")

    argument(:expr, :string, "The expression to evaluate", required: true)
  end

  command(:eval, "Executes the provided expression in a clean node") do
    option(:file, :string, "Evaluate a file instead of an expression")
    argument(:expr, :string, "The expression to evaluate")
  end

  command :escript, "Executes the given escript" do
    argument(:path, :string, "The path to the escript to execute")
  end

  command :info, "Prints information about the remote node to stdout" do
    option(:name)
    option(:cookie)

    command :processes, [callback: :processes_info], "Show a table of running processes" do
      option(
        :sort_by,
        :string,
        "Sets the sort column (default: memory)\n" <>
          "Valid types are: reductions, memory, message_queue, name, current_function, pid",
        transform: :to_process_info_sort_by
      )
    end
  end

  command :describe, "Describes the currently installed release" do
    option(:name)
    option(:cookie)
    option(:release_root_dir, :string, "The root directory for all releases")
    option(:sysconfig, :string, "The path to the sys.config file used by the release")
    option(:vmargs, :string, "The path to the vm.args file used by the release")
    option(:erl_opts, :string, "Extra options for erl")
    option(:run_erl_env, :string, "Extra configuration for run_erl")
  end

  @doc """
  This function executes before any commands are dispatched
  """
  @impl Artificery
  def pre_dispatch(_cmd, _argv, %{name: name, cookie: cookie} = opts) do
    # If required, it means we need to connect to the remote node
    {:ok, peer, name, type} = start_distribution!(name, cookie)

    new_opts =
      opts
      |> Map.put(:name, name)
      |> Map.put(:peer, peer)
      |> Map.put(:name_type, type)<commit_msg>Fix #468 - Add missing flag definition for --release<commit_after>defmodule Mix.Releases.Runtime.Control do
  @moduledoc """
  This module defines the tooling for interacting with nodes, as well
  as other utiltiy functions of use.
  """
  use Artificery

  require Record

  rec = Record.extract(:etop_proc_info, from_lib: "runtime_tools/include/observer_backend.hrl")
  Record.defrecordp(:etop_proc_info, rec)

  alias Artificery.Console

  defoption(
    :name,
    :string,
    "The name of the remote node to connect to.\n" <>
      "Can be in either long form (i.e. 'foo@bar') or short form (i.e. 'foo')"
  )

  defoption(
    :cookie,
    :string,
    "The distribution cookie to use when connecting to peers",
    transform: &String.to_atom/1
  )

  option(:verbose, :boolean, "Turns on verbose output", alias: :v)

  # Basic management tasks
  command :ping, "Pings the remote node" do
    option(:cookie, required: true)
    option(:peer, :string, "The node name of the peer to ping")
  end

  # Stub for `describe`
  command(:start, "Starts the remote node")

  command :stop, "Stops the remote node" do
    option(:name)
    option(:cookie)
  end

  command :restart, "Restarts the remote node. This will not restart the emulator" do
    option(:name)
    option(:cookie)
  end

  command :reboot, "Reboots the remote node. This will restart the emulator" do
    option(:name)
    option(:cookie)
  end

  # Stub for `describe`
  command(:attach, "Attach directly to the remote node's console")

  # Stub for `describe`
  command(:remote_console, "Connect to the remote node via remote shell")

  # Stub for `describe`
  command(:foreground, "Run the release in the foreground")

  # Upgrade management tasks
  command :unpack, "Unpacks a release upgrade for installation" do
    option(:name)
    option(:cookie)
    option(:release, :string, "The release name", required: true, hidden: true)

    argument(:version, :string, "The release version to unpack", required: true)
  end

  command :install, "Installs a release upgrade" do
    option(:name)
    option(:cookie)
    option(:release, :string, "The release name", required: true, hidden: true)

    argument(:version, :string, "The release version to install", required: true)
  end

  # Configuration tasks
  command :reload_config, "Reloads the config of the remote node" do
    option(:name)
    option(:cookie)
    option(:sysconfig, :string, "The path to a sys.config file")
  end

  command :rpc, "Executes the provided expression on the remote node" do
    option(:name)
    option(:cookie)
    option(:file, :string, "Evaluate a file instead of an expression")

    argument(:expr, :string, "The expression to evaluate", required: true)
  end

  command(:eval, "Executes the provided expression in a clean node") do
    option(:file, :string, "Evaluate a file instead of an expression")
    argument(:expr, :string, "The expression to evaluate")
  end

  command :escript, "Executes the given escript" do
    argument(:path, :string, "The path to the escript to execute")
  end

  command :info, "Prints information about the remote node to stdout" do
    option(:name)
    option(:cookie)

    command :processes, [callback: :processes_info], "Show a table of running processes" do
      option(
        :sort_by,
        :string,
        "Sets the sort column (default: memory)\n" <>
          "Valid types are: reductions, memory, message_queue, name, current_function, pid",
        transform: :to_process_info_sort_by
      )
    end
  end

  command :describe, "Describes the currently installed release" do
    option(:name)
    option(:cookie)
    option(:release, :string, "The name of the release")
    option(:release_root_dir, :string, "The root directory for all releases")
    option(:sysconfig, :string, "The path to the sys.config file used by the release")
    option(:vmargs, :string, "The path to the vm.args file used by the release")
    option(:erl_opts, :string, "Extra options for erl")
    option(:run_erl_env, :string, "Extra configuration for run_erl")
  end

  @doc """
  This function executes before any commands are dispatched
  """
  @impl Artificery
  def pre_dispatch(_cmd, _argv, %{name: name, cookie: cookie} = opts) do
    # If required, it means we need to connect to the remote node
    {:ok, peer, name, type} = start_distribution!(name, cookie)

    new_opts =
      opts
      |> Map.put(:name, name)
      |> Map.put(:peer, peer)
      |> Map.put(:name_type, type)
{'fraction_non_alphanumeric': 0.106804867057233, 'fraction_numerical': 0.0005633168093735917, 'mean_word_length': 3.621030713170224, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '353966', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2597, 'n_words': 995}