Skip to content

Commit f2775cb

Browse files
committed
uuid: add --count to main
Sometimes you need more than one UUID. Inspired by https://www.man7.org/linux/man-pages/man1/uuidgen.1.html
1 parent f3e275f commit f2775cb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Doc/library/uuid.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ The following options are accepted:
377377
The name used as part of generating the uuid. Only required for
378378
:func:`uuid3` / :func:`uuid5` functions.
379379

380+
.. option:: --count <count>
381+
382+
Generate more uuids in loop.
383+
380384

381385
.. _uuid-example:
382386

@@ -445,3 +449,5 @@ Here are some examples of typical usage of the :mod:`uuid` command line interfac
445449
# generate a uuid using uuid5
446450
$ python -m uuid -u uuid5 -n @url -N example.com
447451
452+
# generate 42 random uuids
453+
$ python -m uuid --count 42

Lib/uuid.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,8 @@ def main():
949949
parser.add_argument("-N", "--name",
950950
help="The name used as part of generating the uuid. "
951951
"Only required for uuid3/uuid5 functions.")
952+
parser.add_argument("--count", type=int, default=1,
953+
help="Generate more uuids in loop. ")
952954

953955
args = parser.parse_args()
954956
uuid_func = uuid_funcs[args.uuid]
@@ -963,9 +965,11 @@ def main():
963965
"Run 'python -m uuid -h' for more information."
964966
)
965967
namespace = namespaces[namespace] if namespace in namespaces else UUID(namespace)
966-
print(uuid_func(namespace, name))
968+
for _ in range(args.count):
969+
print(uuid_func(namespace, name))
967970
else:
968-
print(uuid_func())
971+
for _ in range(args.count):
972+
print(uuid_func())
969973

970974

971975
# The following standard UUIDs are for use with uuid3() or uuid5().

0 commit comments

Comments
 (0)