Alright, so cards on the table: it's really hard to guide someone through an Expect script without being able to see the raw input/response in action, so you'll have to play with this to get it to work.
This section of code in both scripts sends the "enable" command to enter elevated privilege mode:
// The enable command will elevate the prompt if possible.
cli.send("enable\n")
cli.expect(["(?i)password:", "${prompt[0..-2]}[>#\$]", prompt] as String[], smallBufferSize)
if (cli.matched().toLowerCase().contains("password")) {
cli.send("${epas}\n")
cli.expect(rawPrompt, smallBufferSize)
}
The cli.send("enable\n") is what sends the word "enable" to the device. Currently, the script then waits for the device to respond with some text containing "password:". Since the response is actually "username:" or something like it, you'll need to add some code between the cli.send and the first cli.expect so that the script is expecting (using cli.expect) "username:" instead of "password:". Then you'll need to send the username (using cli.send). The username is contained in the ${user} variable so you should be able to do something very similar to what was done earlier in the script where the initial login happened:
if (cli.matched() =~ /[Uu]?ser\s?[Nn]ame\s?:/) {
cli.send("${user}\n")
cli.expect("[Pp]?assword:", smallBufferSize)
}
I'm sorry it can't be as easy as "just use this code" but, this is often how it goes with Expect.