-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Uid] add command to generate UIDs #36405
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
Conversation
@guillbdx thanks for this and all your other contributions related to Uids. I'd like to ask something: is this really a common need? Do people generate Uids often in the console? |
FYI. Ramsey/uuid has a console library for the UUID component. I runs on Symfony, but I stopped using it because it kept being outdated. It's mostly usable during development when you need it a value for your tests or fixtures. |
My go-to solution has always been https://www.uuidgenerator.net/ There is also the However, for password, we also have a command to generate them, while there are also online bcrypt and libsodium generators. So I think it can make sense to include a UID generate command? |
I usually use website to generate uuid when needed. I think it will be slower to use command line 🤔 |
I have always used that https://www.uuidgenerator.net/ to generate some UUIDs when needed, I don't think that I would never use cli command for that. |
@wouterj for hashing password, there is a good reason not to use a third-party site: that would require that you give them the plaintext password. For the UUID generation, I'm not sure having a command for it in the core is worth it (there is no configuration needing to match). |
https://www.uuidgenerator.net/ doesn't support eg. ULID |
Oh, another reason to have the command: the ability to represent uids in base58/base32 (aka shorter identifiers) - this needs to be added to the command btw. |
src/Symfony/Bundle/FrameworkBundle/Command/UidGenerateCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/UidGenerateCommand.php
Outdated
Show resolved
Hide resolved
break; | ||
} | ||
|
||
$io->title('Generated UID:'); |
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.
Just a thought: I understand that you want to provide a friendly user interface. However, this command could be consumed by shell scripts if we provided a way to produce a UUID without any additional interaction or output.
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.
Maybe we should (if that possible) output everything except from the UID to stderr instead of stdout?
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've updated the code, so it just outputs the result now.
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 think having an interactive way of covering the null
defaults isn't such a good idea TBH
src/Symfony/Bundle/FrameworkBundle/Command/UidGenerateCommand.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Command/UidGenerateCommand.php
Outdated
Show resolved
Hide resolved
@nicolas-grekas ok, i've added base32 and base58 as options. |
Hi, i've updated my PR accordingly to your feedbacks. Main changes are:
|
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
9cdd200
to
78c8e2b
Compare
$name = $input->getArgument('name'); | ||
|
||
if (\in_array($type, [self::UUID_3, self::UUID_5], true) && !Uuid::isValid($namespace)) { | ||
throw new InvalidArgumentException('You must specify a valid namespace as a second argument.'); |
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.
worth generating/outputting one? perhaps toggle name/namespace args
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.
Do you mean that, in case the user hasn't provided a namespace, we should generate/output a random one?
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
To get the tests green, use PHPUnit's |
I'd like to add one more reason to NOT have this command: cluttering the CLI output. We've work hard in the past to get rid of commands (by way of removing optional deps) so that the "default" list of commands is at short as possible. I'm leaning towards a 👎 for adding this one. |
Let's close then, time we tell if we really miss this. |
Command to generate UUID and ULID.