darted_cli 0.2.0 copy "darted_cli: ^0.2.0" to clipboard
darted_cli: ^0.2.0 copied to clipboard

darted_cli is a customizable Dart CLI framework for building command-line tools with hierarchical command structures, argument parsing, and flag management.

example/lib/main.dart

import 'package:darted_cli/yaml_module.dart';

class PackageLogic {
  static doSomething() {}
  // --> Starting 0.1.18, Using Yaml Validation!
  manipulateYaml() async {
    //1. Supply a validation Schema
    final yamlSchema = YamlValidationSchema(
      fields: {
        // --> Starting 0.1.21, Make sure to use YamlValueType enum instead of e.g 'string'.
        'some_key': FieldRule(type: YamlValueType.string, required: true),
        'another_key': FieldRule(
          type: YamlValueType.map,
          required: false,
          nestedFields: {
            'nested_1': FieldRule(type: YamlValueType.string, required: true),
            'nested_2': FieldRule(type: YamlValueType.string, required: false),
          },
        ),
        'some_options': FieldRule(
          type: YamlValueType.map,
          required: false,
          nestedFields: {
            'enable_this': FieldRule(type: YamlValueType.bool, required: false),
            'has_these': FieldRule(type: YamlValueType.list, required: false),
          },
        ),
        // --> Starting 0.1.21, You can add in file/directory path values and validate them!.
        'directoryPathField':
            FieldRule(type: YamlValueType.directoryPath, required: true),
        'filePathField':
            FieldRule(type: YamlValueType.filePath, required: true),
        // --> Starting 0.1.22, You can add in a recursiveMapSchema, This is only relative to YamlValueType.map and would recurse down to every nested Map with key-matching to the rules needed.
        "structure": FieldRule(
          type: YamlValueType.map,
          recursiveMapSchema: {
            RegExp(r'^.*\.dart$'):
                FieldRule(type: YamlValueType.filePath, required: false),
            RegExp(r'^someRecursiveTitleNo\.\\d+$'):
                FieldRule(type: YamlValueType.string, required: true),
          },
        )
      },
    );
    //2. Load the yaml file.
    final yamlFilePath = 'path/to/yaml';
    final YamlMap yamlContent = await YamlModule.load(yamlFilePath);
    //2. Validate the Yaml content with the schema.
    try {
      // --> Starting 0.1.21, To validate file/directory pathes relative to your yaml file, supply the YAML file path, or use `abs:` before absolute pathes.
      await YamlModule.validate(yamlContent, yamlSchema,
          yamlFilePath: yamlFilePath);
      print('Validation successful! The configuration file is correct.');
    } catch (e) {
      print('Validation failed: $e');
    }
    // --> Starting 0.1.19, Extract your Yaml data!
    Map<String, dynamic> yamldata = YamlModule.extractData(yamlContent);
    print('Extracted data: $yamldata');
  }
}
4
likes
160
points
169
downloads

Publisher

verified publishermicazi.dev

Weekly Downloads

darted_cli is a customizable Dart CLI framework for building command-line tools with hierarchical command structures, argument parsing, and flag management.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

enough_ascii_art, path, yaml

More

Packages that depend on darted_cli