<commit_before>package com.yngvark.pc_init

import com.yngvark.pc_init.process.*
import com.yngvark.pc_init.robot.ConsolePasswordReader
import com.yngvark.pc_init.robot.RobotHelper
import com.yngvark.pc_init.robot.SecretGetter
import com.yngvark.pc_init.robot.SomewhatSecureString
import java.awt.Robot
import java.awt.event.KeyEvent

val robot = RobotHelper(Robot())
val loginToOnePassword = LoginToOnePasswordProcess(robot)
val secretGetter = SecretGetter(robot)
val vpnLogin = VpnLoginProcess(robot, secretGetter)
val k8sLogin = K8sLoginProcess(robot)
val webPages = WebPagesProcess(robot)
val sshKeys = SshKeysProcess(robot, SecretGetter(robot))
val programs = ProgramsProcess(robot)

fun main(args: Array<String>) {
    println("Version 0.0.8 - New URLs to Gmail and Outlook")
    decideLoginRoutine(args)

//    robot.debugMode = true
//    test()
}

private fun decideLoginRoutine(args: Array<String>) {
    if (args.any { it == "-p" }) {
        val password = SomewhatSecureString(args[args.indexOf("-p") + 1].toCharArray())
        loginRoutine(password, args)
    } else {
        val password = ConsolePasswordReader().read()
        loginRoutine(password, args)
    }
}


fun loginRoutine(password: <PASSWORD>, args: Array<String>) {
    robot.sleep(2000)

    if (args.isEmpty()) {
        runAllProcesses(password)
    } else {
        if (args.any { it == "--1p" }) {
            println("Running single step: " + LoginToOnePasswordProcess::class.simpleName)
            runLoginToOnePasswordProcess(password)
        }

        if (args.any { it == "--vpn" }) {
            println("Running single step: " + VpnLoginProcess::class.simpleName)
            runVpnProcess(password)
        }
    }
}

private fun runAllProcesses(password: <PASSWORD>) {
    println("Running all processes")

    password.use {
        loginToOnePassword.run(password)
        vpnLogin.run()
        robot.pressAndRelease(KeyEvent.VK_ALT, KeyEvent.VK_TAB).sleep(50) // Switch to chrome
        robot.pressAndRelease(KeyEvent.VK_ESCAPE).sleep(50)
    }

    webPages.run()
    sshKeys.run() // TODO: Fix not having to do this.
    programs.run()
    k8sLogin.run()
}

private fun runLoginToOnePasswordProcess(password: Some<PASSWORD>String) {
    password.use {
        loginToOnePassword.run(password)
    }
}

private fun runVpnProcess(password: <PASSWORD>) {
    password.use {
        vpnLogin.run()
    }
}

fun test() {
    // TODO fix outlook
    programs.run()
}
<commit_msg>Print steps that will be run<commit_after>package com.yngvark.pc_init

import com.yngvark.pc_init.process.*
import com.yngvark.pc_init.robot.ConsolePasswordReader
import com.yngvark.pc_init.robot.RobotHelper
import com.yngvark.pc_init.robot.SecretGetter
import com.yngvark.pc_init.robot.SomewhatSecureString
import java.awt.Robot
import java.awt.event.KeyEvent

val robot = RobotHelper(Robot())
val loginToOnePassword = LoginToOnePasswordProcess(robot)
val secretGetter = SecretGetter(robot)
val vpnLogin = VpnLoginProcess(robot, secretGetter)
val k8sLogin = K8sLoginProcess(robot)
val webPages = WebPagesProcess(robot)
val sshKeys = SshKeysProcess(robot, SecretGetter(robot))
val programs = ProgramsProcess(robot)

fun main(args: Array<String>) {
    println("Version 0.0.9 - Show processes to be run")
    if (args.isEmpty()) {
        println("Running all processes")
    } else {
        if (run1Password(args)) {
            println("Running step: " + LoginToOnePasswordProcess::class.simpleName)
        }

        if (runVpn(args)) {
            println("Running step: " + VpnLoginProcess::class.simpleName)
        }
    }

    decideLoginRoutine(args)

//    robot.debugMode = true
//    test()
}

private fun decideLoginRoutine(args: Array<String>) {
    if (args.any { it == "-p" }) {
        val password = SomewhatSecureString(args[args.indexOf("-p") + 1].toCharArray())
        loginRoutine(password, args)
    } else {
        val password = ConsolePasswordReader().read()
        loginRoutine(password, args)
    }
}


fun loginRoutine(password: <PASSWORD>, args: Array<String>) {
    robot.sleep(2000)

    if (args.isEmpty()) {
        runAllProcesses(password)
    } else {
        if (run1Password(args)) {
            println("Running step: " + LoginToOnePasswordProcess::class.simpleName)
            runLoginToOnePasswordProcess(password)
        }

        if (runVpn(args)) {
            println("Running step: " + VpnLoginProcess::class.simpleName)
            runVpnProcess(password)
        }
    }
}

private fun runAllProcesses(password: <PASSWORD>) {
    println("Running all processes")

    password.use {
        loginToOnePassword.run(password)
        vpnLogin.run()
        robot.pressAndRelease(KeyEvent.VK_ALT, KeyEvent.VK_TAB).sleep(50) // Switch to chrome
        robot.pressAndRelease(KeyEvent.VK_ESCAPE).sleep(50)
    }

    webPages.run()
    sshKeys.run() // TODO: Fix not having to do this.
    programs.run()
    k8sLogin.run()
}

private fun run1Password(args: Array<String>) = args.any { it == "--1p" }

private fun runLoginToOnePasswordProcess(password: <PASSWORD>) {
    password.use {
        loginToOnePassword.run(password)
    }
}

private fun runVpn(args: Array<String>) = args.any { it == "--vpn" }

private fun runVpnProcess(password: Some<PASSWORD>) {
    password.use {
        vpnLogin.run()
    }
}

fun test() {
    // TODO fix outlook
    programs.run()
}

{'fraction_non_alphanumeric': 0.12022971470915154, 'fraction_numerical': 0.006483882919599852, 'mean_word_length': 3.284920634920635, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '410142', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1757, 'n_words': 328}