Coder Social home page Coder Social logo

Comments (3)

jtrowe avatar jtrowe commented on August 23, 2024

I have also seen subdispatch commands being treated as top-level commands. I also did not expect that behavior.

from app-cmd.

le-garff-yoann avatar le-garff-yoann commented on August 23, 2024

Hello, I encounter the same problem.

I have the following setup:

.
./NestedCmd
./NestedCmd/Command
./NestedCmd/Command/first.pm
./NestedCmd/Command/first
./NestedCmd/Command/first/Command
./NestedCmd/Command/first/Command/second.pm
./nestedcmd.pl
./NestedCmd.pm
  • nestedcmd.pl
#!/usr/bin/env perl

use NestedCmd;

NestedCmd->run;
  • NestedCmd.pm
package NestedCmd 0.1;

use App::Cmd::Setup -app;

1;
  • NestedCmd/Command/first.pm
package NestedCmd::Command::first 0.1;

use parent 'App::Cmd::Subdispatch';

1;
  • NestedCmd/Command/first/Command/second.pm
package NestedCmd::Command::first::Command::second;

use NestedCmd::Command::first -command;

sub execute {
    print __PACKAGE__ . "\n";
}

1;

I got the following error when i start this:

Can't locate NestedCmd/Command/first/Command.pm in @INC (you may need to install the NestedCmd::Command::first::Command module) (@INC contains: /usr/local/lib/cperl/site_cperl/5.22.2/x86_64-linux /usr/local/lib/cperl/site_cperl/5.22.2 /usr/local/lib/cperl/5.22.2/x86_64-linux /usr/local/lib/cperl/5.22.2 .) at NestedCmd/Command/first/Command/second.pm line 3.
BEGIN failed--compilation aborted at NestedCmd/Command/first/Command/second.pm line 3.
Compilation failed in require at /usr/local/lib/cperl/site_cperl/5.22.2/App/Cmd.pm line 194.
        App::Cmd::_command("NestedCmd", undef) called at /usr/local/lib/cperl/site_cperl/5.22.2/App/Cmd.pm line 171
        App::Cmd::new("NestedCmd") called at /usr/local/lib/cperl/site_cperl/5.22.2/App/Cmd.pm line 314
        App::Cmd::run("NestedCmd") called at ./nestedcmd.pl line 5

I'ts seems to work when i replace use NestedCmd::Command::first -command; with use App::Cmd::Setup -command; ... but the second command is in the top-level too ...

nestedcmd.pl <command> [-?h] [long options...]
        -? -h --help    show help

Available commands:

  commands: list the application's commands
      help: display a command's help screen

     first: (unknown)
    second: (unknown)
nestedcmd.pl first

Available commands:

  commands: list the application's commands
      help: display a command's help screen

    second: (unknown)

So I override should_ignore() in NestedCmd (and it works):

sub should_ignore {
  my ($self, $command_class) = @_;

  $command_class =~ /^NestedCmd::Command::.*::/;
}

Could you confirm that:

  • this is the right way to do it.
  • this will work with future versions of your module.

?

Thanks.

from app-cmd.

larabr avatar larabr commented on August 23, 2024

In case someone still has trouble with this - in the App module, you can set the max depth to limit the listing of subcommands:

sub _module_pluggable_options {
  return (max_depth => 3);
}

from app-cmd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.