Code Monkey home page Code Monkey logo

Comments (4)

neithere avatar neithere commented on August 17, 2024

I think you mean this:

from argh import alias

@alias('spam')
def do_spam(args):
    print 'Albatross!!!'

If not, please reopen the issue and clarify the use case.

Note: This comment has been automatically migrated from Bitbucket
Created by @neithere on 2012-04-17 14:05:40+00:00, last updated: 2012-04-17 14:06:12+00:00

from argh.

neithere avatar neithere commented on August 17, 2024

Couple things:

  • I think your example would add both do_spam and spam. I need the function name to be do_spam but the parser to recognize only spam from input, but call the correct function.
  • I have a class with lots of do_* methods. I want to have the parser automatically “know” that command should call do_command without having to specify this each time.

Note: This comment has been automatically migrated from Bitbucket
Created by Zearin on 2012-04-17 14:13:46+00:00

from argh.

neithere avatar neithere commented on August 17, 2024
  • Actually at this point {{{@alias}}} renames the command, see the [[http://packages.python.org/argh/reference.html#argh.decorators.alias|documentation]]. It is true that the decorator's name is currently a bit misleading.
  • I think this is a marginal case that requires your class to do some extra work, e.g. have a method that returns a list of commands like this:
from argh import ArghParser, alias, arg

class App:

    @arg(...)
    def do_x(self): pass

    @arg(...)
    def do_y(self): pass

    def get_commands(self):
        names = [name for name in self.__dict__ if name.startswith('do_')]
        for name in names:
            meth = getattr(self, name)
            yield alias(name[3:])(meth)

    def dispatch(self, argv):
        parser = ArghParser()
        parser.add_commands(self.get_commands())
        parser.dispatch(argv)

Note: This comment has been automatically migrated from Bitbucket
Created by @neithere on 2012-04-17 15:07:32+00:00, last updated: 2012-04-17 15:12:28+00:00

from argh.

neithere avatar neithere commented on August 17, 2024

I don't see any reason why this issue should stay open. Please correct me if I'm wrong.

Note: This comment has been automatically migrated from Bitbucket
Created by @neithere on 2012-11-04 05:19:27+00:00

from argh.

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.