### ----------------------------------------------------
### -- Pakku
### -- Licenses: Artistic-2.0
### -- Authors: Haytham Elganiny
### -- File: lib/Pakku/Grammar/Cmd.rakumod
### ----------------------------------------------------
### -- Chunk 2 of 2
 method TOP:sym<nuke> ( $/ ) {

    my %cmd;

    %cmd<cmd>        = 'nuke';
    %cmd<pakku>      = $<pakkuopt>».made.hash if defined $<pakkuopt>;
    %cmd<nuke>       = $<nukeopt>».made.hash  if defined $<nukeopt>;
    %cmd<nuke><nuke> = $<nukes>.made;

    make %cmd;

  }


  method TOP:sym<config> ( $/ ) {

    my %cmd;

    %cmd<cmd>          = 'config';
    %cmd<pakku>        = $<pakkuopt>».made.hash   if defined $<pakkuopt>;
    %cmd<config>       = $<config-cmd>.made.hash  if defined $<config-cmd>;

    make %cmd;

  }


  method TOP:sym<help> ( $/ ) {

    my %cmd;

    %cmd<cmd>       = 'help';
    %cmd<pakku>     = $<pakkuopt>».made.hash if defined $<pakkuopt>;
    %cmd<help><cmd> = $<cmd>.so ?? $<cmd>.made !! '';

    make %cmd;

  }

  method cmd:sym<add>      ( $/ ) { make 'add'      }
  method cmd:sym<update>   ( $/ ) { make 'update'  }
  method cmd:sym<build>    ( $/ ) { make 'build'    }
  method cmd:sym<test>     ( $/ ) { make 'test'     }
  method cmd:sym<remove>   ( $/ ) { make 'remove'   }
  method cmd:sym<download> ( $/ ) { make 'download' }
  method cmd:sym<list>     ( $/ ) { make 'list'     }
  method cmd:sym<search>   ( $/ ) { make 'search'   }
  method cmd:sym<nuke>     ( $/ ) { make 'nuke'     }
  method cmd:sym<config>   ( $/ ) { make 'config'   }
  method cmd:sym<help>     ( $/ ) { make 'help'     }


  method config-cmd:sym<config-view>( $/ ) { 
    make %( :operation<view> )
  }

  method config-cmd:sym<config-new>( $/ ) {
    make  %( operation =>  ~$<config-new> )
  }

  method config-cmd:sym<config-reset>( $/ ) {
    make %( operation => ~$<reset> )
  }

  method config-cmd:sym<config-module-view>( $/ ) {
    make %( :operation<view>, module => ~$<config-module-any> )
  }

  method config-cmd:sym<config-module-reset>( $/ ) {
    make %(
      module    => ~$<config-module-any>,
      operation => ~$<reset>,
    )
  }

  method config-cmd:sym<config-module-unset>( $/ ) {
    make %(
      module    => ~$<config-module-any>,
      operation => ~$<unset>,
    )
  }

  method config-cmd:sym<config-recman-name-view-option>( $/ ) {

    my Str @option = @<key-option>.map( ~* ); 

    make %(
      module    => ~$<config-module-recman>,
      operation => 'view',
      recman-name => ~$<recman-name>,
      :@option,
    )
  }

  method config-cmd:sym<config-log-level-view-option>( $/ ) {

    my Str @option = @<key-option>.map( ~* ); 

    make %(
      module    => ~$<config-module-log>,
      operation => 'view',
      log-level => ~$<log-level>,
      :@option,
    )
  }

  method config-cmd:sym<config-recman-name-view>( $/ ) {

    make %(
      module    => ~$<config-module-recman>,
      operation => 'view',
      recman-name => ~$<recman-name>,
    )
  }

  method config-cmd:sym<config-log-level-view>( $/ ) {

    make %(
      module    => ~$<config-module-log>,
      operation => 'view',
      log-level => ~$<log-level>,
    )
  }



  method config-cmd:sym<config-module-view-option>( $/ ) {

    my Str @option = @<key-option>.map( ~* ); 

    make %(
      module    => ~$<config-module>,
      operation => 'view',
      :@option,
    )
  }

  method config-cmd:sym<config-module-unset-option>( $/ ) {

    my Pair @option = @<key-option>.map( ~* => Nil ); 

    make %(
      module    => ~$<config-module>,
      :@option,
    )
  }

  method config-cmd:sym<config-module-disable>( $/ ) {

    my Pair @option = @<key-option>.map( ~* => False ); 

    make %(
      module    => ~$<config-module>,
      :@option,
    )
  }

  method config-cmd:sym<config-module-enable>( $/ ) {

    my Pair @option = @<key-option>.map( ~* => True ); 

    make %(
      module    => ~$<config-module>,
      :@option,
    )
  }

  method config-cmd:sym<config-module-set>( $/ ) {

    my Pair @option = @<keyval-option>.map( { ~.<key> => ~.<value> } ); 

    make %(
      module    => ~$<config-module>,
      :@option,
    )
  }

  method config-cmd:sym<config-module-recman-set>( $/ ) {

    my Pair @option = @<keyval-option>.map( { ~.<key> => ~.<value> } ); 

    make %(
      module      => ~$<config-module-recman>,
      recman-name => ~$<recman-name>, 
      :@option,
    )
  }


  method config-cmd:sym<config-module-recman-enable>( $/ ) {
    make %(
      module      => ~$<config-module-recman>,
      operation   => ~$<enable>, 
      recman-name => ~$<recman-name>, 
    )
  }

  method config-cmd:sym<config-module-recman-disable>( $/ ) {
    make %(
      module      => ~$<config-module-recman>,
      operation   => ~$<disable>, 
      recman-name => ~$<recman-name>, 
    )
  }

  method config-cmd:sym<config-module-recman-unset>( $/ ) {
    make %(
      module      => ~$<config-module-recman>,
      operation   => ~$<unset>, 
      recman-name => ~$<recman-name>, 
    )
  }

  method config-cmd:sym<config-module-log-set>( $/ ) {
    my Pair @option = @<log-level-option>.map( { ~.<sym> => ~.<value> } ); 

    make %(
      module    => ~$<config-module-log>,
      log-level => ~$<log-level>, 
      :@option
    )
  }

  method config-cmd:sym<config-module-log-unset>( $/ ) {
    make %(
      module    => ~$<config-module-log>,
      operation => ~$<unset>, 
      log-level => ~$<log-level>, 
    )
  }

  method pakkuopt:sym<pretty>   ( $/ ) { make $<pretty>.made               }
  method pakkuopt:sym<force>    ( $/ ) { make $<force>.made                }
  method pakkuopt:sym<async>    ( $/ ) { make $<async>.made                }
  method pakkuopt:sym<recman>   ( $/ ) { make $<recman>.made               }
  method pakkuopt:sym<norecman> ( $/ ) { make $<norecman>.made             }
  method pakkuopt:sym<cache>    ( $/ ) { make $<cache>.made                }
  method pakkuopt:sym<yolo>     ( $/ ) { make ( :yolo )                    }
  method pakkuopt:sym<please>   ( $/ ) { make ( :please )                  }
  method pakkuopt:sym<dont>     ( $/ ) { make ( :dont )                    }
  method pakkuopt:sym<verbose>  ( $/ ) { make ( verbose => $<level>.made ) }
  method pakkuopt:sym<cores>    ( $/ ) { make ( cores => $<number>.Int ) }
  method pakkuopt:sym<config>   ( $/ ) { make ( config  => $<path>.made  ) }
  method pakkuopt:sym<bar>      ( $/ ) { make $<bar>.made                  }
  method pakkuopt:sym<spinner>  ( $/ ) { make $<spinner>.made              }

  method addopt:sym<deps>       ( $/ ) { make $<deps>.made       }
  method addopt:sym<build>      ( $/ ) { make $<build>.made      }
  method addopt:sym<test>       ( $/ ) { make $<test>.made       }
  method addopt:sym<xtest>      ( $/ ) { make $<xtest>.made      }
  method addopt:sym<serial>     ( $/ ) { make $<serial>.made     }
  method addopt:sym<contained>  ( $/ ) { make $<contained>.made  }
  method addopt:sym<precompile> ( $/ ) { make $<precompile>.made }
  method addopt:sym<to>         ( $/ ) { make ( to => $<repo>.Str ) }
  method addopt:sym<exclude>    ( $/ ) { @*exclude.push: $<spec>.made; make ( exclude => @*exclude ) }


  method updateopt:sym<clean>      ( $/ ) { make $<clean>.made  }
  method updateopt:sym<deps>       ( $/ ) { make $<deps>.made  }
  method updateopt:sym<build>      ( $/ ) { make $<build>.made }
  method updateopt:sym<test>       ( $/ ) { make $<test>.made  }
  method updateopt:sym<xtest>      ( $/ ) { make $<xtest>.made }
  method updateopt:sym<precompile> ( $/ ) { make $<precompile>.made }
  method updateopt:sym<in>         ( $/ ) { make ( in => $<repo>.Str ) }
  method updateopt:sym<exclude>    ( $/ ) { @*exclude.push: $<spec>.made; make ( exclude => @*exclude ) }


  method removeopt:sym<from> ( $/ ) { make ( from => $<repo>.Str ) }

  method testopt:sym<build> ( $/ ) { make $<build>.made }
  method testopt:sym<xtest> ( $/ ) { make $<xtest>.made }

  method listopt:sym<details> ( $/ ) { make $<details>.made }

  method listopt:sym<repo> ( $/ ) { make ( repo => $<repo>.Str ) }

  method searchopt:sym<details>    ( $/ ) { make $<details>.made            }
  method searchopt:sym<relaxed>    ( $/ ) { make $<relaxed>.made            }
  method searchopt:sym<latest>     ( $/ ) { make $<latest>.made            }
  method searchopt:sym<count>      ( $/ ) { make ( count => $<number>.Int ) }

  method stateopt:sym<clean>   ( $/ ) { make $<clean>.made   }
  method stateopt:sym<updates> ( $/ ) { make $<updates>.made }

  method updates:sym<updates>   ( $/ ) { make ( :updates  ) }
  method updates:sym<up>        ( $/ ) { make ( :updates  ) }
  method updates:sym<noupdates> ( $/ ) { make ( :!updates ) }
  method updates:sym<nu>        ( $/ ) { make ( :!updates ) }

  method deps:sym<only>    ( $/ )  { make ( deps => 'only' )    }
  method deps:sym<runtime> ( $/ )  { make ( deps => 'runtime' ) }
  method deps:sym<test>    ( $/ )  { make ( deps => 'test' )    }
  method deps:sym<build>   ( $/ )  { make ( deps => 'build' )   }
  method deps:sym<deps>    ( $/ )  { make ( :deps )             }
  method deps:sym<nodeps>  ( $/ )  { make ( :!deps )            }

  method pretty:sym<pretty>   ( $/ )  { make ( :pretty  ) }
  method pretty:sym<p>        ( $/ )  { make ( :pretty  ) }
  method pretty:sym<ℙ>        ( $/ )  { make ( :pretty  ) }
  method pretty:sym<𝛒>        ( $/ )  { make ( :pretty  ) }
  method pretty:sym<℘>        ( $/ )  { make ( :pretty  ) }
  method pretty:sym<nopretty> ( $/ )  { make ( :!pretty ) }
  method pretty:sym<np>       ( $/ )  { make ( :!pretty ) }

  method bar:sym<bar>   ( $/ )  { make ( :bar  ) }
  method bar:sym<b>     ( $/ )  { make ( :bar  ) }
  method bar:sym<nobar> ( $/ )  { make ( :!bar ) }
  method bar:sym<nb>    ( $/ )  { make ( :!bar ) }

  method spinner:sym<spinner>   ( $/ )  { make ( :spinner  ) }
  method spinner:sym<s>         ( $/ )  { make ( :spinner  ) }
  method spinner:sym<nospinner> ( $/ )  { make ( :!spinner ) }
  method spinner:sym<ns>        ( $/ )  { make ( :!spinner ) }

  method async:sym<async>   ( $/ )  { make ( :async  ) }
  method async:sym<noasync> ( $/ )  { make ( :!async ) }
  method async:sym<sync>    ( $/ )  { make ( :!async ) }

  method recman   ( $/ )  { make ( $<recman-name> ?? :recman(   ~$<recman-name> ) !! :recman   ) }
  method norecman ( $/ )  { make ( $<recman-name> ?? :norecman( ~$<recman-name> ) !! :norecman ) }

  method recman:sym<norecman> ( $/ )  { make ( :!recman ) }
  method recman:sym<nr>       ( $/ )  { make ( :!recman ) }

  method cache:sym<cache-path>   ( $/ )  { make ( cache => $<path>.made ) }
  method cache:sym<c-path>       ( $/ )  { make ( cache => $<path>.made ) }
  method cache:sym<cache> ( $/ )  { make ( :cache ) }
  method cache:sym<c>     ( $/ )  { make ( :cache ) }
  method cache:sym<nocache> ( $/ )  { make ( :!cache ) }
  method cache:sym<nc>      ( $/ )  { make ( :!cache ) }

  method build:sym<build>   ( $/ )  { make ( :build  ) }
  method build:sym<b>       ( $/ )  { make ( :build  ) }
  method build:sym<nobuild> ( $/ )  { make ( :!build ) }
  method build:sym<nb>      ( $/ )  { make ( :!build ) }

  method test:sym<test>   ( $/ )  { make ( :test  ) }
  method test:sym<t>      ( $/ )  { make ( :test  ) }
  method test:sym<notest> ( $/ )  { make ( :!test ) }
  method test:sym<nt>     ( $/ )  { make ( :!test ) }

  method xtest:sym<xtest>   ( $/ )  { make ( :xtest  ) }
  method xtest:sym<xt>      ( $/ )  { make ( :xtest  ) }
  method xtest:sym<noxtest> ( $/ )  { make ( :!xtest ) }
  method xtest:sym<nxt>     ( $/ )  { make ( :!xtest ) }

  method force:sym<force>   ( $/ )  { make ( :force  ) }
  method force:sym<f>       ( $/ )  { make ( :force  ) }
  method force:sym<𝙁>       ( $/ )  { make ( :force  ) }
  method force:sym<🔨>      ( $/ )  { make ( :force  ) }
  method force:sym<➟>       ( $/ )  { make ( :force  ) }
  method force:sym<noforce> ( $/ )  { make ( :!force ) }
  method force:sym<nf>      ( $/ )  { make ( :!force ) }

  method serial:sym<serial>   ( $/ )  { make ( :serial  ) }
  method serial:sym<s>        ( $/ )  { make ( :serial  ) }
  method serial:sym<noserial> ( $/ )  { make ( :!serial ) }
  method serial:sym<ns>       ( $/ )  { make ( :!serial ) }

  method contained:sym<contained>   ( $/ )  { make ( :contained  ) }
  method contained:sym<c>           ( $/ )  { make ( :contained  ) }
  method contained:sym<nocontained> ( $/ )  { make ( :!contained ) }
  method contained:sym<nc>          ( $/ )  { make ( :!contained ) }

  method precompile:sym<precompile>   ( $/ )  { make ( :precompile  ) }
  method precompile:sym<precomp>      ( $/ )  { make ( :precompile  ) }
  method precompile:sym<noprecompile> ( $/ )  { make ( :!precompile ) }
  method precompile:sym<noprecomp>    ( $/ )  { make ( :!precompile ) }
  method precompile:sym<np>           ( $/ )  { make ( :!precompile ) }

  method clean:sym<clean>   ( $/ ) { make ( :clean  ) }
  method clean:sym<c>       ( $/ ) { make ( :clean  ) }
  method clean:sym<noclean> ( $/ ) { make ( :!clean ) }
  method clean:sym<nc>      ( $/ ) { make ( :!clean ) }

  method remote:sym<remote>   ( $/ )  { make ( :remote  ) }
  method remote:sym<r>        ( $/ )  { make ( :remote  ) }
  method remote:sym<🌎>       ( $/ )  { make ( :remote  ) }
  method remote:sym<noremote> ( $/ )  { make ( :!remote ) }
  method remote:sym<nr>       ( $/ )  { make ( :!remote ) }

  method local:sym<local>   ( $/ ) { make ( :local  ) }
  method local:sym<l>       ( $/ ) { make ( :local  ) }
  method local:sym<nolocal> ( $/ ) { make ( :!local ) }
  method local:sym<nl>      ( $/ ) { make ( :!local ) }

  method details:sym<details>   ( $/ ) { make ( :details  ) }
  method details:sym<d>         ( $/ ) { make ( :details  ) }
  method details:sym<nodetails> ( $/ ) { make ( :!details ) }
  method details:sym<nd>        ( $/ ) { make ( :!details ) }

  method relaxed:sym<relaxed>   ( $/ ) { make ( :relaxed  ) }
  method relaxed:sym<r>         ( $/ ) { make ( :relaxed  ) }
  method relaxed:sym<norelaxed> ( $/ ) { make ( :!relaxed ) }
  method relaxed:sym<nr>        ( $/ ) { make ( :!relaxed ) }


  method latest:sym<latest>   ( $/ ) { make ( :latest  ) }
  method latest:sym<l>        ( $/ ) { make ( :latest  ) }
  method latest:sym<nolatest> ( $/ ) { make ( :!latest ) }
  method latest:sym<nl>       ( $/ ) { make ( :!latest ) }

  method level:sym<nothing> ( $/ ) { make 'nothing' }
  method level:sym<all>     ( $/ ) { make 'all'     }
  method level:sym<debug>   ( $/ ) { make 'debug'   }
  method level:sym<now>     ( $/ ) { make 'now'     }
  method level:sym<info>    ( $/ ) { make 'info'    }
  method level:sym<warn>    ( $/ ) { make 'warn'    }
  method level:sym<error>   ( $/ ) { make 'error'   }

  method specs ( $/ ) { make $<spec>».made }

  method spec ( $/ ) { make $/.Str }

  method path ( $/ ) { make $/.IO }

  method nukes ( $/ ) { make $<nukable>».made }

  method nukable:sym<home>   ( $/ ) { make 'home'   }
  method nukable:sym<site>   ( $/ ) { make 'site'   }
  method nukable:sym<vendor> ( $/ ) { make 'vendor' }
  method nukable:sym<core>   ( $/ ) { make 'core' }
  method nukable:sym<cache>  ( $/ ) { make 'cache'  }
  method nukable:sym<stage>  ( $/ ) { make 'stage'  }
  method nukable:sym<tmp>    ( $/ ) { make 'tmp'    }
  method nukable:sym<pakku>  ( $/ ) { make 'pakku'  }

}


