-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
43 lines (39 loc) · 1.13 KB
/
cli.js
File metadata and controls
43 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
/**
* cli.js - Command-line ADB wrapper
* Usage: adb-toolkit <command> [args]
*/
const { exec } = require('child_process');
function adb(cmd) {
return new Promise((resolve, reject) => {
exec(`adb shell ${cmd}`, (err, stdout) => {
if (err) reject(err);
resolve(stdout.trim());
});
});
}
async function main() {
const [cmd, ...args] = process.argv.slice(2);
try {
switch(cmd) {
case 'app-info':
const pkg = args[0] || 'com.example.app';
const info = await adb(`dumpsys package ${pkg} | grep versionName`);
console.log(`App: ${pkg}\n${info}`);
break;
case 'screenshot':
exec(`adb exec-out screencap -p > screenshot_${Date.now()}.png`);
console.log('✓ Screenshot saved');
break;
case 'battery':
const bat = await adb('dumpsys battery');
console.log(bat.split('\n').filter(l => l.includes('level') || l.includes('status')).join('\n'));
break;
default:
console.log('Commands: app-info, screenshot, battery, devices');
}
} catch (e) {
console.error(`❌ ${e.message}`);
}
}
main();