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 Input Validations for Command Flags for the command alpha generate #4193

Closed
camilamacedo86 opened this issue Sep 23, 2024 · 6 comments
Closed
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature.

Comments

@camilamacedo86
Copy link
Member

What do you want to happen?

Currently, the alpha generate command lacks proper input validation for its flags. This issue aims to add robust validation to ensure that invalid flag values are caught early, improving the user experience and preventing potential runtime errors.

Acceptance Criteria:

  1. Implement input validations for all flags in the alpha generate command.
  2. Return meaningful error messages when invalid flags are provided.

For reference see its code in: #4180

Extra Labels

No response

@camilamacedo86 camilamacedo86 added kind/feature Categorizes issue or PR as related to a new feature. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. labels Sep 23, 2024
@architlatkar27
Copy link

Hi, I am interested in contributing to kubebuilder and would like to take this up as my first issue.
Can i have a crack at it?

@camilamacedo86
Copy link
Member Author

Yes, sure!!
That seems a very good first issue.

@architlatkar27
Copy link

thanks a lot
/assign

@architlatkar27
Copy link

Hi, i would like some guidance on starting on this issue. As i understand this depends on the #4180 PR that you have created.
On that branch i went through the generate command, which currently has two flags (--input-dir and --output-dir) for which the validation has been implemented. Are there more flags that i am missing?

@camilamacedo86
Copy link
Member Author

Hi @architlatkar27,

In this case, we need to add validations for the flags. (see that we are using COBRA) These are the only flags available in the command:

  • For both -input-dir and --output-dir, check if the directories exist. (Please, verify whether the directory is being created by the command or if it requires the directory to exist in advance before implement the check for output-dir )
  • For -input-dir, ensure the PROJECT file exists within the directory.
  • Additionally, the --output-dir should be empty before running the command.

Let me know if you need further clarification!

@camilamacedo86
Copy link
Member Author

Hi @architlatkar27

I checked this one.
The required checks are in place already now, see:

// Validate ensures the options are valid and kubebuilder is installed.
func (opts *Generate) Validate() error {
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get working directory: %w", err)
}
opts.InputDir, err = getInputPath(cwd, opts.InputDir)
if err != nil {
return err
}
opts.OutputDir, err = getOutputPath(cwd, opts.OutputDir)
if err != nil {
return err
}
_, err = exec.LookPath("kubebuilder")
if err != nil {
return fmt.Errorf("kubebuilder not found in the path: %w", err)
}
return nil
}

So, I am closing this one since it is done already.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants