Comments (4)
@grrtrr I saw that you contributed quite a bit in your fork. Do you have an idea how this could be achieved?
from expect.
Not immediately, this is some time ago. Here are some examples, hope they may be of help: grrtrr@7603f50
from expect.
Hi
I think you should be looking for a choice line matching inputs like:
- Go to Smith valley
and
Your choice
Something like this should match a choice line:
\d).*\n
Do that in a loop till you get "Your choice"
from expect.
Hi guys, and thanks for your quick reply. Got a busy week, I couldn't take a look sooner.
@leemcloughlin I see what you mean, and it's true that I can make it work this way. But I think it'd be simpler to have a buffer from the last matched expect.
Let's look through a more concrete example:
Choose your authentication: ^
1) Send phone text message | this part is asked only once per day
2) Send push |
Authentication choice: 2 v
Choose your credentials:
1) Account: foo Credentials: admin
2) Account: foo Credentials: readonly
3) Account: bar Credentials: storage
4) Account: bar Credentials: readonly
Credentials choice: 3
I could totally do this:
var pushChoice int
pushRE := regexp.MustCompile(`(\d+)\).*push$`)
credentialsMap = make(map[string][]string)
credentialRE := regexp.MustCompile(`(\d+)\) Acccount: (\w+) Credentials: (\w+)`)
for {
index, buff, _ := exp.Expect("Authentication choice: ", pushRE, "Credentials choice: ", credentialsRE)
switch index {
case 0:
break
case 1:
// Use pushRE regexp to extract choice number
pushChoice := pushRE.FindStringSubmatch(string(buff))[1]
case 2:
break
case 3:
// Use credentialRE regexp to extract choice and infos
matches := credentialRE.FindStringSubmatch(string(buf))
credentialsMap[matches[2]] = append(credentialsMap[matches[2]], buff) // store it for example
}
}
but it sounds more natural to me to try to detect first the prompt and use a buffer for the past lines to extract the choices now that I know what I am being asked (which is what we do as human):
index, _, _ := exp.Expect("Authentication choice: ", "Credentials choice: ")
if index == 0 {
// read the exp.Buffer to extract the authentiation choices
} else if index == 1 {
// read the exp.Buffer to extract the credentials choices
}
What do you think?
from expect.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expect.