<commit_before>require "admiral"
require "./concerns/*"

def current_docker_user
  `#{Psykube::Commands::Docker.bin} info`.lines.find(&.=~ /^Username/).try(&.split(":")[1]?).to_s.strip
end

class Psykube::Commands::Init < Admiral::Command
  include PsykubeFileFlag

  define_help description: "Generate a .psykube.yml in the current directory."

  define_flag overwrite : Bool, "Overwrite the file if it exists", short: o
  define_flag name, default: File.basename(Dir.current)
  define_flag namespace
  define_flag registry_host
  define_flag registry_user : String, default: current_docker_user
  define_flag ports : Array(String), long: "port", short: "p", default: [] of String
  define_flag env : Array(String), short: "e", default: [] of String
  define_flag hosts : Array(String), long: "host", default: [] of String
  define_flag tls : Bool
  define_flag image

  def overwrite?
    return true if flags.overwrite
    print "#{flags.file} already exists, do you want to overwrite? (y/n) "
    gets("\n").to_s.strip == "y"
  end

  def run
    if !File.exists?(flags.file) || overwrite?
      puts "Writing #{flags.file}...".colorize(:cyan)
      File.open(flags.file, "w+") do |file|
        manifest = Psykube::Manifest.new flags.name
        if ingress = manifest.ingress
          ingress.annotations = nil
          ingress.hosts = nil
        end
        if flags.image
          manifest.image = flags.image
        else
          manifest.registry_host = flags.registry_host
          manifest.registry_user = flags.registry_user
        end
        manifest.namespace = flags.namespace
        manifest.ports = Hash(String, UInt16).new.tap do |hash|
          flags.ports.each_with_index do |spec, index|
            parts = spec.split("=", 2).reverse
            port = parts[0].to_u16? || raise "Invalid port format."<commit_msg>update init help<commit_after>require "admiral"
require "./concerns/*"

def current_docker_user
  `#{Psykube::Commands::Docker.bin} info`.lines.find(&.=~ /^Username/).try(&.split(":")[1]?).to_s.strip
end

class Psykube::Commands::Init < Admiral::Command
  include PsykubeFileFlag

  define_help description: "Generate a .psykube.yml in the current directory."

  define_flag overwrite : Bool, "Overwrite the file if it exists", short: 'o'
  define_flag name, "Set the name of the application.", short: 'N'
  define_flag namespace, "Set the namespace to deploy into.", short: 'n'
  define_flag registry_host, "The hostname for the registry.", short: 'H'
  define_flag registry_user : String, "The username for the registry.", short: 'U'
  define_flag ports : Array(String), "Set a port. (can be in the format of --port 1234 or --port http=1234).", long: "port", short: "p", default: [] of String
  define_flag env : Array(String), short: "e", default: [] of String
  define_flag hosts : Array(String), "Set a host for ingress.", long: "host", default: [] of String
  define_flag tls : Bool, "Enable tls for ingress.", short: 't'
  define_flag image, "Set the image, this takes precedence over --registry-host and --registry-user.", short: 'i'

  def overwrite?
    return true if flags.overwrite
    print "#{flags.file} already exists, do you want to overwrite? (y/n) "
    gets("\n").to_s.strip == "y"
  end

  def run
    if !File.exists?(flags.file) || overwrite?
      puts "Writing #{flags.file}...".colorize(:cyan)
      File.open(flags.file, "w+") do |file|
        manifest = Psykube::Manifest.new(flags.name || File.basename(Dir.current))
        if ingress = manifest.ingress
          ingress.annotations = nil
          ingress.hosts = nil
        end
        if flags.image
          manifest.image = flags.image
        else
          manifest.registry_host = flags.registry_host
          manifest.registry_user = flags.registry_user || current_docker_user
        end
        manifest.namespace = flags.namespace
        manifest.ports = Hash(String, UInt16).new.tap do |hash|
          flags.ports.each_with_index do |spec, index|
            parts = spec.split("=", 2).reverse
            port = parts[0].to_u16? || raise "Invalid port format."
{'fraction_non_alphanumeric': 0.1282550498904843, 'fraction_numerical': 0.00535410075444147, 'mean_word_length': 3.2024539877300615, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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': '777671', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1245, 'n_words': 367}