Skip to content
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

Add keygen command. #9

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

Add keygen command. #9

wants to merge 32 commits into from

Conversation

ximon18
Copy link
Member

@ximon18 ximon18 commented Oct 17, 2024

WIP.

@ximon18 ximon18 requested a review from a team October 17, 2024 15:09
@ximon18 ximon18 mentioned this pull request Oct 17, 2024
12 tasks
@bal-e bal-e self-assigned this Oct 29, 2024
@bal-e bal-e added enhancement New feature or request needs-review labels Oct 29, 2024
@bal-e bal-e marked this pull request as ready for review October 29, 2024 15:27
src/commands/keygen.rs Outdated Show resolved Hide resolved
src/commands/keygen.rs Outdated Show resolved Hide resolved
src/commands/keygen.rs Show resolved Hide resolved
Copy link
Contributor

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! It's not super pretty, but it's about what you can expect for so much IO. I'd love to see this tested before we merge this.

Cargo.toml Outdated Show resolved Hide resolved
src/commands/keygen.rs Show resolved Hide resolved
src/commands/keygen.rs Outdated Show resolved Hide resolved
src/commands/keygen.rs Outdated Show resolved Hide resolved
src/commands/keygen.rs Outdated Show resolved Hide resolved
src/commands/keygen.rs Show resolved Hide resolved
src/commands/keygen.rs Outdated Show resolved Hide resolved
public_key.algorithm().to_int(),
public_key.key_tag()
);
// TODO: Adjust for how 'Env' mocks the current directory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's on main so you could do this (and make all this testable)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I need to rebase now.

src/commands/keygen.rs Outdated Show resolved Hide resolved
src/commands/keygen.rs Outdated Show resolved Hide resolved
src/commands/keygen.rs Outdated Show resolved Hide resolved
algorithm = parse_os_with("algorithm (-a)", &parser.value()?, |s| {
Ok(match s {
"list" => {
// TODO: Mock stdout and process exit?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is possible after the notify branch is merged, where parse_ldns takes Env as well.


Arg::Short('r') => {
// NOTE: '-r' can be repeated; we don't use it, so the order doesn't matter.
let _ = parser.value()?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to warn or error here? Sounds like something that could lead to unexpected behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean warning that we don't support -r at all? Perhaps that's warranted, yeah.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit error saying that it's not supported yeah.

Comment on lines +212 to +216
impl From<Keygen> for Command {
fn from(value: Keygen) -> Self {
Self::Keygen(value)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put all of these in commands/mod.rs, though maybe you're right it should be here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting them here simplifies some of the merge conflicts we get for every new command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly opposed to the inconsistency


/// Create a symlink, overwriting if it already exists.
#[cfg(unix)]
fn fs_symlink_force(&self, target: impl AsRef<Path>, link: impl AsRef<Path>) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about adding higher-level API's than std here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purpose of CLI programs, std actually provides relatively little. In most languages, CLI codebases tend to have their own utility modules with these kinds of specialized filesystem / OS operations, often matching up with common command-line tools (e.g. symlink_force is basically ln -sf). I think we're going to accumulate these kinds of utility functions somewhere, and while Env isn't necessarily the right place, I think it's certainly the most convenient.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, you said yourself that adding a lot of functions to Env is probably not the right way to go? Besides, it depends on the function, I think we should keep them with the tool as long as they're not used in other tools.

This kind of muddles the idea of Env into both low-level environment interaction a util module. A function that takes Env as first argument is just as effective.

Don't consider this blocking though, it's alright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants