<commit_before>using System;
using System.IO;
using Mono.Options;
using System.Reflection;

namespace IPDL {
  class Cli {
    private Downloader downloader;

    public Cli(Downloader downloader) {
      this.downloader = downloader;
    }

    public Cli() : this(new Downloader()) {}

    public void Run(string[] args) {
      var opts = new OptionSet(){
        {"d=|download-path=", v => Directory.SetCurrentDirectory(v)},
        {"v|version",         v => ShowVersion()},
        {"h|help",            v => ShowHelp()}
      };
      var identifiers = opts.Parse(args);
      if (identifiers.Count == 0)
        ShowHelp();
      foreach (var identifier in identifiers) {
        Download(identifier);
      }
    }

    private void ShowVersion() {
      var details = Assembly.GetName();
      Console.WriteLine("{0} version {1}", details.Name, details.Version);
      Environment.Exit(0);
    }

    private void ShowHelp() {
      Console.WriteLine((new StreamReader(Assembly.GetManifestResourceStream("help.txt"))).ReadToEnd());
      Environment.Exit(0);
    }

    private Assembly Assembly {
      get { return Assembly.GetExecutingAssembly(); }
    }

    private void Download(string identifier) {
      var pid = Util.ExtractPid(identifier);
      if (pid == null) {
        Console.WriteLine("ERROR: {0} is not recognised as a programme ID", identifier);
        return;
      }
      downloader.Download(pid, DownloadStart, DownloadProgress, DownloadEnd);
    }

    private void DownloadStart(string filename) {
      Console.WriteLine("Downloading: {0}", filename);
    }

    private void DownloadProgress(int bytesDownloaded, int total) {
      Console.CursorLeft = 0;
      Console.Write("{1:0.0}% complete; {0} left        ",
                    Util.SIFormat(total - bytesDownloaded, "B"),
                    (bytesDownloaded * 100.0) / total);
      Console.CursorLeft -= 8;
    }

    private void DownloadEnd(DownloadStatus status, string message) {
      Console.WriteLine();
      switch (status) {
        case DownloadStatus.Complete:
          Console.WriteLine("SUCCESS: Downloaded to {0}", message);
          break;
        case DownloadStatus.Incomplete:
          Console.WriteLine("FAILED: Incomplete download saved as {0}", message);
          break;
        case DownloadStatus.AlreadyExists:
          Console.WriteLine("SKIP: File exists: {0}", message);
          break;
        case DownloadStatus.Unavailable:
          Console.WriteLine("ERROR: {0} is currently unavailable", message);
          break;
      }
    }
  }
}
<commit_msg>Eliminated the ugly Exit() calls from ShowHelp and ShowVersion. Run is now simply a method that always returns.<commit_after>using System;
using System.IO;
using Mono.Options;
using System.Reflection;

namespace IPDL {
  class Cli {
    private Downloader downloader;

    public Cli(Downloader downloader) {
      this.downloader = downloader;
    }

    public Cli() : this(new Downloader()) {}

    public void Run(string[] args) {
      bool showHelp    = false;
      bool showVersion = false;
      var opts = new OptionSet(){
        {"d=|download-path=", v => Directory.SetCurrentDirectory(v)},
        {"v|version",         v => showVersion = true},
        {"h|help",            v => showHelp = true}
      };
      var identifiers = opts.Parse(args);
      if (showVersion) {
        ShowVersion();
        return;
      }
      if (showHelp || identifiers.Count == 0) {
        ShowHelp();
        return;
      }
      foreach (var identifier in identifiers) {
        Download(identifier);
      }
    }

    private void ShowVersion() {
      var details = Assembly.GetName();
      Console.WriteLine("{0} version {1}", details.Name, details.Version);
    }

    private void ShowHelp() {
      Console.WriteLine((new StreamReader(Assembly.GetManifestResourceStream("help.txt"))).ReadToEnd());
    }

    private Assembly Assembly {
      get { return Assembly.GetExecutingAssembly(); }
    }

    private void Download(string identifier) {
      var pid = Util.ExtractPid(identifier);
      if (pid == null) {
        Console.WriteLine("ERROR: {0} is not recognised as a programme ID", identifier);
        return;
      }
      downloader.Download(pid, DownloadStart, DownloadProgress, DownloadEnd);
    }

    private void DownloadStart(string filename) {
      Console.WriteLine("Downloading: {0}", filename);
    }

    private void DownloadProgress(int bytesDownloaded, int total) {
      Console.CursorLeft = 0;
      Console.Write("{1:0.0}% complete; {0} left        ",
                    Util.SIFormat(total - bytesDownloaded, "B"),
                    (bytesDownloaded * 100.0) / total);
      Console.CursorLeft -= 8;
    }

    private void DownloadEnd(DownloadStatus status, string message) {
      Console.WriteLine();
      switch (status) {
        case DownloadStatus.Complete:
          Console.WriteLine("SUCCESS: Downloaded to {0}", message);
          break;
        case DownloadStatus.Incomplete:
          Console.WriteLine("FAILED: Incomplete download saved as {0}", message);
          break;
        case DownloadStatus.AlreadyExists:
          Console.WriteLine("SKIP: File exists: {0}", message);
          break;
        case DownloadStatus.Unavailable:
          Console.WriteLine("ERROR: {0} is currently unavailable", message);
          break;
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.1175925925925926, 'fraction_numerical': 0.007407407407407408, 'mean_word_length': 2.4666238767650834, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 58, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1405478', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1426, 'n_words': 377}