lim 0.31.2 → 0.31.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base-command';
|
|
2
|
+
export default class AndroidAppLog extends BaseCommand {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static args: {
|
|
7
|
+
packageName: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
|
|
8
|
+
};
|
|
9
|
+
static flags: {
|
|
10
|
+
id: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
|
+
follow: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
tail: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
13
|
+
'api-key': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
|
+
json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
quiet: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
create: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
workspace: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
18
|
+
daemon: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
};
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=app-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-log.d.ts","sourceRoot":"","sources":["../../../src/commands/android/app-log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,WAAW;IACpD,MAAM,CAAC,OAAO,SAA6D;IAC3E,MAAM,CAAC,WAAW,SAGmB;IACrC,MAAM,CAAC,QAAQ,WAIb;IAEF,MAAM,CAAC,IAAI;;MAKT;IAEF,MAAM,CAAC,KAAK;;;;;;;;;;MAeV;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAiG3B"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_command_1 = require("../../base-command");
|
|
5
|
+
const instance_client_factory_1 = require("../../lib/instance-client-factory");
|
|
6
|
+
class AndroidAppLog extends base_command_1.BaseCommand {
|
|
7
|
+
async run() {
|
|
8
|
+
const { args, flags } = await this.parse(AndroidAppLog);
|
|
9
|
+
this.setParsedFlags(flags);
|
|
10
|
+
// The package name is interpolated into a shell command below, so only
|
|
11
|
+
// accept the characters valid in Android package names.
|
|
12
|
+
if (!/^[A-Za-z0-9._]+$/.test(args.packageName)) {
|
|
13
|
+
this.error(`Invalid package name: ${args.packageName}`);
|
|
14
|
+
}
|
|
15
|
+
await this.withAuth(async () => {
|
|
16
|
+
const resolvedInstance = this.resolveAndroidInstance(flags.id);
|
|
17
|
+
const { client, disconnect } = await (0, instance_client_factory_1.getAndroidInstanceClient)(this.client, resolvedInstance);
|
|
18
|
+
if (!flags.follow) {
|
|
19
|
+
try {
|
|
20
|
+
// logcat has no per-package filter, only per-pid, so resolve the
|
|
21
|
+
// app's main pid first. Logs of an app that is not running are
|
|
22
|
+
// not retrievable this way; --follow does not have that limit.
|
|
23
|
+
const result = await client.adbShell('sh', [
|
|
24
|
+
'-c',
|
|
25
|
+
`pid="$(pidof -s ${args.packageName})" || { echo "${args.packageName} is not running; start it or use --follow." >&2; exit 1; }; ` +
|
|
26
|
+
`logcat -d --pid "$pid" -t ${flags.tail}`,
|
|
27
|
+
]);
|
|
28
|
+
if (result.stdout) {
|
|
29
|
+
process.stdout.write(result.stdout);
|
|
30
|
+
}
|
|
31
|
+
if (result.stderr) {
|
|
32
|
+
process.stderr.write(result.stderr);
|
|
33
|
+
}
|
|
34
|
+
if (result.exitCode !== 0) {
|
|
35
|
+
this.exit(result.exitCode);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
disconnect();
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
// The live stream is fed by an app log capture. Start a live-only
|
|
45
|
+
// one; if a capture is already active for this package (e.g.
|
|
46
|
+
// started by `android create --app-logs`), attach to its stream
|
|
47
|
+
// instead and leave it running on exit. The instance rejects a
|
|
48
|
+
// second capture with the active package's name, which is also how
|
|
49
|
+
// an already-active failure is told apart from a transient one.
|
|
50
|
+
let startedCapture = false;
|
|
51
|
+
try {
|
|
52
|
+
await client.startAppLogCapture({ bundleId: args.packageName });
|
|
53
|
+
startedCapture = true;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
57
|
+
const active = /already active for (\S+)/.exec(message)?.[1];
|
|
58
|
+
if (!active) {
|
|
59
|
+
this.error(`Could not start an app log capture: ${message}`);
|
|
60
|
+
}
|
|
61
|
+
if (active !== args.packageName) {
|
|
62
|
+
this.error(`An app log capture is already active for ${active} and only one runs at a time; ` +
|
|
63
|
+
`run \`lim android app-log ${active} --follow\` to tail it.`);
|
|
64
|
+
}
|
|
65
|
+
this.warn(`Attaching to the app log capture already active for ${active}.`);
|
|
66
|
+
}
|
|
67
|
+
const closeStream = client.streamAppLogCapture({
|
|
68
|
+
onLine: (line) => {
|
|
69
|
+
process.stdout.write(line.line + '\n');
|
|
70
|
+
},
|
|
71
|
+
onError: (err) => {
|
|
72
|
+
this.warn(`App log stream error: ${err.message}`);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
await new Promise((resolve) => {
|
|
76
|
+
const keepAlive = setInterval(() => { }, 1 << 30);
|
|
77
|
+
const shutdown = () => {
|
|
78
|
+
clearInterval(keepAlive);
|
|
79
|
+
resolve();
|
|
80
|
+
};
|
|
81
|
+
process.on('SIGINT', shutdown);
|
|
82
|
+
process.on('SIGTERM', shutdown);
|
|
83
|
+
});
|
|
84
|
+
closeStream();
|
|
85
|
+
if (startedCapture) {
|
|
86
|
+
try {
|
|
87
|
+
await client.stopAppLogCapture();
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// The instance may already be gone; nothing to clean up then.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
disconnect();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
AndroidAppLog.summary = 'Stream or tail app logs from a running Android instance';
|
|
101
|
+
AndroidAppLog.description = 'Read logcat output for a specific installed app on a running Android instance. ' +
|
|
102
|
+
'Use `--tail` for recent lines of the running app, or `--follow` to keep streaming ' +
|
|
103
|
+
'logs until you stop the command.';
|
|
104
|
+
AndroidAppLog.examples = [
|
|
105
|
+
'<%= config.bin %> android app-log com.example.app',
|
|
106
|
+
'<%= config.bin %> android app-log com.example.app --tail 50',
|
|
107
|
+
'<%= config.bin %> android app-log com.example.app --follow --id <instance-ID>',
|
|
108
|
+
];
|
|
109
|
+
AndroidAppLog.args = {
|
|
110
|
+
packageName: core_1.Args.string({
|
|
111
|
+
description: 'Package name of the installed app whose logs should be read',
|
|
112
|
+
required: true,
|
|
113
|
+
}),
|
|
114
|
+
};
|
|
115
|
+
AndroidAppLog.flags = {
|
|
116
|
+
...base_command_1.BaseCommand.baseFlags,
|
|
117
|
+
id: core_1.Flags.string({
|
|
118
|
+
description: 'Android instance ID to target. Defaults to the last created Android instance.',
|
|
119
|
+
}),
|
|
120
|
+
follow: core_1.Flags.boolean({
|
|
121
|
+
char: 'f',
|
|
122
|
+
description: 'Keep streaming log lines until interrupted',
|
|
123
|
+
default: false,
|
|
124
|
+
}),
|
|
125
|
+
tail: core_1.Flags.integer({
|
|
126
|
+
char: 'n',
|
|
127
|
+
description: 'Number of recent lines to fetch when not using `--follow`.',
|
|
128
|
+
default: 100,
|
|
129
|
+
}),
|
|
130
|
+
};
|
|
131
|
+
exports.default = AndroidAppLog;
|
|
132
|
+
//# sourceMappingURL=app-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-log.js","sourceRoot":"","sources":["../../../src/commands/android/app-log.ts"],"names":[],"mappings":";;AAAA,sCAA0C;AAC1C,qDAAiD;AACjD,+EAA6E;AAE7E,MAAqB,aAAc,SAAQ,0BAAW;IAoCpD,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACxD,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAE3B,uEAAuE;QACvE,wDAAwD;QACxD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE;YAC7B,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC/D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAA,kDAAwB,EAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YAE7F,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;gBAClB,IAAI,CAAC;oBACH,iEAAiE;oBACjE,+DAA+D;oBAC/D,+DAA+D;oBAC/D,MAAM,MAAM,GAAG,M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