feat: init

This commit is contained in:
Darwin Cereska
2026-03-27 19:39:50 +01:00
commit fb3c0a7474
9 changed files with 262 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

3
CHANGELOG.md Normal file
View File

@@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

39
README.md Normal file
View File

@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

30
analysis_options.yaml Normal file
View File

@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

View File

@@ -0,0 +1,6 @@
import 'package:bolt/bolt.dart';
void main() {
var awesome = Awesome();
print('awesome: ${awesome.isAwesome}');
}

8
lib/bolt.dart Normal file
View File

@@ -0,0 +1,8 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.
library;
export 'src/bolt_base.dart';
// TODO: Export any libraries intended for clients of this package.

101
lib/src/bolt_base.dart Normal file
View File

@@ -0,0 +1,101 @@
import 'dart:io';
List<void Function()> initializers = [];
List<void Function()> finalizers = [];
/// enablePrefixMatching allows for automatic prefix matching.
/// Automatic prefix matching can be a dangerous thing to automatically enable in CLI tools.
var enablePrefixMatching = false;
/// enableCommandSorting controls sorting of the slice of commands, which is turned on by default.
var enableCommandSorting = true;
/// enableCaseInsensitive allows case-insensitve command names. (case sensitive by default)
var enableCaseInsensitive = false;
/// enableTraverseRunHooks executes persistent pre-run and post-run hooks from all parents.
/// By default this is disabled, which means only the first run hook to be found is executed.
var enableTraverseRunHooks = false;
/// mousetrapHelpText enables an information splash screen on Windows
/// if the CLI is started from explorer.exe.
/// To disable the mousetrap, just set this variable to blank string ("").
// Works only on Microsoft Windows.
String mousetrapHelpText = """This is a command line tool.
You need to open cmd.exe and run it from there.
""";
/// mousetrapDisplayDuration controls how long the mousetrapHelpText message is displayed on Windows
/// if the CLI is started from explorer.exe. Set to 0 to wait for the return key to be pressed.
/// To disable the mousetrap, just set mousetrapHelpText to a blank string ("").
Duration mousetrapDisplayDuration = Duration(seconds: 5);
/// onInitialize sets the passed functions to be run when each command's
/// execute method is called.
void onInitialize(List<void Function()> y) {
initializers.addAll(y);
}
/// onFinalize sets the passed functions to be run when each command's
/// execute method is terminated.
void onFinalize(List<void Function()> y) {
finalizers.addAll(y);
}
/// ld compares two strings and returns the levenshtein distance between them.
int ld(String s, String t, bool ignoreCase) {
if (ignoreCase) {
s.toLowerCase();
t.toLowerCase();
}
List<List<int>> d = List.generate(
s.length + 1,
(_) => List<int>.filled(t.length + 1, 0),
);
for (int i = 0; i < d.length; i++) {
d[i][0] = i;
}
for (int j = 0; j < d[0].length; j++) {
d[0][j] = j;
}
for (int j = 1; j <= t.length; j++) {
for (int i = 1; i <= s.length; i++) {
if (s[i - 1] == t[j - 1]) {
d[i][j] = d[i - 1][j - 1];
} else {
int min = d[i - 1][j - 1];
if (d[i][j - 1] < min) {
min = d[i][j - 1];
}
if (d[i - 1][j - 1] < min) {
min = d[i - 1][j - 1];
}
d[i][j] = min + 1;
}
}
}
return d[s.length][t.length];
}
/// checkError print the msg with the prefix 'Error:' and exits with error code 1. If the msg is null, it does nothing.
void checkError(Object? msg) {
if (msg != null) {
stderr.write("Error: $msg");
exit(1);
}
}
/// writeStringAndCheck writes a string into a buffer, and checks if the error is not null.
void writeStringAndCheck(StringBuffer b, String s) {
try {
b.write(s);
} catch (e) {
checkError(e);
}
}

15
pubspec.yaml Normal file
View File

@@ -0,0 +1,15 @@
name: bolt
description: A starting point for Dart libraries or applications.
version: 1.0.0
# repository: https://github.com/my_org/my_repo
environment:
sdk: ^3.11.3
# Add regular dependencies here.
dependencies:
# path: ^1.9.0
dev_dependencies:
lints: ^6.0.0
test: ^1.25.6

53
test/bolt_test.dart Normal file
View File

@@ -0,0 +1,53 @@
import 'package:bolt/bolt.dart';
import 'package:test/test.dart';
void main() {
group("Bolt: Check core functions", () {
test("Levenshtein", () {
// Create cases
List<Map<String, dynamic>> tests = [
{
"name": "Equal strings (case sensitive)",
"s": "hello",
"t": "hello",
"ignoreCase": false,
"expected": 0,
},
{
"name": "Equal strings (case insensitive)",
"s": "Hello",
"t": "hello",
"ignoreCase": true,
"expected": 0,
},
{
"name": "Different strings (case sensitive)",
"s": "kitten",
"t": "sitting",
"ignoreCase": false,
"expected": 3,
},
{
"name": "Different strings (case insensitive)",
"s": "Kitten",
"t": "Sitting",
"ignoreCase": true,
"expected": 3,
},
{
"name": "One empty string",
"s": "abc",
"t": "",
"ignoreCase": false,
"expected": 3,
},
];
// Run tests
for (var t in tests) {
print("Running test: ${t["name"]}");
expect(ld(t["s"], t["t"], t["ignoreCase"]), t["expected"]);
}
});
});
}