#!perl6

use Terminal::ANSIColor;
use Tomtit;

sub MAIN (
  $run?, 
  Bool :$bootstrap  = False, 
  Bool :$verbose    = False, 
  Bool :$quiet      = False,
  Bool :$q          = False, # alias for $quiet 
  Bool :$completion = False, 
  Bool :$clean      = False, 
  Bool :$help       = False, 
  Bool :$list       = False, 
  Bool :$profile    = False, 
  Bool :$remove     = False, 
  Bool :$doc        = False, 
  Bool :$cat        = False, 
  Bool :$lines      = False, 
  Bool :$last       = False, 
  Bool :$edit       = False, 
  Str  :$env 
)

{

  init();

  if ($last) {

    scenario-last("{$*CWD}/.tom");

  } elsif ($completion) {

    completion-install();

  } elsif ($cat && $run) {

    scenario-cat("{$*CWD}/.tom", $run, %( lines => $lines ));

  } elsif ($profile && !$run && !$list ) {

    profile-list();

  } elsif ($profile && $list && $run ) {

    profile-list("{$*CWD}/.tom", $run);

  } elsif ($profile && $run) {

    profile-install("{$*CWD}/.tom", $run);

  } elsif ($list) {

    scenario-list("{$*CWD}/.tom")

  } elsif ($help) {

    tomtit-help();

  } elsif ($clean) {

    tomtit-clean("{$*CWD}/.tom");

  } elsif ($bootstrap) {

    tomtit-bootstrap();

  } elsif ($run && !$remove && !$doc && !$list && ! $edit) {

    die "you can't use both verbose and quiet options" if ( $quiet && $verbose );

    scenario-run("{$*CWD}/.tom",$run, %( quiet => $quiet||$q , verbose => $verbose, env => $env ));

  } elsif ($run && $remove && !$profile && !$list ) {

    scenario-remove("{$*CWD}/.tom",$run );

  } elsif ($run && $doc && !$profile && !$list) {

    scenario-doc("{$*CWD}/.tom",$run );

  } elsif ($edit && $run) {

    scenario-edit("{$*CWD}/.tom",$run );

  } elsif ($edit && $env) {

    environment-edit("{$*CWD}/.tom/env",$env );

  } else {

    scenario-list("{$*CWD}/.tom");

  }

}


