1.0.0 • Published 2 years ago
nv-cli-simple-expect v1.0.0
nv-cli-simple-expect
- nv-cli-simple-expect
- for creat automation cli project, input interact command
install
- npm install nv-cli-simple-expect
usage
const sexpect = require("nv-cli-simple-expect");
var [we,w,quit,cache] = sexpect();
await we("login",":");
await we("dev", ":");
await we("xxxxpasswd", "# ");
....
await quit()
//when using a expect_ptrn THAT WILL NEVER MATCH, can goto the history-cache mode
var p = we("ls-l", "xx$$%@!@%%@%")
cache() to get the history
APIS
ExpectFunc : async (
data, //newest ondata
cache, //Array<String> the last-element IS data
cfg, //---config WHEN init
_pty //---pty
) => Boolean
Expect : RegExp | String | ExpectFunc
RegExp.test(data)
String.includes(data)
ExpectFunc(data,cache,cfg,_pty)
- async we(cmd:String,expect:Expect=DFLT_EXPECT):Array //auto append "\r"
- async w(cmd:String,expect:Expect=DFLT_EXPECT):Array
- async quit() //must be called WHEN finish using
- cache():Array //debug using , temperary ondata buf
EXAMPLE
> await we("ls -l","# ")
[
'ls -l\r\n',
'total 8\r\n',
'drwxr-xr-x 3 root root 4096 Aug 15 2021 snap\r\n' +
'drwxr-xr-x 2 root root 4096 May 6 06:31 upload\r\n' +
'root@dev2:~# '
]
> await we("login",": ")
[ 'login\r\n', 'dev2 login: ' ]
> await we("root",": ")
[ 'root\r\n', 'Password: ' ]
> await we("my-xxxx-passwd","# ")
[
'\r\n',
'Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-110-generic x86_64)\r\n' +
......
'root@dev2:~# '
]
>
await quit(); // !!------MUST CALL this BEFORE EXIT
dont resolve , history cache mode
> var DUMMY_PTRN_DONT_RTRN = "XXXXXXX"
> var p = we("ls -l",DUMMY_PTRN_DONT_RTRN)
> cache()
[
'ls -l\r\n',
'total 8\r\n',
'drwxr-xr-x 3 root root 4096 Aug 15 2021 snap\r\n' +
'drwxr-xr-x 2 root root 4096 May 6 06:31 upload\r\n',
'root@dev2:~# '
]
> p
Promise {
<pending>,
[Symbol(async_id_symbol)]: 1233,
[Symbol(trigger_async_id_symbol)]: 5,
[Symbol(destroyed)]: { destroyed: false }
}
>
METHODS
LICENSE
- ISC
1.0.0
2 years ago