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

Problems with Option/Argument stacking behaviour. Unnessary sub-command is shown in help menu. #650

Open
tomclad opened this issue Mar 1, 2023 · 1 comment
Assignees

Comments

@tomclad
Copy link

tomclad commented Mar 1, 2023

Cement Issue Reporting and Feature Requests

Pre-Note:

  • I have been using cement only from last 3-4 days. so, I am new to this framework. And I must say, I really like the framework @derks . Thank you for your work on this framework.
  • Cement exactly solves the problem I was having with other frameworks.

System Information

  • Cement Version: 3.0.8
  • Python Version: 3.10.9
  • Operating System and Version: Platform Linux-6.1.14-1-lts-x86_64-with-glibc2.37.
  • OS : Arch Linux

Steps to Reproduce (Bugs Only)

  • Below example is provided to reproduce bug.

What Am I trying to achieve

  • I am trying to define single options / Arguments in single module (python files) using Controllers.
  • Because I want to keep their functionality in separate file and then stack them onto base class.
  • In the below example, Embedded class will be defined in separate python file, just like here we have added Items Controller code.

Example

The following is an [MCVE] (Minimal Complete
Verifiable Example
) that reproduces the issue:

# INSERT EXAMPLE CODE HERE
from cement import App, Controller, ex
import sys

class Base(Controller):
    class Meta:
        label = 'base'
        arguments = [
            (['-c','--count'],
             {'help': 'takes numeric value',
              'type': int,
              'default': 1}),
        ]

    def _default(self):
        # if _default is not modified, then it is prints help by default as no commands
        # are parsed. help is printed even if self.app.pargs.name is parsed
        if len(sys.argv) == 1:
            self.app.args.print_help()

class Embedded(Controller):
    class Meta:
        label = 'embedded_controller'
        stacked_on = 'base'
        stacked_type = 'embedded'

        arguments = [
                (['-n','--name'],
                 {'help': 'takes name',
                  'action': 'store'}),
                ]

    def _post_argument_parsing(self):
        count = self.app.pargs.count
        name = self.app.pargs.name

        if name is not None:
            for i in range(count):
                print(name)


class MyApp(App):
    class Meta:
        label = 'myapp'
        handlers = [
            Base,
            Embedded,
        ]

with MyApp() as app:
    app.run()

Output of above Example


options:
  -h, --help            show this help message and exit
  -d, --debug           full application debug mode
  -q, --quiet           suppress all console output
  -c COUNT, --count COUNT
                        takes numeric value
  -n NAME, --name NAME  takes name

sub-commands:        <------------- unnecessary sub-commands
  {}         

Desired Output


options:
  -h, --help            show this help message and exit
  -d, --debug           full application debug mode
  -q, --quiet           suppress all console output
  -c COUNT, --count COUNT
                        takes numeric value
  -n NAME, --name NAME  takes name
@derks derks self-assigned this Mar 8, 2023
@derks
Copy link
Member

derks commented Mar 8, 2023

@tomclad is the intention to have completely separate cli's, that can also be used from a single unified cli? I assume similar to the way git used to be?

  • Example 1: myapp [sub-controller]
  • Example 2: myapp-sub-controller (as a separate app)

I have not seen this use case before, but i'll be happy to try it out and figure out what needs to happen in order to remove the empty sub-commands from Argparse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants