From a95764357668b778ae9ba419ff5edab888c332c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Mon, 11 Jul 2005 21:17:37 +0000 Subject: [PATCH] * ufak bir yanlis anlama olmus, hemen duzelteyim, kusura bakmayin benim hatam sayilir. pisi-cli komutlarina specific option'lar icin ne yaptigim tam anlasilmamis sanirim. olay su. her komutun ayri bir option'i var. bunu optparse'la yapabilmek icin once komutu okuyup sonra parser'i construct ediyor. ilk komutu okumayi da gene optparse'la yaptim ama daha kolay bir yolunu biliyorsaniz yapin (bu daha basit o acidan). bir de svn'de oldugu gibi common option'larin specific option'lardan once gelmesi de enforce edilebilir. su anda enforce edilmiyor ama oyle olmassa sicabilir. nasil calistigini gormek icin: pisi-cli --test remove x pisi-cli --test build x birincisinde remove'a ozel --test option'i taninir. ikincisinde build'in oyle bir option'i olmadigi icin veryansin eder. --- pisi-cli | 88 +++++++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/pisi-cli b/pisi-cli index a529588b..b477dc5f 100755 --- a/pisi-cli +++ b/pisi-cli @@ -25,23 +25,6 @@ Use \"%prog help \" for help on a specific subcommand. PISI Package Manager """ -# def commonopts(parser): -# parser.add_option("-D", "--destdir", action="store") -# parser.add_option("-u", "--username", action="store") -# parser.add_option("-p", "--password", action="store") -# parser.add_option("-P", action="store_true", dest="getpass", default=False, -# help="Get password from the command line") -# parser.add_option("-v", "--verbose", action="store_true", -# dest="verbose", default=False, -# help="detailed output") -# parser.add_option("-d", "--debug", action="store_true", -# default=True, help="show debugging information") -# parser.add_option("-n", "--dry-run", action="store_true", default=False, -# help = "do not perform any action, just show what\ -# would be done") -# return parser - - class ParserError: def __init__(self, msg): self.msg = msg @@ -54,52 +37,65 @@ class Parser(OptionParser): def error(self, msg): raise ParserError(msg) +# eheh, burada ne yaptigim anlasilamamis galiba +# sunlari yazin: +# pisi-cli --test remove x +# pisi-cli --test build x +# diger turlu olmaz bu. dikkat. per command optionlar +# svn log'unda anlatmistim. simdi bir daha yazmam gerekti bazi +# seyleri bastan calistirabilmek icin. bir ise yaramasa yapmazdim. + class PisiCLI(object): commands = ["help", "build", "info", "install", "remove", "index", "updatedb"] + def commonopts(self): + p = self.parser + p.add_option("-D", "--destdir", action="store") + p.add_option("-u", "--username", action="store") + p.add_option("-p", "--password", action="store") + p.add_option("-P", action="store_true", dest="getpass", default=False, + help="Get password from the command line") + p.add_option("-v", "--verbose", action="store_true", + dest="verbose", default=False, + help="detailed output") + p.add_option("-d", "--debug", action="store_true", + default=True, help="show debugging information") + p.add_option("-n", "--dry-run", action="store_true", default=False, + help = "do not perform any action, just show what\ + would be done") + + def __init__(self): # first construct a parser for common options # this is really dummy - parser = Parser(usage=usage, version="%prog " + pisi.__version__) -# parser.allow_interspersed_args = False -# parser = commonopts(parser) - parser.add_option("-D", "--destdir", action="store") - parser.add_option("-u", "--username", action="store") - parser.add_option("-p", "--password", action="store") - parser.add_option("-P", action="store_true", dest="getpass", default=False, - help="Get password from the command line") - parser.add_option("-v", "--verbose", action="store_true", - dest="verbose", default=False, - help="detailed output") - parser.add_option("-d", "--debug", action="store_true", - default=True, help="show debugging information") - parser.add_option("-n", "--dry-run", action="store_true", default=False, - help = "do not perform any action, just show what\ - would be done") + self.parser = Parser(usage=usage, version="%prog " + pisi.__version__) + #self.parser.allow_interspersed_args = False + self.commonopts() self.command = "" try: - (options, args) = parser.parse_args() -# if len(parser.rargs)==0: -# self.die() + (options, args) = self.parser.parse_args() + #if len(parser.rargs)==0: + # self.die() self.command = args[0] except ParserError: # fully expected :) let's see if we got an argument - if len(parser.rargs)==0: + if len(self.parser.rargs)==0: self.die() - #print 'rargs', parser.rargs, 'vals', parser.values - self.command = parser.rargs[0] + self.command = self.parser.rargs[0] -# # now for the real parser -# parser = OptionParser(usage=usage, version="%prog " + pisi.__version__) -# parser.allow_interspersed_args = False -# self.parser = commonopts(parser) -# self.add_subcommand_opts() -# (self.options, args) = self.parser.parse_args() + #print '*', self.command + + # now for the real parser THIS IS ABSOLUTELY NECESSARY + self.parser = OptionParser(usage=usage, + version="%prog " + pisi.__version__) + #self.parser.allow_interspersed_args = False + self.commonopts() + self.add_subcommand_opts() + (self.options, args) = self.parser.parse_args() self.args = args[1:] - self.options = options self.authInfo = None self.checkAuthInfo()