-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-131236: allow to generate multiple UUIDs at once via CLI #131218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f2775cb
ff6dc1c
0f95b45
8ec7c36
13c3428
6535ead
e34e8b4
3cab8b2
5b5f34a
4577a99
6ea8b3a
206caad
038bfbb
b3ef5e6
33f7cd1
43ee1ab
e7c214f
1a6ad78
1acb594
03ec58b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -949,6 +949,8 @@ def main(): | |||||||||
| parser.add_argument("-N", "--name", | ||||||||||
| help="The name used as part of generating the uuid. " | ||||||||||
| "Only required for uuid3/uuid5 functions.") | ||||||||||
| parser.add_argument("--count", type=int, default=1, | ||||||||||
| help="Generate more uuids in loop. ") | ||||||||||
|
||||||||||
| help="Generate more uuids in loop. ") | |
| help="Generate COUNT UUIDs. Default: 1.") |
Or add formatter_class=argparse.ArgumentDefaultsHelpFormatter to argparse.ArgumentParser() and:
| help="Generate more uuids in loop. ") | |
| help="Generate this many UUIDs.") |
And also delete "By default uuid4 function is used."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to have a short option -C as well so to mimick uuidgen, and use NUM as a metavar instead of COUNT. In addition, we can just say Generate NUM fresh UUIDs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also delete "By default uuid4 function is used."
Isn't it the default though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but argparse.ArgumentDefaultsHelpFormatter prints the default for us:
❯ ./python.exe -m uuid -h
usage: python.exe -m uuid [-h]
[-u {uuid1,uuid3,uuid4,uuid5,uuid6,uuid7,uuid8}]
[-n NAMESPACE] [-N NAME] [--count COUNT]
Generates a uuid using the selected uuid function.
options:
-h, --help show this help message and exit
-u, --uuid {uuid1,uuid3,uuid4,uuid5,uuid6,uuid7,uuid8}
The function to use to generate the uuid. By default
uuid4 function is used. (default: uuid4)
-n, --namespace NAMESPACE
The namespace is a UUID, or '@ns' where 'ns' is a
well-known predefined UUID addressed by namespace
name. Such as @dns, @url, @oid, and @x500. Only
required for uuid3/uuid5 functions. (default: None)
-N, --name NAME The name used as part of generating the uuid. Only
required for uuid3/uuid5 functions. (default: None)
--count COUNT Generate more uuids in loop. (default: 1)(I have an idea to add colour to those in future.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I thought that the suggestion was separate, my bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With ArgumentDefaultsHelpFormatter it would look the following:
It seems that the typesetting of the help text mixed – Do we start the help text with a capital letter? Do we use a period at the end (this looks strange with the (default: 1) generated by ArgumentDefaultsHelpFormatter)?
> python -m uuid -h
usage: python -m uuid [-h] [-u {uuid1,uuid3,uuid4,uuid5,uuid6,uuid7,uuid8}] [-n NAMESPACE] [-N NAME] [-C NUM]
Generates a uuid using the selected uuid function.
options:
-h, --help show this help message and exit
-u, --uuid {uuid1,uuid3,uuid4,uuid5,uuid6,uuid7,uuid8}
The function to use to generate the uuid. (default: uuid4)
-n, --namespace NAMESPACE
The namespace is a UUID, or '@ns' where 'ns' is a well-known predefined UUID addressed by namespace name. Such as @dns, @url, @oid, and @x500. Only required
for uuid3/uuid5 functions. (default: None)
-N, --name NAME The name used as part of generating the uuid. Only required for uuid3/uuid5 functions. (default: None)
-C, --count NUM Generate NUM fresh UUIDs. (default: 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding ArgumentDefaultsHelpFormatter, going for lowercase first letter, removing period at the end, adding metavar="NS" for namespace yields a more compact and consistent help output:
> python -m uuid -h
usage: python -m uuid [-h] [-u {uuid1,uuid3,uuid4,uuid5,uuid6,uuid7,uuid8}] [-n NS] [-N NAME] [-C NUM]
Generate a UUID using the selected UUID function.
options:
-h, --help show this help message and exit
-u, --uuid {uuid1,uuid3,uuid4,uuid5,uuid6,uuid7,uuid8}
function to generate the UUID (default: uuid4)
-n, --namespace NS a UUID, or '@ns' where 'ns' is a well-known predefined UUID addressed by namespace name, such as @dns, @url, @oid, and @x500 (only required for uuid3/uuid5)
(default: None)
-N, --name NAME name used as part of generating the UUID (only required for uuid3/uuid5) (default: None)
-C, --count NUM generate NUM fresh UUIDs (default: 1)
I'm still not happy with the verbose --namespace help, though:
-n, --namespace NS a UUID, or '@ns' where 'ns' is a well-known predefined UUID addressed by namespace name, such as @dns, @url, @oid, and @x500 (only required for uuid3/uuid5)
(default: None)
Is the following any better?
-n, --namespace NS a UUID, or @dns, @url, @oid, @x500, or any '@ns' where 'ns' is a well-known predefined UUID addressed by namespace name (only required for uuid3/uuid5)
(default: None)
Or specify the few choices explicitly?
-n, --namespace {any UUID,@dns,@url,@oid,@x500}
a UUID, or a well-known predefined UUID addressed by namespace name (only required for uuid3/uuid5) (default: None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
ArgumentDefaultsHelpFormatter, going for lowercase first letter, removing period at the end, addingmetavar="NS"for namespace yields a more compact and consistent help output:
👍
I'm still not happy with the very verbose
"a UUID, or '@ns' where 'ns' is a well-known predefined UUID addressed by namespace name, such as @dns, @url, @oid, and @x500 (only required for uuid3/uuid5)", though. Is"a UUID, or @dns, @url, @oid, @x500, or any '@ns' where 'ns' is a well-known predefined UUID addressed by namespace name (only required for uuid3/uuid5)"any better?
It's a bit better, and I don't have a much better suggestion :)
I think we could also prefix and shorten the "(only required for uuid3/uuid5)" bits, so if you're not using uuid3/5 you can immediately skip it and save some mental effort:
-n, --namespace NS uuid3/uuid5 only: [etc]
(default: None)
-N, --name NAME uuid3/uuid5 only: name used as part of generating the UUID (default: None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For --namespace, maybe specify the few choices explicitly?
-n, --namespace {any UUID,@dns,@url,@oid,@x500}
uuid3/uuid5 only: a UUID, or a well-known predefined UUID addressed by namespace name (default: None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your ideas. Here's the concise result:
> python -m uuid -h
usage: python -m uuid [-h] [-u {uuid1,uuid3,uuid4,uuid5,uuid6,uuid7,uuid8}] [-n {any UUID,@dns,@url,@oid,@x500}] [-N NAME] [-C NUM]
Generate a UUID using the selected UUID function.
options:
-h, --help show this help message and exit
-u, --uuid {uuid1,uuid3,uuid4,uuid5,uuid6,uuid7,uuid8}
function to generate the UUID (default: uuid4)
-n, --namespace {any UUID,@dns,@url,@oid,@x500}
uuid3/uuid5 only: a UUID, or a well-known predefined UUID addressed by namespace name) (default: None)
-N, --name NAME uuid3/uuid5 only: name used as part of generating the UUID (default: None)
-C, --count NUM generate NUM fresh UUIDs (default: 1)
Uh oh!
There was an error while loading. Please reload this page.