<commit_before>
module.exports = stage;

stage.usage = "\nfhc stage <appId> "  
            + "\nfhc stage <appId> --live "
            +"\nfhc stage <appId> [number_of_instances] --live"
            + "\nStage is made to Live environment if the '--live' flag is used";

var log = require("./utils/log");
var fhc = require("./fhc");
var fhreq = require("./utils/request");
var common = require("./common");
var util = require('util');
var async = require('async');
var ini = require('./utils/ini');

// main stage entry point
function stage (args, cb) {
  if(args.length > 4 || args.length == 0) return unknown("stage", cb);

  var clean = ini.get('clean');
  var target = ini.get('live') ? 'live' : 'development';
  var numinstances = 1;

  if (args[1] === "live" || args[1] === "develop") target = args[1];
  else if(Number(args[1])) numinstances = Number(args[1]);
  if (args[2]) clean = args[2] === 'clean';
  if (args[3]) clean = args[3] === 'clean';


  doStage(fhc.appId(args[0]), target, clean, numinstances, cb);
};

function unknown (action, cb) {
  cb("Wrong arguments for or unknown action: " + action + "\nUsage:\n" + stage.usage);
};

// do our staging..
function doStage(app, target, clean, numinstances, cb) {
  var type = 'stage';
  
  log.verbose(target, 'Staging Target');
  if(target === 'live' || target === 'Live') {
    type = 'releasestage';
  }

  // constuct uri and payload
  var uri = "box/srv/1.1/ide/" + fhc.domain + "/app/" + type;
  var payload = {payload:{guid: app, clean: clean, 'numappinstances':numinstances}};
  // finally do our call
  
  common.doApiCall(fhreq.getFeedHenryUrl(), uri, payload, "Error staging app: ", function(err, data) {
    if (err) return cb(err);
    async.map([data.cacheKey], common.waitFor, function(err, results) {
      if (results && results[0] && results[0][0] && results[0][0].status === 'complete') {
        stage.message = "App staged ok..";
      }
      return cb(err, results);
    });
  });
};

// bash completion
stage.completion = function (opts, cb) {
  common.getAppIds(cb); 
};<commit_msg>multiple instances for stage command<commit_after>
module.exports = stage;

stage.usage = "\nfhc stage <appId> "  
            + "\nfhc stage <appId> --live "
            +"\nfhc stage <appId> [number_of_instances] --live"
            + "\nStage is made to Live environment if the '--live' flag is used";

var log = require("./utils/log");
var fhc = require("./fhc");
var fhreq = require("./utils/request");
var common = require("./common");
var util = require('util');
var async = require('async');
var ini = require('./utils/ini');

// main stage entry point
function stage (args, cb) {
  if(args.length > 4 || args.length == 0) return unknown("stage", cb);

  var clean = ini.get('clean');
  var target = ini.get('live') ? 'live' : 'development';
  var numinstances = 1;

  if (args[1] === "live" || args[1] === "develop") target = args[1];
  else if(Number(args[1])) numinstances = Number(args[1]);
  if (args[2]) clean = args[2] === 'clean';
  if (args[3]) clean = args[3] === 'clean';


  doStage(fhc.appId(args[0]), target, clean, numinstances, cb);
};

function unknown (action, cb) {
  cb("Wrong arguments for or unknown action: " + action + "\nUsage:\n" + stage.usage);
};

// do our staging..
function doStage(app, target, clean, numinstances, cb) {
  var type = 'stage';
  
  log.verbose(target, 'Staging Target');
  if(target === 'live' || target === 'Live') {
    type = 'releasestage';
  }

  // constuct uri and payload
  var uri = "box/srv/1.1/ide/" + fhc.domain + "/app/" + type;
  var payload = {payload:{guid: app, clean: clean, 'numappinstances':numinstances}};
  // finally do our call

  common.doApiCall(fhreq.getFeedHenryUrl(), uri, payload, "Error staging app: ", function(err, data) {
    if (err) return cb(err);
    async.map([data.cacheKey], common.waitFor, function(err, results) {
      if (results && results[0] && results[0][0] && results[0][0].status === 'complete') {
        stage.message = "App staged ok..";
      }
      return cb(err, results);
    });
  });
};

// bash completion
stage.completion = function (opts, cb) {
  common.getAppIds(cb); 
};
{'fraction_non_alphanumeric': 0.1932227829848594, 'fraction_numerical': 0.009613073780341264, 'mean_word_length': 3.4323748668796594, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1008813', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1400, 'n_words': 388}