<commit_before>import 'dart:io';
import 'package:args/command_runner.dart';
import "package:console/console.dart";
import 'package:dart_style/dart_style.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:recase/recase.dart';
import 'maker.dart';

class PluginCommand extends Command {
  final TextPen _pen = new TextPen();

  @override
  String get name => "plugin";

  @override
  String get description => "Creates a new plug-in within the given project.";

  PluginCommand() {
    argParser
      ..addOption('name',
          abbr: 'n', help: 'Specifies a name for the plug-in class.')
      ..addOption('output-dir',
          help: 'Specifies a directory to create the plug-in class in.',
          defaultsTo: 'lib/src/config/plugins');
  }

  @override
  run() async {
    var pubspec = await Pubspec.load(Directory.current);
    String name;
    if (argResults.wasParsed('name')) name = argResults['name'];

    if (name?.isNotEmpty != true) {
      var p = new Prompter('Name of Controller class: ');
      name = await p.prompt(checker: (s) => s.isNotEmpty);
    }

    List<MakerDependency> deps = [
      const MakerDependency('angel_framework', '^1.0.0')
    ];

    var rc = new ReCase(name);
    final pluginDir = new Directory.fromUri(
        Directory.current.uri.resolve(argResults['output-dir']));
    final pluginFile =
        new File.fromUri(pluginDir.uri.resolve("${rc.snakeCase}.dart"));
    if (!await pluginFile.exists()) await pluginFile.create(recursive: true);
    await pluginFile.writeAsString(
        new DartFormatter().format(_generatePlugin(pubspec, rc)));

    if (deps.isNotEmpty) await depend(deps);

    _pen.green();
    _pen(
        '${Icon.CHECKMARK} Successfully generated plug-in file "${pluginFile.absolute.path}".');
    _pen();
  }

  String _generatePlugin(Pubspec pubspec, ReCase rc) {
    return '''
library ${pubspec.name}.src.config.plugins.${rc.snakeCase};

import 'dart:async';
import 'package:angel_framework/angel_framework.dart';
<commit_msg>Update plugin gen<commit_after>import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:dart_style/dart_style.dart';
import 'package:io/ansi.dart';
import 'package:prompts/prompts.dart' as prompts;
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:recase/recase.dart';
import '../../util.dart';
import 'maker.dart';

class PluginCommand extends Command {
  @override
  String get name => "plugin";

  @override
  String get description => "Creates a new plug-in within the given project.";

  PluginCommand() {
    argParser
      ..addOption('name',
          abbr: 'n', help: 'Specifies a name for the plug-in class.')
      ..addOption('output-dir',
          help: 'Specifies a directory to create the plug-in class in.',
          defaultsTo: 'lib/src/config/plugins');
  }

  @override
  run() async {
    var pubspec = await loadPubspec();
    String name;
    if (argResults.wasParsed('name')) name = argResults['name'] as String;

    if (name?.isNotEmpty != true) {
      name = prompts.get('Name of plug-in class');
    }

    List<MakerDependency> deps = [
      const MakerDependency('angel_framework', '^1.0.0')
    ];

    var rc = new ReCase(name);
    final pluginDir = new Directory.fromUri(
        Directory.current.uri.resolve(argResults['output-dir'] as String));
    final pluginFile =
        new File.fromUri(pluginDir.uri.resolve("${rc.snakeCase}.dart"));
    if (!await pluginFile.exists()) await pluginFile.create(recursive: true);
    await pluginFile.writeAsString(
        new DartFormatter().format(_generatePlugin(pubspec, rc)));

    if (deps.isNotEmpty) await depend(deps);

    print(green.wrap(
        '$checkmark Successfully generated plug-in file "${pluginFile.absolute.path}".'));
  }

  String _generatePlugin(Pubspec pubspec, ReCase rc) {
    return '''
library ${pubspec.name}.src.config.plugins.${rc.snakeCase};

import 'dart:async';
import 'package:angel_framework/angel_framework.dart';

{'fraction_non_alphanumeric': 0.1417854463615904, 'fraction_numerical': 0.0015003750937734434, 'mean_word_length': 3.7058823529411766, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5195807', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1244, 'n_words': 294}