<commit_before>require "vmc/cli"
require "tunnel-vmc-plugin/tunnel"

module VMCTunnel
  class Tunnel < VMC::CLI
    CLIENTS_FILE = "#{VMC::CONFIG_DIR}/tunnel-clients.yml"
    STOCK_CLIENTS = File.expand_path("../../../config/clients.yml", __FILE__)

    desc "Create a local tunnel to a service."
    group :services, :manage
    input(:instance, :argument => :optional,
          :from_given => find_by_name("service instance"),
          :desc => "Service instance to tunnel to") { |instances|
      ask("Which service instance?", :choices => instances,
          :display => proc(&:name))
    }
    input(:client, :argument => :optional,
          :desc => "Client to automatically launch") { |clients|
      if clients.empty?
        "none"
      else
        ask("Which client would you like to start?",
            :choices => clients.keys.unshift("none"))
      end
    }
    input(:port, :default => 10000, :desc => "Port to bind the tunnel to")
    def tunnel(input)
      instances = client.service_instances
      fail "No services available for tunneling." if instances.empty?

      instance = input[:instance, instances.sort_by(&:name)]
      clients = tunnel_clients[instance.vendor] || {}
      client_name = input[:client, clients]

      tunnel = CFTunnel.new(client, instance)
      port = tunnel.pick_port!(input[:port])

      conn_info =
        with_progress("Opening tunnel on port #{c(port, :name)}") do
          tunnel.open!
        end

      if client_name == "none"
        unless simple_output?
          line
          display_tunnel_connection_info(conn_info)

          line
          line "Open another shell to run command-line clients or"
          line "use a UI tool to connect using the displayed information."
          line "Press Ctrl-C to exit..."
        end

        tunnel.wait_for_end
      else
        with_progress("Waiting for local tunnel to become available") do
          tunnel.wait_for_start
        end

        unless start_local_prog(clients, client_name, conn_info, port)
          fail "'#{client_name}' execution failed; is it in your $PATH?"
        end
      end
    end
<commit_msg>tunnel: simple_output? -> quiet?<commit_after>require "vmc/cli"
require "tunnel-vmc-plugin/tunnel"

module VMCTunnel
  class Tunnel < VMC::CLI
    CLIENTS_FILE = "#{VMC::CONFIG_DIR}/tunnel-clients.yml"
    STOCK_CLIENTS = File.expand_path("../../../config/clients.yml", __FILE__)

    desc "Create a local tunnel to a service."
    group :services, :manage
    input(:instance, :argument => :optional,
          :from_given => find_by_name("service instance"),
          :desc => "Service instance to tunnel to") { |instances|
      ask("Which service instance?", :choices => instances,
          :display => proc(&:name))
    }
    input(:client, :argument => :optional,
          :desc => "Client to automatically launch") { |clients|
      if clients.empty?
        "none"
      else
        ask("Which client would you like to start?",
            :choices => clients.keys.unshift("none"))
      end
    }
    input(:port, :default => 10000, :desc => "Port to bind the tunnel to")
    def tunnel(input)
      instances = client.service_instances
      fail "No services available for tunneling." if instances.empty?

      instance = input[:instance, instances.sort_by(&:name)]
      clients = tunnel_clients[instance.vendor] || {}
      client_name = input[:client, clients]

      tunnel = CFTunnel.new(client, instance)
      port = tunnel.pick_port!(input[:port])

      conn_info =
        with_progress("Opening tunnel on port #{c(port, :name)}") do
          tunnel.open!
        end

      if client_name == "none"
        unless quiet?
          line
          display_tunnel_connection_info(conn_info)

          line
          line "Open another shell to run command-line clients or"
          line "use a UI tool to connect using the displayed information."
          line "Press Ctrl-C to exit..."
        end

        tunnel.wait_for_end
      else
        with_progress("Waiting for local tunnel to become available") do
          tunnel.wait_for_start
        end

        unless start_local_prog(clients, client_name, conn_info, port)
          fail "'#{client_name}' execution failed; is it in your $PATH?"
        end
      end
    end

{'fraction_non_alphanumeric': 0.11307174367309032, 'fraction_numerical': 0.0023218017181332712, 'mean_word_length': 2.476997578692494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '222124', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1223, 'n_words': 354}