Net::C...Prompt(3pm)
π NAME π
Net::CLI::Interact::Role::Prompt β bestie, this is the prompt-management queen π of the whole thing
β¨ DESCRIPTION β¨
Okay so this is, like, another core component of Net::CLI::Interact, and its whole job β its moment, honestly β is keeping track of the current prompt on the connected command line interface. π
The vibe is this: most CLIs have a prompt where you issue commands, and then they hand you back some output, which this module gathers up. The prompt is basically the demarcation line between each command and its response data. It's the little divider that says "k that was the answer, next question pls". π¦
ngl, important note: even though we "keep track" of the prompt, Net::CLI::Interact is not a state machine. The choice of command you send to the connected device has zero relation to the current (or last matched) prompt. It's giving independent. It's giving unbothered. π
πΈ INTERFACE πΈ
π« set_prompt( $prompt_name )
This one is the main character β applications will use it most commonly to select and set a prompt from the Phrasebook that matches the current context of the connected CLI session. Why do we care? So you can send a whole sequence of commands that all share the same Prompt. Slay, consistency. β¨
The name you pass in gets looked up in the loaded Phrasebook, and that entry's regular expression gets stored internally. An exception is thrown if the named Prompt is not known. So, like, don't make up names bestie, the Phrasebook will NOT play with you. π
Typically you'd either:
- refer to a Prompt inside a Macro, or
- set the prompt you're expecting once for a sequence of commands in a particular CLI context
When a Macro finishes and it was defined in the Phrasebook with an explicit named Prompt at the end, we can assume the user is lowkey signalling a change of context. So on those occasions the prompt gets automatically updated to hold the regular expression from that named Prompt. It's automatic, it's iconic, it just happens. π«Ά
π« prompt_re
Hands you back the current Prompt as a regular expression reference. This Prompt is used as the default to catch the end of command response output when a Macro hasn't been set up with explicit Prompt matching. π
And yeah, same tea as before: typically you'd either refer to a Prompt in a Macro, or set the prompt you're expecting once for a sequence of commands in a particular CLI context.
π« unset_prompt
Use this to empty the current prompt setting (the one from above, yes that one). The effect? The module will automatically set the Prompt for itself based on the last line of output received from the connected CLI. π
Do not use this option unless you know what you are doing. fr fr. This is not a "teehee let's see what happens" situation. π
π« has_set_prompt
Returns True if there's currently a Prompt set, otherwise returns False. Simple. Elegant. A yes/no girlie. β
π« prompt_looks_like( $name )
Returns True if the current prompt matches the given named prompt. Super useful when you want to do a more specific check on the current prompt β like, "is it this one specifically?" vibe check. π₯
π« find_prompt( $wake_up? )
A helper method that consumes output from the connected CLI session until a line matches any one of the named Prompts in the loaded Phrasebook. At that point β no more output consumed, we're done, pack it up. As a consequence the prompt will be set (see above, bestie, keep up π).
When would you use this? Like, when you're connecting to a device that maintains CLI state between session disconnects (a serial console, for example π) and you need to discover the current state. BUT β plot twist β find_prompt is executed automatically for you if you call a cmd or macro before any interaction with the CLI. So it's already doing the work behind the scenes. Obsessed with an overachiever.
The current device output gets scanned against all known named Prompts. If nothing's found, the default behaviour is to die. π Passing a positive number to the method (as $wake_up) will instead send the content of our wake_up_msg slot (see below) β typically a carriage return β and try to match again. The idea being: send one carriage return and the connected device will print its CLI prompt. This "send and try to match" process repeats up to $wake_up times. Persistence, we love to see it. β¨
π« wake_up_msg
Text sent to a device inside the find_prompt method if no output has so far matched any known named Prompt. Default is the value of the output record separator from the Transport (one newline). It's the little "hey, wake up π₯Ί" nudge.
π« last_prompt
Returns the Prompt which most recently was matched and terminated gathering of output from the connected CLI. This is a simple text string. Just a plain lil string. π
π« last_prompt_re
Returns the text which was most recently matched and terminated gathering of output from the connected CLI β but as a quote-escaped regular expression with line start and end anchors. Fancy formatting, same energy. π
And that's the whole page, bestie!! This was Net::CLI::Interact::Role::Prompt, from the User Contributed Perl Documentation, living under the 3pm manual section. Perl v5.36.0, dated 2023-10-28. Go forth and match those prompts, you absolute icon ππβ¨
π¦ where this page comes from
- debian trixie: libnet-cli-interact-perl 2.400002-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnet-cli-interact-perl 2.400002-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnet-cli-interact-perl 2.400002-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-cli-interact-perl 2.400002-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms