<commit_before>part of hop;

/**
 * Deprecated in favor of [HopConfig].
 *
 * Just a name change.
 */
@deprecated
class BaseConfig extends HopConfig {
}

class HopConfig {
  static final RegExp _validNameRegExp = new RegExp(r'^[a-z]([a-z0-9_\-]*[a-z0-9])?$');
  static const _reservedTasks = const[COMPLETION_COMMAND_NAME];
  final Map<String, Task> _tasks = new Map<String, Task>();

  String _helpTaskName;
  Level _logLevel = Level.INFO;

  ReadOnlyCollection<String> _sortedTaskNames;

  HopConfig();

  Level get logLevel => _logLevel;

  void set logLevel(Level value) {
    require(!isFrozen, "Cannot change logLevel. Frozen.");
    requireArgumentNotNull(value, 'value');
    _logLevel = value;
  }

  /// Can only be accessed when frozen
  /// Always sorted
  List<String> get taskNames {
    requireFrozen();
    return _sortedTaskNames;
  }

  bool hasTask(String taskName) {
    requireFrozen();
    return _tasks.containsKey(taskName);
  }

  Task _getTask(String taskName) {
    return _tasks[taskName];
  }

  void addSync(String name, Func1<TaskContext, bool> func) {
    addTask(name, new Task.sync(func));
  }

  void addAsync(String name, TaskDefinition execFuture) {
    addTask(name, new Task.async(execFuture));
  }

  void addTask(String name, Task task) {
    require(!isFrozen, "Cannot add a task. Frozen.");
    requireArgumentNotNullOrEmpty(name, 'name');
    requireArgumentContainsPattern(_validNameRegExp, name, 'name');
    requireArgument(!_reservedTasks.contains(name), 'task',
        'The provided task has a reserved name');
    requireArgument(!_tasks.containsKey(name), 'task',
        'A task with name ${name} already exists');

    requireArgumentNotNull(task, 'task');
    _tasks[name] = task;
  }

  void requireFrozen() {
    if(!isFrozen) {
      throw "not frozen!";
    }
  }

  void _addHelpTask(String helpTaskName) {
    assert(_helpTaskName == null);
    addTask(helpTaskName, _getHelpTask());
    _helpTaskName = helpTaskName;
  }

  void freeze() {
    require(!isFrozen, "Already frozen.");
    final list = new List<String>.from(_tasks.keys);
    list.sort();
    _sortedTaskNames = new ReadOnlyCollection<String>.wrap(list);
  }

  bool get isFrozen => _sortedTaskNames != null;

  /**
   * Defaults to [print] method from `dart:io`
   */
  void doPrint(Object value) {
    print(value);
  }
}<commit_msg>hop: HopConfig: moving things around<commit_after>part of hop;

/**
 * Deprecated in favor of [HopConfig].
 *
 * Just a name change.
 */
@deprecated
class BaseConfig extends HopConfig {
}

class HopConfig {
  static final RegExp _validNameRegExp = new RegExp(r'^[a-z]([a-z0-9_\-]*[a-z0-9])?$');
  static const _reservedTasks = const[COMPLETION_COMMAND_NAME];
  final Map<String, Task> _tasks = new Map<String, Task>();

  String _helpTaskName;
  Level _logLevel = Level.INFO;

  ReadOnlyCollection<String> _sortedTaskNames;

  HopConfig();

  Level get logLevel => _logLevel;

  void set logLevel(Level value) {
    require(!isFrozen, "Cannot change logLevel. Frozen.");
    requireArgumentNotNull(value, 'value');
    _logLevel = value;
  }

  /// Can only be accessed when frozen
  /// Always sorted
  List<String> get taskNames {
    requireFrozen();
    return _sortedTaskNames;
  }

  bool hasTask(String taskName) {
    requireFrozen();
    return _tasks.containsKey(taskName);
  }

  void addSync(String name, Func1<TaskContext, bool> func) {
    addTask(name, new Task.sync(func));
  }

  void addAsync(String name, TaskDefinition execFuture) {
    addTask(name, new Task.async(execFuture));
  }

  void addTask(String name, Task task) {
    require(!isFrozen, "Cannot add a task. Frozen.");
    requireArgumentNotNullOrEmpty(name, 'name');
    requireArgumentContainsPattern(_validNameRegExp, name, 'name');
    requireArgument(!_reservedTasks.contains(name), 'task',
        'The provided task has a reserved name');
    requireArgument(!_tasks.containsKey(name), 'task',
        'A task with name ${name} already exists');

    requireArgumentNotNull(task, 'task');
    _tasks[name] = task;
  }

  void requireFrozen() {
    if(!isFrozen) {
      throw "not frozen!";
    }
  }

  void freeze() {
    require(!isFrozen, "Already frozen.");
    final list = new List<String>.from(_tasks.keys);
    list.sort();
    _sortedTaskNames = new ReadOnlyCollection<String>.wrap(list);
  }

  bool get isFrozen => _sortedTaskNames != null;

  /**
   * Defaults to [print] method from `dart:io`
   */
  void doPrint(Object value) {
    print(value);
  }

  void _addHelpTask(String helpTaskName) {
    assert(_helpTaskName == null);
    addTask(helpTaskName, _getHelpTask());
    _helpTaskName = helpTaskName;
  }

  Task _getTask(String taskName) {
    return _tasks[taskName];
  }
}
{'fraction_non_alphanumeric': 0.12813487881981034, 'fraction_numerical': 0.002107481559536354, 'mean_word_length': 3.7698492462311557, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '3072830', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1528, 'n_words': 376}