<commit_before>import {coins as AllCoins, Coin} from "./coins";

import * as chalk from "chalk";

export interface Options {
  prompt: boolean,
  percent: boolean|number,
  fixed: boolean,
}

export const DefaultOptions: Options = {
  prompt: false,
  percent: false,
  fixed: false,
}

function getCoin(c: string): Coin|null{
  for (var coin of AllCoins){
    if (coin.name.toLowerCase() === c || (coin.names && coin.names.indexOf(c) > -1)){
      return coin;
    }
  }
  return null;
}

/**
 * Parses command line arguments for coins, options, etc.
 * @export
 * @class OptionsParser
 */
export class OptionsParser{
  constructor(args: string[]){
    this.args = args;
  }

  private args: string[];
  private customized: boolean = false;
  coins: Coin[] = AllCoins;
  options: Options = DefaultOptions;

  parse(){
    for (var i = 0; i < this.args.length; i++){
      var arg = this.args[i];

      if (arg.startsWith("--percent")){
        if (arg.includes(":")){
          this.options.percent = Number(arg.split(":")[1]);
        }else{
          this.options.percent = true;
        }
      }else if (arg === "--prompt"){
        this.options.prompt = true;
      }else if (arg === "--fixed"){
        this.options.fixed = true;
      }else{
        this.coinParser(arg);
      }
    }
  }

  private invalidOption(option: string){
    console.warn(chalk.red(`Invalid option: ${chalk.underline(option)}`));
  }

  private coinParser(_arg: string){
    var arg = _arg;

    enum Action {Hide = 0, Show = 1};
    var action;
    if (arg[0] === "-"){
      arg = arg.substring(1);
      action = Action.Hide;
    }else{
      action = Action.Show;
    }

    var coin = getCoin(_arg);

    if (coin === null){
      this.invalidOption(_arg);
      return;
    }

    if (action === Action.Show){
      if (!this.customized){
        this.customized = true;
        for (var i of this.coins){
          i.enabled = false;
        }
      } 
    }
    coin.enabled = !!action;
  }
}
<commit_msg>Fixed coin hiding<commit_after>import {coins as AllCoins, Coin} from "./coins";

import * as chalk from "chalk";

export interface Options {
  prompt: boolean,
  percent: boolean|number,
  fixed: boolean,
}

export const DefaultOptions: Options = {
  prompt: false,
  percent: false,
  fixed: false,
}

function getCoin(c: string): Coin|null{
  for (var coin of AllCoins){
    if (coin.name.toLowerCase() === c || (coin.names && coin.names.indexOf(c) > -1)){
      return coin;
    }
  }
  return null;
}

/**
 * Parses command line arguments for coins, options, etc.
 * @export
 * @class OptionsParser
 */
export class OptionsParser{
  constructor(args: string[]){
    this.args = args;
  }

  private args: string[];
  private customized: boolean = false;
  coins: Coin[] = AllCoins;
  options: Options = DefaultOptions;

  parse(){
    for (var i = 0; i < this.args.length; i++){
      var arg = this.args[i];

      if (arg.startsWith("--percent")){
        if (arg.includes(":")){
          this.options.percent = Number(arg.split(":")[1]);
        }else{
          this.options.percent = true;
        }
      }else if (arg === "--prompt"){
        this.options.prompt = true;
      }else if (arg === "--fixed"){
        this.options.fixed = true;
      }else{
        this.coinParser(arg);
      }
    }
  }

  private invalidOption(option: string){
    console.warn(chalk.red(`Invalid option: ${chalk.underline(option)}`));
  }

  private coinParser(_arg: string){
    var arg = _arg;

    enum Action {Hide = 0, Show = 1};
    var action;
    if (arg[0] === "-"){
      arg = arg.substring(1);
      action = Action.Hide;
    }else{
      action = Action.Show;
    }

    var coin = getCoin(arg);

    if (coin === null){
      this.invalidOption(_arg);
      return;
    }

    if (action === Action.Show){
      if (!this.customized){
        this.customized = true;
        for (var i of this.coins){
          i.enabled = false;
        }
      } 
    }
    coin.enabled = !!action;
  }
}

{'fraction_non_alphanumeric': 0.15746063484128967, 'fraction_numerical': 0.0034991252186953262, 'mean_word_length': 2.371524852569503, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, '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': '4842944', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1290, 'n_words': 338}