'use strict';

const meow = require('meow');
const version = require('../package.json').version;
const cli = meow(`
  Usage: latestvid [OPTIONS]

  Examples:
    $ latestvid -u marquesbrownlee      # to open latest MKBHD video
    $ latestvid -u marquesbrownlee -d   # to DL latest MKBHD video

  Options:
    -h, --help      Display this help message
    -v, --version   Display current version
    -u, --user      YouTube account to view/dl latest video for
    -d, --download  Include to download video instead of opening
`);

const flags = cli.flags;


};

const exists = function(var_) {
  return var_ !== undefined && typeof(var_) === 'boolean' && String(var_) !== '';
};


let username = flags['u'] || flags['user'];
let download = Boolean(flags['d'] || flags['download']);

module.exports = {
  'user': username,
  'toDl': download,
};

@@ -549,16 +549,126 @@
 flags;%0A%0A
+let error = %7B%0A  'msg': null,%0A  'code': 0%0A%7D;%0A%0Aconst exit = function(msg) %7B%0A  error.msg = msg;%0A  error.code = 1;
 %0A%7D;%0A%0Acon
@@ -782,16 +782,254 @@
 '';%0A%7D;%0A%0A
+if (exists(flags%5B'h'%5D)) %7B%0A  exit(%60$%7Bcli.help%7D%60);%0A%7D else if (exists(flags%5B'v'%5D)) %7B%0A  exit(%60latestvid v$%7Bversion%7D%60);%0A%7D else if (exists(flags%5B'u'%5D) %7C%7C exists(flags%5B'user'%5D)) %7B%0A  exit(%60Expected user account, run 'latestvid -h' for help.%60);%0A%7D%0A
 %0Alet use
@@ -1182,11 +1182,28 @@
 wnload,%0A
+  'error': error%0A
 %7D;%0A

Add validation, exit to cli