Skip to content

Commit

Permalink
chore: update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
thitlwincoder committed Nov 23, 2023
1 parent 9a03397 commit d3d0301
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 93 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
[![License: MIT][license_badge]][license_link]

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

A Very Good Project created by Very Good CLI..

Expand Down
167 changes: 80 additions & 87 deletions lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:pub_updater/pub_updater.dart';

const executableName = 'ai_commit';
const packageName = 'ai_commit';
const description = 'Dart CLI for generate commit messages with OpenAI.';
const description = 'Dart CLI for generated commit messages with OpenAI.';

/// {@template ai_commit_command_runner}
/// A [CommandRunner] for the CLI.
Expand Down Expand Up @@ -106,15 +106,18 @@ Format the commit message according to the Conventional Commits specification.''
// On format errors, show the commands error message, root usage and
// exit with an error code
_logger
..err(e.message)..err('$stackTrace')
..info('')..info(usage);
..err(e.message)
..err('$stackTrace')
..info('')
..info(usage);
return ExitCode.usage.code;
} on UsageException catch (e) {
// On usage errors, show the commands usage message and
// exit with an error code
_logger
..err(e.message)
..info('')..info(e.usage);
..info('')
..info(e.usage);
return ExitCode.usage.code;
}
}
Expand All @@ -128,7 +131,9 @@ Format the commit message according to the Conventional Commits specification.''
}

// Verbose logs
_logger..detail('Argument information:')..detail(' Top level options:');
_logger
..detail('Argument information:')
..detail(' Top level options:');
for (final option in topLevelResults.options) {
if (topLevelResults.wasParsed(option)) {
_logger.detail(' - $option: ${topLevelResults[option]}');
Expand Down Expand Up @@ -203,72 +208,69 @@ Run ${lightCyan.wrap('$executableName update')} to update''',
required dynamic exclude,
required dynamic conventional,
}) async {
try {
final apiKey = await getKey();
if (apiKey == null) {
_logger.info(
'''No API key found. To generate one, run ${lightCyan.wrap('$executableName config')}''',
);
return ExitCode.software.code;
}

if (all == true) await Process.run('git', ['add', '--update']);
final apiKey = await getKey();
if (apiKey == null) {
_logger.info(
'''No API key found. To generate one, run ${lightCyan.wrap('$executableName config')}''',
);
return ExitCode.software.code;
}

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

if (count != null) {
final value = int.tryParse('$count');
if (value == null) {
_logger.err('Count must be an integer.');
int? msgCount;

return ExitCode.software.code;
}
if (value < 0) {
_logger.err('Count must be an greater than 0.');
return ExitCode.software.code;
}
if (count != null) {
final value = int.tryParse('$count');
if (value == null) {
_logger.err('Count must be an integer.');

if (value > 5) {
_logger.err('Count must be less than or equal to 5.');
return ExitCode.software.code;
}
return ExitCode.software.code;
}
if (value < 0) {
_logger.err('Count must be an greater than 0.');
return ExitCode.software.code;
}

msgCount = value;
if (value > 5) {
_logger.err('Count must be less than or equal to 5.');
return ExitCode.software.code;
}

var excludeFiles = <String>[];
msgCount = value;
}

if (exclude != null) {
excludeFiles = [
for (final e in exclude.toString().split(',')) e.trim()
];
}
var excludeFiles = <String>[];

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

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

if (staged.isEmpty) {
detectingFiles.complete('Detecting staged files');
_logger.info(
'''
final staged = await getStagedDiff(excludeFiles: excludeFiles);

if (staged.isEmpty) {
detectingFiles.complete('Detecting staged files');
_logger.info(
'''
No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` options.''',
);
return ExitCode.success.code;
}
);
return ExitCode.success.code;
}

final files = staged['files'] as List<String>? ?? [];
final files = staged['files'] as List<String>? ?? [];

var message = getDetectedMessage(files: files);
var message = getDetectedMessage(files: files);

detectingFiles.complete(
'$message:\n${files.map((e) => ' $e').join('\n')}',
);
detectingFiles.complete(message);
_logger.info(files.map((e) => ' $e').join('\n'));

final s = _logger.progress('The AI is analyzing your changes');
final s = _logger.progress('The AI is analyzing your changes');

var messages = <String>[];
var messages = <String>[];

try {
final locale = await getLocale();
final maxLength = await getMaxLength();

Expand Down Expand Up @@ -297,47 +299,38 @@ No staged changes found. Stage your changes manually, or automatically stage all
diff: staged['diff'] as String,
isConventional: isConventional,
);
} finally {
s.complete('Changes analyzed');
}

s.fail('Changes analyzed');

if (messages.isEmpty) {
_logger.info('No commit messages were generated. Try again.');
return ExitCode.success.code;
}
if (messages.isEmpty) {
_logger.info('No commit messages were generated. Try again.');
return ExitCode.success.code;
}

if (messages.length == 1) {
message = messages.first;
if (messages.length == 1) {
message = messages.first;

final confirmed =
_logger.confirm('Use this commit message?\n\n $message\n');
final confirmed =
_logger.confirm('\nUse this commit message?\n\n $message\n\n');

if (!confirmed) {
_logger.info('Commit message canceled.');
return ExitCode.software.code;
}
} else {
final selected = _logger.chooseOne(
'Pick a commit message to use: ',
choices: messages,
);

if (selected.isEmpty) {
_logger.info('Commit message canceled.');
return ExitCode.software.code;
}

message = selected;
if (!confirmed) {
s.fail('Commit message canceled.');
return ExitCode.software.code;
}
} else {
final selected = _logger.chooseOne(
'Pick a commit message to use: ',
choices: messages,
);

await Process.run('git', ['commit', '-m', message]);
message = selected;
}

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

return ExitCode.success.code;
} catch (e) {
print(e.runtimeType);
print(e);
exit(0);
}
s.complete('Successfully committed');

return ExitCode.success.code;
}
}
1 change: 0 additions & 1 deletion lib/src/commands/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
export 'config_command.dart';
export 'sample_command.dart';
export 'update_command.dart';

2 changes: 1 addition & 1 deletion lib/src/utils/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Future<void> setCount(int value) async {

// get generate commit message count
Future<int> getCount() async {
final value = await getData('generate_count',1);
final value = await getData('generate_count', 1);
return value as int;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/prompt.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';

String get conventionalPrompt {
var map = {
final map = {
'docs': 'Documentation only changes',
'style': '''
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)''',
Expand Down
3 changes: 1 addition & 2 deletions lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//GENERATED BARREL FILE
//GENERATED BARREL FILE
export 'config.dart';
export 'error.dart';
export 'git.dart';
export 'openai.dart';
export 'prompt.dart';

0 comments on commit d3d0301

Please sign in to comment.