text: // Generated by CoffeeScript 2.5.1
  (function() {
    var CLI, RemoteObject, Spinner, c, cloud, globalScope, log, olog, ostr, printError, printSuccess, remotehandlermodule, request, urlHandler, userConfig;
  
    remotehandlermodule = {
      name: "remotehandlermodule"
    };
  
    //region modulesFromEnvironment
    //region node_modules imports
    CLI = require('clui');
  
    Spinner = CLI.Spinner;
  
    request = require("request-promise");
  
    c = require("chalk");
  
    //endregion
  
    //region localModules
    cloud = null;
  
    userConfig = null;
  
    globalScope = null;
  
    urlHandler = null;
  
    //endregion
    //endregion
  
    //region logPrintFunctions
    //#############################################################################
    log = function(arg) {
      if (allModules.debugmodule.modulesToDebug["remotehandlermodule"] != null) {
        console.log("[remotehandlermodule]: " + arg);
      }
    };
  
    olog = function(o) {
      return log("\n" + ostr(o));
    };
  
    ostr = function(o) {
      return JSON.stringify(o, null, 4);
    };
  
    printSuccess = function(arg) {
      return console.log(c.green(arg));
    };
  
    printError = function(arg) {
      return console.log(c.red(arg));
    };
  
    //endregion
    //##############################################################################
    remotehandlermodule.initialize = function() {
      log("remotehandlermodule.initialize");
      cloud = allModules.cloudservicemodule;
      userConfig = allModules.userconfigmodule;
      globalScope = allModules.globalscopemodule;
      urlHandler = allModules.urlhandlermodule;
    };
  
    //region classes
    RemoteObject = class RemoteObject {
      constructor(service1, repoName1) {
        var httpsBase, sshBase;
        this.service = service1;
        this.repoName = repoName1;
        log("RemoteObject.constructor");
        if (this.repoName.lastIndexOf(".git") === (this.repoName.length - 4)) {
          this.repoName = this.repoName.substring(0, this.repoName.length - 4);
        }
        httpsBase = cloud.getHTTPSBaseForService(this.service);
        this.httpsURL = httpsBase + "/" + this.repoName + ".git";
        log("constructed httpsURL: " + this.httpsURL);
        sshBase = cloud.getSSHBaseForService(this.service);
        this.sshURL = sshBase + "/" + this.repoName + ".git";
        log("constructed sshURL: " + this.sshURL);
        this.reachability = false;
        this.reachabilityChecked = false;
      }
  
      async checkReachability() {
        var err, options, status;
        if (globalScope.repoIsInScope(this.repoName)) {
          return true;
        }
        options = {
          method: 'HEAD',
          uri: this.httpsURL
        };
        status = new Spinner("Checking if " + this.httpsURL + " is reachable...");
        try {
          status.start();
          await request(options);
          printSuccess("Reachable!");
          this.reachability = true;
          return true;
        } catch (error) {
          err = error;
          printError("Not Reachable!");
          this.reachability = false;
          return false;
        } finally {
          status.stop();
          this.reachabilityChecked = true;
        }
      }
  
      getRepo() {
        return this.repoName;
      }
  
      getHTTPS() {
        return this.httpsURL;
      }
  
      getSSH() {
        return this.sshURL;
      }
  
      isReachable() {
        if (!this.reachabilityChecked) {
          console.log(c.yellow("warning! reachability has not been checked yet!"));
        }
        return this.reachability;
      }
  
    };
  
    //endregion
  
    //region exposed functions
    remotehandlermodule.getRemoteObject = function(repoName) {
      var service;
      log("remotehandlermodule.getRemoteObject");
      service = globalScope.serviceForRepo(repoName);
      if (service) {
        return new RemoteObject(service, repoName);
      }
      throw "No Service in globalScope for: " + repoName;
    };
  
    
    // service = userConfig.getMasterService()
    // return new RemoteObject(service, repoName)
    remotehandlermodule.createNewRemote = function(repoName) {
      var service;
      log("remotehandlermodule.createNewRemote");
      service = userConfig.getMasterService();
      return new RemoteObject(service, repoName);
    };
  
    remotehandlermodule.createRemote = function(serviceOrURL, repoName) {
      log("remotehandlermodule.createRemote");
      if (typeof serviceOrURL === "string" && !repoName) {
        return remotehandlermodule.createRemoteFromURL(serviceOrURL);
      }
      if (typeof service === "object" && (repoName != null)) {
        return new RemoteObject(service, repoName);
      }
      throw "remotehandlermodule.createRemote invalid argument variation";
    };
  
    remotehandlermodule.createRemoteFromURL = function(url) {
      var info;
      log("remotehandlermodule.createRemoteFromURL");
      info = cloud.serviceAndRepoFromURL(url);
      olog(info);
      return new RemoteObject(info.service, info.repoName);
    };
  
    remotehandlermodule.createRemoteFromUserInput = function(value) {
      log("remotehandlermodule.createRemoteFromUserInput");
      if (urlHandler.isURL(value)) {
        if (value.substr(0, 8) !== "https://") {
          return null;
        }
        return remotehandlermodule.createRemoteFromURL(value);
      } else {
        return remotehandlermodule.getRemoteObject(value);
      }
    };
  
    remotehandlermodule.checkIfRemoteIsAvailable = async function(value) {
      var err, remote;
      try {
        remote = remotehandlermodule.createRemoteFromUserInput(value);
        if (remote) {
          return (await remote.checkReachability());
        } else {
          return "Cannot Create Remote!";
        }
      } catch (error) {
        err = error;
        return "Cannot Create Remote!";
      }
    };
  
    //endregion
    module.exports = remotehandlermodule;
  
  }).call(this);
  