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

cli.CountOf returns a list instead of zero #118

Closed
khorn opened this issue Apr 18, 2014 · 1 comment
Closed

cli.CountOf returns a list instead of zero #118

khorn opened this issue Apr 18, 2014 · 1 comment

Comments

@khorn
Copy link
Contributor

khorn commented Apr 18, 2014

When using cli.CountOf, if the parser does not find any instances of the flag (and so should return a value of zero), then it returns a single-element list, with the single element being zero.

Here's a quick program which illustrates the problem:

from plumbum import cli

class HelloApp(cli.Application):
    '''A simple app to say "Hello!"'''
    PROGNAME = 'HelloApp'
    VERSION = '1.0'

    verbosity = cli.CountOf('-v', help="Verbosity Level")

    def main(self, who='CLI World'):
        print self.verbosity
        print type(self.verbosity)
        if self.verbosity >= 1:
            print "I'm about to say hello."

        msg = 'Hello {!s}!'.format(who)
        print msg


if __name__ == "__main__":
    HelloApp.run()

Note that if you do not provide a -v flag, the value of self.verbosity will always be: [0]

If you give any other number of -v flags, CountOf returns the appropriate integer.

@khorn khorn changed the title CountOf returns a list instead of zero cli.CountOf returns a list instead of zero Apr 18, 2014
@khorn
Copy link
Contributor Author

khorn commented Apr 18, 2014

Thanks, @tomerfiliba! Talk about rapid turnaround. 🍪

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

1 participant