Skip to content

Commit d7ade1d

Browse files
committed
refactor: replace print statements with stdout and stderr
1 parent b6a44d5 commit d7ade1d

File tree

2 files changed

+27
-51
lines changed

2 files changed

+27
-51
lines changed

bin/commands/upload_so_files.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,29 @@ class UploadSoFilesCommand {
8484
// Validate file exists
8585
final file = File(options.file);
8686
if (!await file.exists()) {
87-
print('[Instabug-CLI] Error: File not found: ${options.file}');
87+
stderr.writeln('[Instabug-CLI] Error: File not found: ${options.file}');
8888
throw Exception('File not found: ${options.file}');
8989
}
9090

9191
// validate file is a zip file
9292
if (!file.path.endsWith('.zip')) {
93-
print('[Instabug-CLI] Error: File is not a zip file: ${options.file}');
93+
stderr.writeln(
94+
'[Instabug-CLI] Error: File is not a zip file: ${options.file}');
9495
throw Exception('File is not a zip file: ${options.file}');
9596
}
9697

9798
// Validate architecture
9899
if (!validArchs.contains(options.arch)) {
99-
print(
100+
stderr.writeln(
100101
'[Instabug-CLI] Error: Invalid architecture: ${options.arch}. Valid options: ${validArchs.join(', ')}');
101102
throw Exception(
102103
'Invalid architecture: ${options.arch}. Valid options: ${validArchs.join(', ')}');
103104
}
104105

105-
print('Uploading .so files...');
106-
print('Architecture: ${options.arch}');
107-
print('File: ${options.file}');
108-
print('App Version: ${options.name}');
106+
stdout.writeln('Uploading .so files...');
107+
stdout.writeln('Architecture: ${options.arch}');
108+
stdout.writeln('File: ${options.file}');
109+
stdout.writeln('App Version: ${options.name}');
109110

110111
const endPoint = 'https://api.instabug.com/api/web/public/so_files';
111112

@@ -133,18 +134,18 @@ class UploadSoFilesCommand {
133134

134135
if (response.statusCode < 200 || response.statusCode >= 300) {
135136
final responseBody = await response.stream.bytesToString();
136-
print('[Instabug-CLI] Error: Failed to upload .so files');
137-
print('Status Code: ${response.statusCode}');
138-
print('Response: $responseBody');
137+
stderr.writeln('[Instabug-CLI] Error: Failed to upload .so files');
138+
stderr.writeln('Status Code: ${response.statusCode}');
139+
stderr.writeln('Response: $responseBody');
139140
exit(1);
140141
}
141142

142-
print(
143+
stdout.writeln(
143144
'Successfully uploaded .so files for version: ${options.name} with arch ${options.arch}');
144145
exit(0);
145146
} catch (e) {
146-
print('[Instabug-CLI] Error uploading .so files, $e');
147-
print('[Instabug-CLI] Error Stack Trace: ${StackTrace.current}');
147+
stderr.writeln('[Instabug-CLI] Error uploading .so files, $e');
148+
stderr.writeln('[Instabug-CLI] Error Stack Trace: ${StackTrace.current}');
148149
exit(1);
149150
}
150151
}

bin/instabug.dart

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,6 @@ class CommandHandler {
2828
CommandHandler({required this.parser, required this.execute});
2929
}
3030

31-
// Future<bool> makeHttpPostRequest({
32-
// required String url,
33-
// required Map<String, String> body,
34-
// Map<String, String>? headers,
35-
// }) async {
36-
// try {
37-
// final client = HttpClient();
38-
// final request = await client.postUrl(Uri.parse(url));
39-
// request.headers.contentType = ContentType.json;
40-
// request.write(jsonEncode(body));
41-
// final response = await request.close();
42-
// if (response.statusCode >= 200 && response.statusCode < 300) {
43-
// final responseBody = await response.transform(utf8.decoder).join();
44-
// return true;
45-
// } else {
46-
// print('Error Code: ${response.statusCode}');
47-
// print('Error Body: ${await response.transform(utf8.decoder).join()}');
48-
// return false;
49-
// }
50-
// } catch (e) {
51-
// print('[Instabug-CLI] Error while making HTTP POST request: $e');
52-
// exit(1);
53-
// }
54-
// }
55-
5631
void main(List<String> args) async {
5732
final parser = ArgParser()..addFlag('help', abbr: 'h');
5833

@@ -61,7 +36,7 @@ void main(List<String> args) async {
6136
parser.addCommand(entry.key, entry.value.parser);
6237
}
6338

64-
print('--------------------------------');
39+
stdout.writeln('--------------------------------');
6540

6641
try {
6742
final result = parser.parse(args);
@@ -72,8 +47,8 @@ void main(List<String> args) async {
7247
if (command['help'] == true) {
7348
final commandHandler = CommandRegistry.commands[command.name];
7449
if (commandHandler != null) {
75-
print('Usage: instabug ${command.name} [options]');
76-
print(commandHandler.parser.usage);
50+
stdout.writeln('Usage: instabug ${command.name} [options]');
51+
stdout.writeln(commandHandler.parser.usage);
7752
}
7853
return;
7954
}
@@ -83,21 +58,21 @@ void main(List<String> args) async {
8358
if (commandHandler != null) {
8459
commandHandler.execute(command);
8560
} else {
86-
print('Unknown command: ${command.name}');
87-
print('Available commands: ${CommandRegistry.commandNames.join(', ')}');
61+
stderr.writeln('Unknown command: ${command.name}');
62+
stdout.writeln('Available commands: ${CommandRegistry.commandNames.join(', ')}');
8863
exit(1);
8964
}
9065
} else {
91-
print('No applicable command found');
92-
print('Usage: instabug [options] <command>');
93-
print('Available commands: ${CommandRegistry.commandNames.join(', ')}');
94-
print('\nFor help on a specific command:');
95-
print(' instabug <command> --help\n');
96-
print(parser.usage);
66+
stderr.writeln('No applicable command found');
67+
stdout.writeln('Usage: instabug [options] <command>');
68+
stdout.writeln('Available commands: ${CommandRegistry.commandNames.join(', ')}');
69+
stdout.writeln('For help on a specific command:');
70+
stdout.writeln(' instabug <command> --help');
71+
stdout.writeln(parser.usage);
9772
}
9873
} catch (e) {
99-
print('[Instabug-CLI] Error: $e');
100-
print(parser.usage);
74+
stderr.writeln('[Instabug-CLI] Error: $e');
75+
stdout.writeln(parser.usage);
10176
exit(1);
10277
}
10378
}

0 commit comments

Comments
 (0)