#!/usr/bin/env node

/*
  Insulin On Board (IOB) calculations.

  IOB is also known as "Bolus on Board", "Active Insulin", or "Insulin Remaining"

  Released under MIT license. See the accompanying LICENSE.txt file for
  full terms and conditions

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.

*/

var find_insulin = require('oref0/lib/iob/history');
function usage ( ) {
    console.log('usage: ', process.argv.slice(0, 2), '<pumphistory.json> <profile.json>');
}

if (!module.parent) {
  var iob_input = process.argv[2]
  if ([null, '--help', '-h', 'help'].indexOf(iob_input) > 0) {
    usage( );
    process.exit(0)
  }
  var profile_input = process.argv[3]
  var clock_input = process.argv[4]

  if (!iob_input || !profile_input) {
    usage( );
    process.exit(1);
  }

  var cwd = process.cwd();
  var all_data = require(cwd + '/' + iob_input);
  var profile_data = require(cwd + '/' + profile_input);

  var inputs = {
    history: all_data
  , profile: profile_data
  };

  var treatments = find_insulin(inputs);

  console.log(JSON.stringify(treatments));
}


@@ -778,404 +778,366 @@
 ');%0A
-function usage ( ) %7B%0A    console.log('usage: ', process.argv.slice(0, 2), '%3Cpumphistory.json%3E %3Cprofile.json%3E');%0A%7D%0A%0Aif (!module.parent) %7B%0A  var iob_input = process.argv%5B2%5D%0A  if (%5Bnull, '--help', '-h', 'help'%5D.indexOf(iob_input) %3E 0) %7B%0A    usage( );%0A    process.exit(0)%0A  %7D%0A  var profile_input = process.argv%5B3%5D%0A  var clock_input = process.argv%5B4%5D%0A%0A  if (!iob_input %7C%7C !profile_input) %7B%0A    usage( 
+%0Aif (!module.parent) %7B%0A  var argv = require('yargs')%0A    .usage('$0 %3Cpumphistory.json%3E %3Cprofile.json%3E')%0A    .demand(2)%0A    .strict(true)%0A    .help('help');%0A%0A  var params = argv.argv;%0A  var inputs = params._;%0A%0A  var iob_input = inputs%5B0%5D;%0A  var profile_input = inputs%5B1%5D;%0A%0A  if (inputs.length %3E 2) %7B%0A    argv.showHelp();%0A    console.error(%22Too many arguments%22
 );%0A 

Migrate oref0-find-insulin-uses.js to yargs argument processing. (#1120)