Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook `cli_unknown_subcommand` #47

Closed
hkoba opened this issue Sep 3, 2018 · 1 comment

Comments

@hkoba
Copy link
Owner

commented Sep 3, 2018

How about interpreting a subcommand DB.select_all as $obj->DB->select_all? Sub classes of CLI/CLI_JSON should be able to implement such subcommand interpretations easily. #46 is a good chance to introduce this.

@hkoba hkoba added the enhancement label Sep 3, 2018

@hkoba hkoba self-assigned this Sep 3, 2018

@hkoba

This comment has been minimized.

Copy link
Owner Author

commented Sep 3, 2018

To achieve such subcommand interpretation in a subclass, having below code in the class might be enough:

sub cli_unknown_subcommand {
  (my MY $self, my ($cmd, $arglist)) = @_;

  my (@method) = split /\./, $cmd;

  my $obj = $self;
  foreach my $meth (@method[0..$#method-1]) {
    $obj = $obj->$meth;
  }

  my $sub = $obj->can($method[-1])
    or $self->cmd_help("Unknown method in @method[0..$#method-1]: $method[-1]");

  $self->cli_invoke_sub($sub, $obj, @$arglist);
}
hkoba added a commit that referenced this issue Sep 3, 2018
For [GH #47] - add `cli_unknown_subcommand`
* Also add CLI_JSON::cli_invoke_sub

@hkoba hkoba closed this Sep 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.