mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-04 18:46:17 +01:00
- rewrite command and command alias handling so it is all defined in one place
This commit is contained in:
parent
d159226078
commit
1145aa0d3e
@ -19,29 +19,6 @@ on the directories. If no arguments are supplied to such a
|
|||||||
command, it recurses on the current directory (inclusive) by default.
|
command, it recurses on the current directory (inclusive) by default.
|
||||||
|
|
||||||
Available subcommands:
|
Available subcommands:
|
||||||
|
|
||||||
add
|
|
||||||
addremove
|
|
||||||
commit (checkin, ci)
|
|
||||||
checkout (co)
|
|
||||||
diff
|
|
||||||
editmeta
|
|
||||||
help
|
|
||||||
history (hist)
|
|
||||||
id
|
|
||||||
log
|
|
||||||
ls
|
|
||||||
meta
|
|
||||||
platforms
|
|
||||||
rebuildpac
|
|
||||||
remove (del, delete, rm)
|
|
||||||
resolved
|
|
||||||
results
|
|
||||||
results_meta
|
|
||||||
status (st)
|
|
||||||
update (up)
|
|
||||||
updatepacmetafromspec
|
|
||||||
|
|
||||||
""" % get_osc_version()
|
""" % get_osc_version()
|
||||||
|
|
||||||
|
|
||||||
@ -293,7 +270,7 @@ usage: osc addremove
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def checkin(args):
|
def commit(args):
|
||||||
"""commit (ci): Upload change content from your working copy to the repository
|
"""commit (ci): Upload change content from your working copy to the repository
|
||||||
|
|
||||||
usage: osc ci # current dir
|
usage: osc ci # current dir
|
||||||
@ -597,55 +574,59 @@ def help(args):
|
|||||||
usage: osc help [SUBCOMMAND...]
|
usage: osc help [SUBCOMMAND...]
|
||||||
"""
|
"""
|
||||||
if args:
|
if args:
|
||||||
cmd = resolve_cmd_alias(args[0])
|
cmd = args[0]
|
||||||
|
for i in cmd_dict.keys():
|
||||||
|
if cmd in cmd_dict[i]:
|
||||||
|
cmd = i
|
||||||
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print cmd_dict[cmd].func_doc
|
print cmd.func_doc
|
||||||
|
|
||||||
except KeyError:
|
except AttributeError, KeyError:
|
||||||
print 'unknown command \'%s\'' % cmd
|
print 'unknown command \'%s\'' % cmd
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print usage_general
|
print usage_general
|
||||||
|
lines = []
|
||||||
|
for i in cmd_dict.keys():
|
||||||
|
line = ' ' + (i.__name__)
|
||||||
|
if len(cmd_dict[i]) > 1:
|
||||||
|
line += ' (%s)' % ', '.join(cmd_dict[i][1:])
|
||||||
|
lines.append(line)
|
||||||
|
lines.sort()
|
||||||
|
lines.append('')
|
||||||
|
print '\n'.join(lines)
|
||||||
|
|
||||||
|
|
||||||
def resolve_cmd_alias(cmd):
|
|
||||||
if cmd in ['commit', 'ci']: return 'checkin'
|
|
||||||
if cmd == 'co': return 'checkout'
|
|
||||||
if cmd == 'st': return 'status'
|
|
||||||
if cmd == 'up': return 'update'
|
|
||||||
if cmd == 'list': return 'ls'
|
|
||||||
if cmd == 'hist': return 'history'
|
|
||||||
if cmd in ['del', 'remove', 'rm']: return 'delete'
|
|
||||||
return cmd
|
|
||||||
|
|
||||||
|
|
||||||
cmd_dict = {
|
cmd_dict = {
|
||||||
'add': add,
|
add: ['add'],
|
||||||
'addremove': addremove,
|
addremove: ['addremove'],
|
||||||
'checkin': checkin,
|
commit: ['commit', 'ci', 'checkin'],
|
||||||
'checkout': checkout,
|
checkout: ['checkout', 'co'],
|
||||||
'updatepacmetafromspec': updatepacmetafromspec,
|
updatepacmetafromspec: ['updatepacmetafromspec'],
|
||||||
'diff': diff,
|
diff: ['diff'],
|
||||||
'editmeta': editmeta,
|
editmeta: ['editmeta'],
|
||||||
'help': help,
|
help: ['help'],
|
||||||
'history': history,
|
history: ['history', 'hist'],
|
||||||
'id': userid, # <- small difference here
|
userid: ['id'], # <- small difference here
|
||||||
'init': init, # depracated
|
init: ['init'], # depracated
|
||||||
'log': log,
|
log: ['log'],
|
||||||
'ls': ls,
|
ls: ['ls', 'list'],
|
||||||
'meta': meta,
|
meta: ['meta'],
|
||||||
'platforms': platforms,
|
platforms: ['platforms'],
|
||||||
'delete': delete,
|
delete: ['delete', 'del', 'rm', 'remove'],
|
||||||
'repourls': repourls,
|
repourls: ['repourls'],
|
||||||
'resolved': resolved,
|
resolved: ['resolved'],
|
||||||
'results': results,
|
results: ['results'],
|
||||||
'results_meta': results_meta,
|
results_meta: ['results_meta'],
|
||||||
'rebuildpac': rebuildpac,
|
rebuildpac: ['rebuildpac'],
|
||||||
'status': status,
|
status: ['status', 'st'],
|
||||||
'update': update,
|
update: ['update', 'up'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""handling of commandline arguments, and dispatching to subcommands"""
|
"""handling of commandline arguments, and dispatching to subcommands"""
|
||||||
|
|
||||||
@ -654,7 +635,7 @@ def main():
|
|||||||
print "Type 'osc help' for usage."
|
print "Type 'osc help' for usage."
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
cmd = resolve_cmd_alias(sys.argv[1])
|
cmd = sys.argv[1]
|
||||||
|
|
||||||
# more arguments?
|
# more arguments?
|
||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
@ -662,12 +643,16 @@ def main():
|
|||||||
else:
|
else:
|
||||||
args = None
|
args = None
|
||||||
|
|
||||||
|
for i in cmd_dict.keys():
|
||||||
|
if cmd in cmd_dict[i]:
|
||||||
|
cmd = i
|
||||||
|
|
||||||
# run subcommand
|
# run subcommand
|
||||||
if cmd not in cmd_dict:
|
if cmd not in cmd_dict:
|
||||||
print 'unknown command \'%s\'' % cmd
|
print 'unknown command \'%s\'' % cmd
|
||||||
print "Type 'osc help' for usage."
|
print "Type 'osc help' for usage."
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
cmd_dict[cmd](args)
|
cmd(args)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user