From fb3c0a74743a2b065f8a45327403d4e4a22d5acd Mon Sep 17 00:00:00 2001 From: Darwin Cereska Date: Fri, 27 Mar 2026 19:39:50 +0100 Subject: [PATCH] feat: init --- .gitignore | 7 +++ CHANGELOG.md | 3 ++ README.md | 39 +++++++++++++++ analysis_options.yaml | 30 +++++++++++ example/bolt_example.dart | 6 +++ lib/bolt.dart | 8 +++ lib/src/bolt_base.dart | 101 ++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 15 ++++++ test/bolt_test.dart | 53 ++++++++++++++++++++ 9 files changed, 262 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 README.md create mode 100644 analysis_options.yaml create mode 100644 example/bolt_example.dart create mode 100644 lib/bolt.dart create mode 100644 lib/src/bolt_base.dart create mode 100644 pubspec.yaml create mode 100644 test/bolt_test.dart diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3cceda5 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..effe43c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8831761 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ + + +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. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..dee8927 --- /dev/null +++ b/analysis_options.yaml @@ -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 diff --git a/example/bolt_example.dart b/example/bolt_example.dart new file mode 100644 index 0000000..bb77260 --- /dev/null +++ b/example/bolt_example.dart @@ -0,0 +1,6 @@ +import 'package:bolt/bolt.dart'; + +void main() { + var awesome = Awesome(); + print('awesome: ${awesome.isAwesome}'); +} diff --git a/lib/bolt.dart b/lib/bolt.dart new file mode 100644 index 0000000..40f4020 --- /dev/null +++ b/lib/bolt.dart @@ -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. diff --git a/lib/src/bolt_base.dart b/lib/src/bolt_base.dart new file mode 100644 index 0000000..e3eeef8 --- /dev/null +++ b/lib/src/bolt_base.dart @@ -0,0 +1,101 @@ +import 'dart:io'; + +List initializers = []; +List 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 y) { + initializers.addAll(y); +} + +/// onFinalize sets the passed functions to be run when each command's +/// execute method is terminated. +void onFinalize(List 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> d = List.generate( + s.length + 1, + (_) => List.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); + } +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..7c6a264 --- /dev/null +++ b/pubspec.yaml @@ -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 diff --git a/test/bolt_test.dart b/test/bolt_test.dart new file mode 100644 index 0000000..3fd589d --- /dev/null +++ b/test/bolt_test.dart @@ -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> 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"]); + } + }); + }); +}