#!perl6

use Tomty;

sub MAIN (

  $thing?,
  Bool :$verbose    = False, 
  Bool :$all        = False,
  Str  :$skip,
  Str  :$only,
  Bool :$log        = False,
  Bool :$completion = False, 
  Bool :$clean      = False, 
  Bool :$help       = False, 
  Bool :$list       = False, 
  Bool :$remove     = False, 
  Bool :$cat        = False, 
  Bool :$lines      = False, 
  Bool :$edit       = False, 
  Bool :$env-set    = False, 
  Bool :$env-edit   = False, 
  Bool :$env-list   = False, 
  Bool :$env-cat    = False, 
  Str  :$env 

)

{

  my %config = init();
  
  if ($completion) { # install completion

    completion-install();

  } elsif ($cat && $thing) { # cat test

    test-cat("{$*CWD}/.tomty", $thing, %( lines => $lines ));

  } elsif ($list) { # tests list

    test-list-print("{$*CWD}/.tomty")

  } elsif ($help) { # help page

    tomty-help();

  } elsif ($clean) { # clean cache

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

  } elsif ($thing && $remove) { # remove test

    test-remove("{$*CWD}/.tomty",$thing );

  } elsif ($edit && $thing) { # edir test

    test-edit("{$*CWD}/.tomty",$thing );

  } elsif ($env-edit && $thing) { # edit env

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

  } elsif ($env-cat && $thing) { # cat env

    environment-cat("{$*CWD}/.tomty/env", $thing, %( lines => $lines ));

  } elsif ($env-list) { # env list

    environment-list("{$*CWD}/.tomty/env");

  } elsif ($env-set && $thing) { # activate env

    environment-set("{$*CWD}/.tomty/env", $thing);

  } elsif ($env-set && !$thing) { # print activated env

    environment-show("{$*CWD}/.tomty/env");

  } elsif ($log && $thing ) {

    test-log($thing);

  } elsif (!$all && $thing ) {

    test-run("{$*CWD}/.tomty", $thing );

  } elsif ($all) {

    test-run-all("{$*CWD}/.tomty", %( verbose-mode => $verbose, skip => $skip, only => $only ));

  } else {

    test-list-print("{$*CWD}/.tomty")

  }

}


