Skip to content

Commit d3d0301

Browse files
committed
chore: update documentation
1 parent 9a03397 commit d3d0301

File tree

6 files changed

+84
-93
lines changed

6 files changed

+84
-93
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
55
[![License: MIT][license_badge]][license_link]
66

7-
Generated by the [Very Good CLI][very_good_cli_link] 🤖
7+
Dart CLI for generated git commit messages with OpenAI.
88

99
A Very Good Project created by Very Good CLI..
1010

lib/src/command_runner.dart

Lines changed: 80 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:pub_updater/pub_updater.dart';
1212

1313
const executableName = 'ai_commit';
1414
const packageName = 'ai_commit';
15-
const description = 'Dart CLI for generate commit messages with OpenAI.';
15+
const description = 'Dart CLI for generated commit messages with OpenAI.';
1616

1717
/// {@template ai_commit_command_runner}
1818
/// A [CommandRunner] for the CLI.
@@ -106,15 +106,18 @@ Format the commit message according to the Conventional Commits specification.''
106106
// On format errors, show the commands error message, root usage and
107107
// exit with an error code
108108
_logger
109-
..err(e.message)..err('$stackTrace')
110-
..info('')..info(usage);
109+
..err(e.message)
110+
..err('$stackTrace')
111+
..info('')
112+
..info(usage);
111113
return ExitCode.usage.code;
112114
} on UsageException catch (e) {
113115
// On usage errors, show the commands usage message and
114116
// exit with an error code
115117
_logger
116118
..err(e.message)
117-
..info('')..info(e.usage);
119+
..info('')
120+
..info(e.usage);
118121
return ExitCode.usage.code;
119122
}
120123
}
@@ -128,7 +131,9 @@ Format the commit message according to the Conventional Commits specification.''
128131
}
129132

130133
// Verbose logs
131-
_logger..detail('Argument information:')..detail(' Top level options:');
134+
_logger
135+
..detail('Argument information:')
136+
..detail(' Top level options:');
132137
for (final option in topLevelResults.options) {
133138
if (topLevelResults.wasParsed(option)) {
134139
_logger.detail(' - $option: ${topLevelResults[option]}');
@@ -203,72 +208,69 @@ Run ${lightCyan.wrap('$executableName update')} to update''',
203208
required dynamic exclude,
204209
required dynamic conventional,
205210
}) async {
206-
try {
207-
final apiKey = await getKey();
208-
if (apiKey == null) {
209-
_logger.info(
210-
'''No API key found. To generate one, run ${lightCyan.wrap('$executableName config')}''',
211-
);
212-
return ExitCode.software.code;
213-
}
214-
215-
if (all == true) await Process.run('git', ['add', '--update']);
211+
final apiKey = await getKey();
212+
if (apiKey == null) {
213+
_logger.info(
214+
'''No API key found. To generate one, run ${lightCyan.wrap('$executableName config')}''',
215+
);
216+
return ExitCode.software.code;
217+
}
216218

217-
int? msgCount;
219+
if (all == true) await Process.run('git', ['add', '--update']);
218220

219-
if (count != null) {
220-
final value = int.tryParse('$count');
221-
if (value == null) {
222-
_logger.err('Count must be an integer.');
221+
int? msgCount;
223222

224-
return ExitCode.software.code;
225-
}
226-
if (value < 0) {
227-
_logger.err('Count must be an greater than 0.');
228-
return ExitCode.software.code;
229-
}
223+
if (count != null) {
224+
final value = int.tryParse('$count');
225+
if (value == null) {
226+
_logger.err('Count must be an integer.');
230227

231-
if (value > 5) {
232-
_logger.err('Count must be less than or equal to 5.');
233-
return ExitCode.software.code;
234-
}
228+
return ExitCode.software.code;
229+
}
230+
if (value < 0) {
231+
_logger.err('Count must be an greater than 0.');
232+
return ExitCode.software.code;
233+
}
235234

236-
msgCount = value;
235+
if (value > 5) {
236+
_logger.err('Count must be less than or equal to 5.');
237+
return ExitCode.software.code;
237238
}
238239

239-
var excludeFiles = <String>[];
240+
msgCount = value;
241+
}
240242

241-
if (exclude != null) {
242-
excludeFiles = [
243-
for (final e in exclude.toString().split(',')) e.trim()
244-
];
245-
}
243+
var excludeFiles = <String>[];
246244

247-
final detectingFiles = _logger.progress('Detecting staged files');
245+
if (exclude != null) {
246+
excludeFiles = [for (final e in exclude.toString().split(',')) e.trim()];
247+
}
248248

249-
final staged = await getStagedDiff(excludeFiles: excludeFiles);
249+
final detectingFiles = _logger.progress('Detecting staged files');
250250

251-
if (staged.isEmpty) {
252-
detectingFiles.complete('Detecting staged files');
253-
_logger.info(
254-
'''
251+
final staged = await getStagedDiff(excludeFiles: excludeFiles);
252+
253+
if (staged.isEmpty) {
254+
detectingFiles.complete('Detecting staged files');
255+
_logger.info(
256+
'''
255257
No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` options.''',
256-
);
257-
return ExitCode.success.code;
258-
}
258+
);
259+
return ExitCode.success.code;
260+
}
259261

260-
final files = staged['files'] as List<String>? ?? [];
262+
final files = staged['files'] as List<String>? ?? [];
261263

262-
var message = getDetectedMessage(files: files);
264+
var message = getDetectedMessage(files: files);
263265

264-
detectingFiles.complete(
265-
'$message:\n${files.map((e) => ' $e').join('\n')}',
266-
);
266+
detectingFiles.complete(message);
267+
_logger.info(files.map((e) => ' $e').join('\n'));
267268

268-
final s = _logger.progress('The AI is analyzing your changes');
269+
final s = _logger.progress('The AI is analyzing your changes');
269270

270-
var messages = <String>[];
271+
var messages = <String>[];
271272

273+
try {
272274
final locale = await getLocale();
273275
final maxLength = await getMaxLength();
274276

@@ -297,47 +299,38 @@ No staged changes found. Stage your changes manually, or automatically stage all
297299
diff: staged['diff'] as String,
298300
isConventional: isConventional,
299301
);
302+
} finally {
303+
s.complete('Changes analyzed');
304+
}
300305

301-
s.fail('Changes analyzed');
302-
303-
if (messages.isEmpty) {
304-
_logger.info('No commit messages were generated. Try again.');
305-
return ExitCode.success.code;
306-
}
306+
if (messages.isEmpty) {
307+
_logger.info('No commit messages were generated. Try again.');
308+
return ExitCode.success.code;
309+
}
307310

308-
if (messages.length == 1) {
309-
message = messages.first;
311+
if (messages.length == 1) {
312+
message = messages.first;
310313

311-
final confirmed =
312-
_logger.confirm('Use this commit message?\n\n $message\n');
314+
final confirmed =
315+
_logger.confirm('\nUse this commit message?\n\n $message\n\n');
313316

314-
if (!confirmed) {
315-
_logger.info('Commit message canceled.');
316-
return ExitCode.software.code;
317-
}
318-
} else {
319-
final selected = _logger.chooseOne(
320-
'Pick a commit message to use: ',
321-
choices: messages,
322-
);
323-
324-
if (selected.isEmpty) {
325-
_logger.info('Commit message canceled.');
326-
return ExitCode.software.code;
327-
}
328-
329-
message = selected;
317+
if (!confirmed) {
318+
s.fail('Commit message canceled.');
319+
return ExitCode.software.code;
330320
}
321+
} else {
322+
final selected = _logger.chooseOne(
323+
'Pick a commit message to use: ',
324+
choices: messages,
325+
);
331326

332-
await Process.run('git', ['commit', '-m', message]);
327+
message = selected;
328+
}
333329

334-
s.complete('Successfully committed');
330+
await Process.run('git', ['commit', '-m', message]);
335331

336-
return ExitCode.success.code;
337-
} catch (e) {
338-
print(e.runtimeType);
339-
print(e);
340-
exit(0);
341-
}
332+
s.complete('Successfully committed');
333+
334+
return ExitCode.success.code;
342335
}
343336
}

lib/src/commands/commands.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
export 'config_command.dart';
33
export 'sample_command.dart';
44
export 'update_command.dart';
5-

lib/src/utils/config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Future<void> setCount(int value) async {
4444

4545
// get generate commit message count
4646
Future<int> getCount() async {
47-
final value = await getData('generate_count',1);
47+
final value = await getData('generate_count', 1);
4848
return value as int;
4949
}
5050

lib/src/utils/prompt.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:convert';
22

33
String get conventionalPrompt {
4-
var map = {
4+
final map = {
55
'docs': 'Documentation only changes',
66
'style': '''
77
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)''',

lib/src/utils/utils.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
//GENERATED BARREL FILE
1+
//GENERATED BARREL FILE
22
export 'config.dart';
33
export 'error.dart';
44
export 'git.dart';
55
export 'openai.dart';
66
export 'prompt.dart';
7-

0 commit comments

Comments
 (0)