Configuration: Improve --help output throughout.
This commit is contained in:
parent
5fb01151d1
commit
63b0ad3c76
1 changed files with 32 additions and 20 deletions
|
@ -57,7 +57,11 @@ class Configuration:
|
||||||
)
|
)
|
||||||
subparsers = prog_parser.add_subparsers()
|
subparsers = prog_parser.add_subparsers()
|
||||||
|
|
||||||
hist_parser = subparsers.add_parser('historical', aliases=['hist'])
|
hist_parser = subparsers.add_parser(
|
||||||
|
'historical', aliases=['hist'],
|
||||||
|
usage='%(prog)s historical YYYY-MM-DD [[amount] code] [[in] code]',
|
||||||
|
help="Show a currency conversion or rate from a past date",
|
||||||
|
)
|
||||||
hist_parser.set_defaults(
|
hist_parser.set_defaults(
|
||||||
command='historical',
|
command='historical',
|
||||||
amount=None,
|
amount=None,
|
||||||
|
@ -70,12 +74,24 @@ class Configuration:
|
||||||
)
|
)
|
||||||
hist_parser.add_argument(
|
hist_parser.add_argument(
|
||||||
'date',
|
'date',
|
||||||
type=date_from('%Y-%m-%d'), metavar='YYYY-MM-DD',
|
type=date_from('%Y-%m-%d'),
|
||||||
|
help="Use rates from this date, in YYYY-MM-DD format"
|
||||||
)
|
)
|
||||||
hist_parser.add_argument(
|
hist_parser.add_argument(
|
||||||
'remainder',
|
'word1', nargs='?', metavar='first code',
|
||||||
nargs=argparse.REMAINDER,
|
help="Convert or show rates from this currency, in three-letter code format. "
|
||||||
|
"If not specified, show all rates on the given date.",
|
||||||
)
|
)
|
||||||
|
hist_parser.add_argument(
|
||||||
|
'word2', nargs='?', metavar='amount',
|
||||||
|
help="Convert this amount of currency. If not specified, show rates.",
|
||||||
|
)
|
||||||
|
hist_parser.add_argument(
|
||||||
|
'word3', nargs='?', metavar='second code',
|
||||||
|
help="Convert to this currency, in three-letter code format. "
|
||||||
|
"If not specified, defaults to the base currency.",
|
||||||
|
)
|
||||||
|
hist_parser.add_argument('word4', nargs='?', help=argparse.SUPPRESS)
|
||||||
|
|
||||||
return prog_parser
|
return prog_parser
|
||||||
|
|
||||||
|
@ -101,25 +117,21 @@ class Configuration:
|
||||||
if self.args.base is None:
|
if self.args.base is None:
|
||||||
self.args.base = self.conffile.get('Historical', 'base')
|
self.args.base = self.conffile.get('Historical', 'base')
|
||||||
self.args.to_currency = self.args.base
|
self.args.to_currency = self.args.base
|
||||||
remain_len = len(self.args.remainder)
|
if self.args.word4 and (self.args.word3.lower() in self.PREPOSITIONS):
|
||||||
if (remain_len > 3) and (self.args.remainder[2].lower() in self.PREPOSITIONS):
|
self.args.word3 = self.args.word4
|
||||||
del self.args.remainder[2]
|
if self.args.word1 is None:
|
||||||
remain_len -= 1
|
|
||||||
if remain_len == 0:
|
|
||||||
pass
|
pass
|
||||||
elif remain_len == 1:
|
elif self.args.word2 is None:
|
||||||
self.args.from_currency = self._convert_or_error(
|
self.args.from_currency = self._convert_or_error(
|
||||||
currency_code, self.args.remainder[0])
|
currency_code, self.args.word1)
|
||||||
elif remain_len < 4:
|
|
||||||
self.args.amount = self._convert_or_error(
|
|
||||||
decimal.Decimal, self.args.remainder[0])
|
|
||||||
self.args.from_currency = self._convert_or_error(
|
|
||||||
currency_code, self.args.remainder[1])
|
|
||||||
if remain_len == 3:
|
|
||||||
self.args.to_currency = self._convert_or_error(
|
|
||||||
currency_code, self.args.remainder[2])
|
|
||||||
else:
|
else:
|
||||||
self.error("too many arguments")
|
self.args.amount = self._convert_or_error(
|
||||||
|
decimal.Decimal, self.args.word1)
|
||||||
|
self.args.from_currency = self._convert_or_error(
|
||||||
|
currency_code, self.args.word2)
|
||||||
|
if self.args.word3 is not None:
|
||||||
|
self.args.to_currency = self._convert_or_error(
|
||||||
|
currency_code, self.args.word3 or self.args.base)
|
||||||
|
|
||||||
def _build_cache_loader(self):
|
def _build_cache_loader(self):
|
||||||
kwargs = dict(self.conffile.items('Cache'))
|
kwargs = dict(self.conffile.items('Cache'))
|
||||||
|
|
Loading…
Reference in a new issue